Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a simple linked list program to create a class list containing class node

ID: 3539979 • Letter: C

Question

Create a simple linked list program to create a class list containing class node :


{

void *info;

node *next;

public:

node (void *v) {info = v; next = 0; }

void put_next (node *n) {next = n;}

node *get_next ( ) {return next;}

void *get_info ( ) {return info;}

};


Be able to initially fill the list. Provide functions to insert/append nodes and remove nodes from the linked list. Be able to display the contents of the list.


Write a little driver program with at least 5 values passed in (so that 5 nodes are created) as you insert/append, delete and display data, showing the programs operation.


Please show all work. Thanks!

Explanation / Answer

To create a list, you have to specify your first element (root) and the maximum number of nodes. Further useful attributes and methods are the current number of nodes, the constructor of a new list and the getters and setters of the attributes (maximum and current number should not be manipulable).

You simply can create and insert several nodes into your list. Be careful: if an instance of ListNode is null, you don't have any access to the node. The following example inserts a new node at the end of the list.

Otherwise you can insert a new node as a new root-node which could be more efficient but not always useful.

In Java it is simple to remove any node. You must not delete the node itself but the reference to that node (java uses garbage collection). There are many options to remove any node. You can remove the node with the greatest or smallest value, the node with a special value or a special node (for example the n-th node). The easiest way is to remove a special node by counting the nodes from zero to current number (as in arrays).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote