Using classes
struct Node {
int val;
Node * next;
};
Using Classes
- Define a LinkedList class suitable for holding the Node struct defined above
- Only variables should be public Node * head and private int nodeCount
- nodeCount should be updated any time a node is created or destroyed
- Functions should include:
- public void insertItem(int n, bool atHead); //Fills a new node with n, adds at the beginning or the end of the list based on atHead
- public LinkedList();//Initializes head to indicate no value
- public int findItem(int n);//Indicates where the requested item is located within our linked list. 0 or -1 == not located in list (your choice, document!)
- public int getNodeCount();//Accessor, tells the user how many nodes are currently contained in the linked list
- private Node* getNodeAt(int n);//Returns the address of the requested node. Checks to see if n is a valid number first.
- public bool removeNodePosition(int n);//Attempts to delete node n in the list; return value indicates success
- public bool removeValue(int n);//Attempts to delete Node node where node.val == n
- public void destroyList();//Deletes and removes all nodes currently in the linked list
- public void display();//Displays entire contents of linked list. The list’s size should be displayed, followed by each value in order
- public ~LinkedList();//Frees any memory that has been dynamically allocated in the lifespan of the list. Hint: calls destroyList()
- Only variables should be public Node * head and private int nodeCount
- In main, create a LinkedList then present the user with a menu of options:
- Add an item (asks user for item, if start/end)
- Find an item (asks user for item)
- Remove an item (asks user to choose between providing a position and a value, then call with appropriate function)
- Display list
- Destroy list
- Destroy list and exit
- Return to step 2 if user did not choose f
This lab may be extended, with additional points, in the remainder of the semester.
Points:
2 – Documentation, readability, format
1 – Filename and Header
1 – Output testing
3 – Proper use of dynamic memory/data structures
3 – Proper use of classes
Header
//Author: Eric May (your name)
//CPSC 121 Lab 9
//<MM/DD/YY> (Current Date)
Filename
Your name is <Last Name><First Initial>
For example, my name would be MayE
This project is suitable for being split up into up to three files. I want all of your submitted files in a .zip or .rar archive, named <Last Name><First Initial>.zip
The three potential files should be:
1.Header file with definition of class, method prototypes
2.Source file with our class’s methods’ definitions
3.Driver file that connects our class to a menu in main()
These three files can be named anything as long as the archive file follows the appropriate naming style. Don’t forget to include your header in all files you submit. If you wish to submit the project without submitting multiple files, you may do so at a slight point deduction.
"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.
Discount Code: CIPD30
Click ORDER NOW..


