Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey I need some help with a project I\'m working on. I asked this question befor

ID: 3533777 • Letter: H

Question

Hey I need some help with a project I'm working on. I asked this question before but i didnt specipfy that my professor wants us to make an AUTOMATICALLY ordered doubly linked list. Meaning it finds the node where the record should be put after automatically. The one i made Isn't automaticly ordered and I'm confused as to where I would start or how to go about it. I know I need a ket and a bunch of nested if statements but im soo lost!!!! Please help! Here's the .cpp #include #include #include /* ***************************************************************************************** * This program creates a doubly linked list and allows the user to perform options such as * * Insert, Remove, and so on. * ***************************************************************************************** */ using namespace std; struct node { int id; string name; node *next; node *prev; }; //FUNCTION HEADERS int menu(); void addnode(); void delnode(); void display(); void show(); void search(); void purge(); void modify(); //POINTER DECLARATIONS node *start=NULL, *temp1, *temp2, *temp3, *temp4; //MAIN int main() { //Function call to menu function menu(); return 0; } /* ***************************************************************************************** * Function name: addNode * * Function purpose: adds records to the doubly linked list * * Function parameters: N/A * * Function type: void * ***************************************************************************************** */ void addnode() { char r; temp1 = new node; temp4 = new node; cout << "Enter a Name and ID to store: " << endl; cout << "ID: "; cin >> temp1->id; cout << endl << "Name: "; cin.ignore(); getline(cin,temp1-> name); temp4=start; if(start!=NULL) { while(temp4 != NULL) { if(temp4->id == temp1-> id) { cout << "That record exists!" << endl; return; } temp4 = temp4->next; } } cout << "Press 's' to insert from start of list" << endl << "Press 'm' to insert from middle of list" << endl << "Press 'e' to insert from the enf of the list" << endl; cin>>r; switch (r) { case's': if(start == NULL) { start = temp1; temp1->next = NULL; temp1->prev = NULL; } else { temp2 = start; temp1->next = temp2; temp1->prev = NULL; start = temp1; temp2->prev = temp1; } break; case'e': if(start == NULL) { start=temp1; temp1->next=NULL; temp1->prev=NULL; } else { temp2=start; while(temp2->next!=NULL) temp2=temp2->next; temp2->next=temp1; temp1->prev=temp2; temp1->next=NULL; } break; case'm': int num; cout << "Enter the ID after which you want to enter: "; cin >> num; cout << endl; temp2=start; while(temp2&&temp2->id!=num) temp2=temp2->next; if(temp2) { temp1->next=temp2->next; temp1->prev=temp2; temp2->next=temp1; if(temp1->next) temp1->next->prev=temp1; else temp1->next=NULL; } else { cout<<" Node not found "<id << " " << endl; cout << "Name:" << temp3-> name << endl << endl; temp3 = temp3->next; } } } /* ***************************************************************************************** * Function name: search * * Function purpose:searches the list * * Function parameters: N/A * * Function type: void * ***************************************************************************************** */ void search() { int p; cout << endl; cout << "Enter ID to search:"; cin >> p; temp1=start; while(temp1->next != NULL) { if(temp1-> id ==p) { cout << endl; cout << "ID: " << temp1-> id << endl << "Name: " << temp1-> name << endl; return; } temp1=temp1->next; } cout<<"record not found"<>d; switch (d) { case's': if (start == NULL) { cout<<"There are no records to delete!"<next==NULL) start=NULL; else { start=start->next; start->prev=NULL; } delete temp1; } break; case'e': if(start == NULL) { cout<<"There are no records to delete!" << endl; } else { temp1=start; if(temp1->next==NULL) { start=NULL; delete temp1; } else { while(temp1->next!=NULL) { temp2=temp1; temp1=temp1->next; } temp2->next=NULL; delete temp1; } } break; case'm': int num; cout << "Enter the ID of the node you want to delete: "; cin >> num; cout << endl; temp2=start; while(temp2&&temp2->id!=num) { temp1=temp2; temp2=temp2->next; } if(temp2) { temp1->next=temp2->next; temp1->next->prev=temp1; delete temp2; } else { cout<<" record not found"<next!=NULL) { temp3=temp3->next; } while(temp3!=NULL) { cout << "ID: " << temp3-> id << endl << "Name: "<< temp3-> name<< endl << endl; temp3 = temp3 -> prev; } } } /* ***************************************************************************************** * Function name: purge * * Function purpose: purges the list * * Function parameters: N/A * * Function type: void * ***************************************************************************************** */ void purge() { if(start == NULL) { cout << "The list is empty!"; return; } while(start != NULL) { temp1=start; start = start->next; delete temp1; } cout << "List has been purged!"; system("pause"); menu(); } /* ***************************************************************************************** * Function name: Menu * * Function purpose: displays the menu and allow user to perform options on the Doubly * * Function parameters: N/A * * Function type: void * ***************************************************************************************** */ int menu() { system("CLS"); int choice; char returner; cout << "****************************************************" << endl; cout << "*************Doubly Linked List Program*************" << endl; cout << "****************************************************" << endl; cout << "" << endl; cout << "Menu Options " << endl; cout << "1. Add a name " << endl; cout << "2. Delete a name" << endl; cout << "3. Display List" << endl; cout << "4. Search for someone" << endl; cout << "5. Display list backwards" << endl; cout << "6. Modify" << endl; cout << "7. Purge list" << endl; cout << "8. Exit program" << endl << endl; cout << "Choice: "; do { cin >> choice; switch (choice) { case 1: addnode(); cout << "Want to process more y/n" << endl; cin >> returner; system("CLS"); if(returner == 'y') menu(); else return 0; break; case 2: delnode(); cout << "Want to process more y/n" << endl; cin >> returner; system("CLS"); if(returner == 'y') menu(); else return 0; break; case 3: display(); cout << "Want to process more y/n" << endl; cin >> returner; system("CLS"); if(returner == 'y') menu(); else return 0; break; case 4: search(); cout << "Want to process more y/n" << endl; cin >> returner; system("CLS"); if(returner == 'y') menu(); else return 0; break; case 5: show(); cout << "Want to process more y/n" << endl; cin >> returner; system("CLS"); if(returner == 'y') menu(); else return 0; break; case 6: modify(); cout << "Want to process more y/n" << endl; cin >> returner; system("CLS"); if(returner == 'y') menu(); else return 0; break; case 7: purge(); cout << "Want to process more y/n" << endl; cin >> returner; system("CLS"); if(returner == 'y') menu(); else return 0; break; case 8: cout << "Now exitiing" << endl; system("PAUSE"); break; // return EXIT_SUCCESS; // return 0; default: cout << "Bad input" << endl; break; } } while(choice != 8); return 0; } /* ***************************************************************************************** * Function name: modify * * Function purpose: modifies the records user wants * * Function parameters: N/A * * Function type: void * ***************************************************************************************** */ void modify() { system("CLS"); int p; cout << "Enter ID to modify:"; cin >> p; temp1=start; while(temp1) { if(temp1->id==p) { cout << "Here's the record you'd like to modify" << endl; cout << "ID: " << temp1-> id << endl << "Name: " << temp1-> name << endl << endl; cout << "Enter the modifed version: " << endl << endl; cout << "ID: " << temp1-> id << endl << "New Name: "; cin.ignore(); getline(cin,temp1-> name); return; } temp1=temp1->next; } cout<<" record not found"<

Explanation / Answer

If no one answers please rate me a life saver...please,please....understand.....thank you..!!