Design your own linked list (LL) class to hold customer names and phone numbers.
ID: 3584476 • Letter: D
Question
Design your own linked list (LL) class to hold customer names and phone numbers. The class should have member functions for appending, inserting, deleting, searching and displaying nodes. You should also have a constructor and a destructor for the class. You should also have a copy constructor for the class. Demonstrate the class with a driver program. Your driver program should show each case of functions. Your output of the program should have the following information: - Initially create 10 customer names and phone numbers in the LLExplanation / Answer
//Name: //Class: Data Structures //Due: //Description: This program will create a linked list to hold customer names and // their phone numbers. #include using namespace std; class LinkedList { private: struct ListNode { char name; int phnum; struct ListNode *next; }; ListNode *head; public: NumberList() { head = NULL; } ~NumberList(); void appendNode(char, int); void insertNode(char, int); void deleteNode(char, int); void displayList() const; }; int main() { LinkedList list; Business person1(Aker, 6924456); Business person2(Clay, 6881234); Business person3(Davis, 6913453); list.appendNode(person1); list.appendNode(person2); list.appendNode(person3); cout next = NULL; if (!head) head = newNode; else { nodePtr = head; while (nodePtr->next) nodePtr = nodePtr->next; nodePtr->next = newNode; } } void NumberList::insertNode(char nm, int phm) { ListNode *newNode; ListNode *nodePtr; ListNode *previousNode = NULL; newNode = new ListNode; newNode->name = nm; newNode->phnum = phm; if (!head) { head = newNode; newNode->next = NULL; } else { nodePtr = head; previousNode = NULL; if (previousNode == NULL) { head = newNode; newNode->next = nodePtr; } else { previousNode->next = newNode; newNode->next = nodePtr; } } } void NumberList::deleteNode(char nm, int phm) { ListNode *nodePtr; ListNode *previousNode; if (!head) return; if (head->name == nm) { nodePtr = head->next; delete head; head = nodePtr; } else { nodePtr = head; while (nodePtr != NULL && nodePtr->name != nm) { previousNode = nodePtr; nodePtr = nodePtr->next; } if (nodePtr) { previousNode->next = nodePtr->next; delete nodePtr; } } } void NumberList::displayList() const { ListNode *nodePtr; nodePtr = head; while (nodePtr) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.