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 #include using namespace std; class HashTable { public: string Name; HashTable* prev; HashTable* next; HashTable(); }; HashTable::HashTable() { Name = "Nil"; prev = NULL; next = NULL; } class List { public: HashTable* head; int Totall = 0; bool isempty() { if (head == NULL) { return true; } else { return false; } } void AddNode() { HashTable* temp; HashTable* ptr; temp = new HashTable; cout << " \t\tKindly Enter Name: "; cin.ignore(); getline(cin, temp->Name); temp->next = NULL; temp->prev = NULL; ptr = head; if (isempty()) { head = temp; } else { while (ptr->next != NULL) { ptr = ptr->next; } ptr->next = temp; } Totall++; } void DeleteNode() { string Name; HashTable* temp; HashTable* ptr; cout << " \t\tEnter Name to DELETE: "; cin >> Name; cout << endl; ptr = NULL; temp = head; while (temp != NULL && temp->Name != Name) { ptr = temp; temp = temp->next; } if (temp == NULL) { return; } else { if (ptr == NULL) { head = temp->next; } else { ptr->next = temp->next; } delete temp; Totall--;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!