Question: In C++, add one function to this program. Write a function to find the list with maximum number of nodes and then print it. #include
In C++, add one function to this program. Write a function to find the list with maximum number of nodes and then print it.
#include
cout << " Record is Deleted Successfully..." << endl;
} } }; class Hash { public: List* l; int size; Hash(); int Hashing(string); void display(); void Search(string); void Insert(HashTable*); }; Hash::Hash() { size = 27; l = new List[size]; for (int i = 0; i < size; i++) { l[i].head = NULL; } } int Hash::Hashing(string key) { int index = 0, asciicode = key[0]; if (asciicode >= 65 && asciicode <= 90) { index = asciicode - 65; } else if (asciicode >= 97 && asciicode <= 90) { index = asciicode - 97; } else { index = 26; } return index; } void Hash::display() { int index; char arrindex; cout << endl; cout << " \t\t\tHASH TABLE "; cout << endl; for (int i = 0; i < size; i++) { index = i + 65; if (i == 26) { index = 35; } arrindex = index; HashTable* temp = l[i].head; cout << "[" << arrindex << "]"; while (temp != NULL) { cout << "--> (" << temp->Name << ")"; temp = temp->next; } if (l[i].head == NULL || temp == NULL) { cout << "-> (NULL)" << endl; } cout << endl; } cout << "-------------------------------" << endl; } void Hash::Insert(HashTable* TempNode) { int index; HashTable* ptr; HashTable* Node = new HashTable; Node->Name = TempNode->Name; Node->next = NULL; Node->prev = NULL;
index = Hashing(TempNode->Name); ptr = l[index].head; if (l[index].isempty()) { l[index].head = Node; } else { while (ptr->next != NULL) { ptr = ptr->next; } ptr->next = Node; Node->prev = ptr; }
} void Hash::Search(string S) { int index; char arrindex; cout << endl; cout << " \t\t\tHASH TABLE "; cout << endl; for (int i = 0; i < size; i++) { index = i + 65; if (i == 26) { index = 35; } arrindex = index; HashTable* temp = l[i].head;
cout << "[" << arrindex << "]"; while (temp != NULL) { if (temp->Name == S) {
cout << "--> (" << temp->Name << ")";
}
temp = temp->next;
}
cout << endl; } cout << endl; cout << "-------------------------------" << endl;
} void main() { Hash h; List AR; string Name; int num, ind; int choice; loop: system("cls"); cout << " Press 1 to Enter Names "; cout << " Press 2 to Display Names "; cout << " Press 3 to Search Names "; cout << " Press 4 to Delete Names "; cout << " Press 5 to Exit "; cin >> choice; switch (choice) { case 1: { AR.AddNode(); HashTable* temp = AR.head;
for (int i = 0; i < AR.Totall; i++) { h.Insert(temp); temp = temp->next; } cout << endl << endl; system("pause"); system("cls"); goto loop;
} case 2: { h.display(); cout << endl << endl; system("pause"); system("cls"); goto loop; } case 3: {cout << " Enter a name to Search: "; string Search; cin >> Search; h.Search(Search); cout << endl << endl; system("pause"); system("cls"); goto loop; } case 4: { AR.DeleteNode(); HashTable* temp = AR.head; for (int i = 0; i < AR.Totall; i++) { h.Insert(temp); temp = temp->next; } cout << endl << endl; system("pause"); system("cls"); goto loop; } case 5: { exit(0); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
