import'dart:io';import'dart:math';classDataItem{intdata;DataItem(this.data){}intgetKey(){returndata;}}classHashTable{intarraySize;List<DataItem>hashArray;DataItemnonItem;HashTable(intsize){this.arraySize=size;hashArray=newList<DataItem>(size);nonItem=newDataItem(-1);}voiddisplayTable(){stdout.write('HashTable: ');for(inti=0;i<arraySize;i++){if(hashArray[i]!=null){stdout.write('${hashArray[i].getKey()} ');}else{stdout.write('** ');}}stdout.writeln();}/// Hash FunctioninthashFunc(intkey){returnkey%arraySize;}/// Insert a DataItemvoidinsert(DataItemitem){intkey=item.getKey();inthashVal=hashFunc(key);// until empty cell or -1while(hashArray[hashVal]!=null&&hashArray[hashVal].getKey()!=-1){++hashVal;// go to next cellhashVal%=arraySize;}// insert itemhashArray[hashVal]=item;}/// Delete a DataItemDataItemdelete(intkey){inthashVal=hashFunc(key);// until empty cellwhile(hashArray[hashVal]!=null){if(hashArray[hashVal].getKey()==key){DataItemtemp=hashArray[hashVal];hashArray[hashVal]=nonItem;returntemp;}++hashVal;hashVal%=arraySize;}returnnull;}/// Find Element by keyDataItemfind(intkey){inthashVal=hashFunc(key);// until empty cellwhile(hashArray[hashVal]!=null){if(hashArray[hashVal].getKey()==key){returnhashArray[hashVal];}++hashVal;hashVal%=arraySize;}returnnull;}}voidmain(){DataItemdataItem;intkey,size,n;Randomrandom=newRandom();// get sizestdout.write('Enter size of hash table: ');size=int.parse(stdin.readLineSync());stdout.write('Enter initial number of items: ');n=int.parse(stdin.readLineSync());// make tableHashTablehashTable=newHashTable(size);// insert datafor(inti=0;i<n;i++){key=random.nextInt(200);dataItem=newDataItem(key);hashTable.insert(dataItem);}// interact with userwhile(true){stdout.writeln('Enter first leter of show, insert, delete, find: ');Stringchoice=stdin.readLineSync();switch(choice){case's':hashTable.displayTable();break;case'i':stdout.write('Enter key value to insert: ');key=int.parse(stdin.readLineSync());dataItem=newDataItem(key);hashTable.insert(dataItem);break;case'd':stdout.write('Enter key value to delete: ');key=int.parse(stdin.readLineSync());hashTable.delete(key);break;case'f':stdout.write('Enter key value to find: ');key=int.parse(stdin.readLineSync());dataItem=hashTable.find(key);if(dataItem!=null){stdout.writeln('Found $key');}else{stdout.writeln('Could NOT found $key');}break;default:stdout.writeln('Invalid command');}}}