01 Jul Using classes
Question Description
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()
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
//
Filename
Your name is
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
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.
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.