In: Computer Science
# List at least three functions in the linked list toolbox, including function names and their functionality.
# Assuming we have already implemented all functions in the linked list toolbox and we have a pointer head_ptr pointing to the front of a linked list. Write a few lines to insert the number 42 and make it the second item in the list. Note: if the list was originally empty, then it should be the first in the list.
HELLO
The three function in linked list can be go like this
1>insert_item(Node head_ptr,int item)
Functionality : This function will insert given item at first position in linkedlist
2>remove_item(Node head_ptr,int item)
Functionality : this function will remove item from linked list by iterating trough linked list till it founds the given item
and if provided item is found then simply deleting it
3>print_linkedlist(Node head_ptr)
Functionality : this function will print all items of linked list from start to end
Function IN C++ to insert number 42 at second position goes like this
Node insert2nd(Node head_ptr) {
if(head_ptr == null)
{
Node node = new Node();
node.data = 42;
node.next = head_ptr;
return node;
}
Node dummy = new Node();
dummy.next = head_ptr;
Node runner = dummy;
for (int i = 0; i < 2; ++i) {
runner = runner.next;
}
Node node = new Node();
node.data = 42;
node.next = runner.next;
runner.next = node;
return dummy.next;
}