Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CPSC 121 Lab 9 Fall 2017 Eric May struct Node { int val; Node * next; }; Using Classes Define a LinkedList class suitable for

CPSC 121 Lab 9 Fall 2017 Eric May 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 EXTRA CREDIT: ensure contents of destroyList consist of a call to to recursive function private void destroyNode(Node *), which then calls destroyNode on the arguments next pointer, with head passed as an argumer public void display();//Displays entire contents of linked list. The lists 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 // (Current Date) 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 .zip The three potential files should be: 1. Header file with definition of class, method prototypes 2. Source file with our classs 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. Dont 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago