A linked list is formed from the objects of the class
class Node
{
int number;
Node nextNode;
}
Write an Algoritm OR a Method to add a node at the end of an existing liked list The method declaration is as follows.
void add node(Node start, int num)
Algorithm to add a node at the end of an existing linked list.
Steps.
- Start
- Set temporary pointer to start node
- Repeat steps 4 until it reaches null
- move the pointer to the next node
- create a new node, assign num to number and link to the temporary node
- 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;
}
}