1.

A linked list is formed from the objects of the class:class Node { int number, Node nextNode; } Write an Algorithm OR a Method to add a node at the end of an existing linked list. The method declaration is as follows: void add node (Node start, int num)

Answer»

Algorithm to add a node at the end of an existing linked list. 

Steps: 

1. Start 

2. Set temporary pointer to start node 

3. Repeat steps 4 until it reaches null 

4. move the pointer to the next node 

5. create a new node, assign num to number and link to the temporary node 

6. End Method to add a node at the end of an existing linked list. 

void add node (node start, int num) 

Node A = new Node(start) 

while (A != null) 

A=A.nextNode; 

Node C = new node (); 

C. number = num; 

C.nextNode = null; 

A. next = C; 

}



Discussion

No Comment Found

Related InterviewSolutions