Question

In: Computer Science

# List at least three functions in the linked list toolbox, including function names and their...

# 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.

Solutions

Expert Solution

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;
}

Related Solutions

Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Create a table including the names and functions of the major enzymes and proteins involved in...
Create a table including the names and functions of the major enzymes and proteins involved in DNA replication. 1.Enzyme 2.Helicase 3.Primase 4. Topoisomerase 5. DNA polymerase 1 6. DNA polymerase 2 7. DNA polymerase 3 8. Ligase
List names of neurotransmitters, their main functions and implications in human disease.
List names of neurotransmitters, their main functions and implications in human disease.
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void remove_node(struct linked_list* list, int rm_node_value) (the function to make) This function removes a node with specified value. If there is only one node in the list, remove the node and remove the list also since there is nothing left. While removing a node, the node should be perfectly freed. If the type of list is...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void pop_Stack (struct linked_list* list, int number) //*This is the function to make and below is the explanation that should be written in given code. This function removes some nodes in stack manner; the tail of the list will be removed, repeatedly. The parameter (variable number_of_nodes) means the number of nodes that will be removed. When...
1. What is money and list the three functions of money? Which function is the most...
1. What is money and list the three functions of money? Which function is the most important? 2. Describe the organizational structure and functions of the Federal Reserve Syste 3. What is the difference between money market instruments and capital market instruments?
a) name the 4 layers of the stomach and list their functions b) names 2 things...
a) name the 4 layers of the stomach and list their functions b) names 2 things found in gastric juice and explain what stimulates it to be released
C++ program Complete the following functions for linked list. You are not allowed to alter the...
C++ program Complete the following functions for linked list. You are not allowed to alter the names or the function prototypes. #ifndef _ULL #define _ULL #include <iostream> #include "nodeType.h" using namespace std; void initializeList(nodeType *&head, nodeType *&tail, int&count); //Initialize the list to an empty state. //Postcondition: head = NULL, tail = NULL, count = 0; bool isEmptyList(const nodeType *head) ; //Function to determine whether the list is empty. //Postcondition: Returns true if the list is empty, // otherwise it returns false. void print(const...
Python 3 Function which takes the head Node of a linked list and sorts the list...
Python 3 Function which takes the head Node of a linked list and sorts the list into non-descending order. PARAM: head_node The head of the linked list RETURNS: The node at the head of the sorted linked list. ''' def sort(head_node): #Code goes here ''' Test code goes here '' ' if __name__ == '__main__':
list 7 most common diseases of potato including a) the disease and pathogen names (common and...
list 7 most common diseases of potato including a) the disease and pathogen names (common and scientific), b) plant symptoms, c) microscopic features, d) references for the information. Note the similarities and differences to what you have observed.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT