Description
Design your own linked list class named IntList to hold a series of integers.
Include the following public member functions, named as shown:
Member Function | Description |
Default Constructor | Creates an empty list. |
Copy Constructor | Accepts an IntList object passed by reference. Makes nodes in the current object for each node in the object passed in and copies the integers from the object passed in into the current object. Hint: In this constructor, set head to nullptr, then loop through the object that was passed in, calling appendNode to create a node in the object being constructed for each node in the existing object.
|
appendNode | Accepts an integer argument. Allocates a new node, stores the passed value into the node and appends the node to the end of the list.
|
insertNode | Accepts an integer argument. Allocates a new node, stores the passed value into the node and inserts the node into the list so that the nodes are in increasing numerical order.
|
deleteNode | Accepts an integer argument. Searches for the node that contains the passed value and deletes it from the list. To delete a node: remove it from the list without breaking the links created by the next pointers & delete the memory allocated for the node.
|
displayList | Displays the entire list to the monitor. For each node, this function prints the node number and the value stored in the node.
|
countNodes | Public ‘wrapper’ function that calls private countNodes recursive function, passing in the head member variable. |
countNodes | Private recursive function that counts the number of nodes in the list. |
- Write the default constructor and ‘wrapper’ function in-line. Write the remaining member functions non-in-line. For full credit, you must use the function names specified above. Store your class into IntList.h and IntList.cpp files as directed below.
- I recommend implementing the standard Linked List class with default constructor, appendNode, insertNode, deleteNode, displayList, and destructor first. Get that working with a test program as shown in the book examples. Then add the copy constructor and countNodes functions. Your private countNodes function must be recursive.
- Write a program (main) to test your class. Be sure to test both constructors and all public member functions. Your book has example test programs and we’ve also used them in class.
- You don’t need a menu.
- Just make an IntList object, append a few nodes, insert a few nodes, delete a few nodes, printing the list after each group to make sure it’s right. Plan the values that you’re adding / removing to make sure that you have one at the start, in the middle, and at the end to test all of your code.
- Then test the copy constructor by making a new list that’s a copy of the current list, print both lists, change one and reprint both to make sure that they are separate. Then call your countNodes function and print the number of nodes in the list.
- Design your class and program by completing the CS 250 OOP Design Document. Give the description of the class along with a brief description of what is to be stored in each member variable and the purpose of each member function. Also give a description of what the main program will do. You will need to include time estimates for design, coding each function, program testing, and total time. Save the design in a file named IntListDesign_xxx.doc where xxx are your initials. Submit your program design by the beginning of the class preceding the program due date.
- Save the program (main) in a file named integers.cpp. Save the class declaration in a file named IntList.h. Save the member functions for the class in a file named IntList.cpp.
- Compile, run and test your program
- Update your Program Design Document by updating the class and program descriptions to fit your working program. Update the time estimates based on actual time spent. Save the updated document.
- Submit your updated design document and working .h and .cpp files in the Program 8 drop box. For this assignment, you should submit one file in the Program 8 Design drop box and 4 files in the Program 8 drop box.