Linked List 2014

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.

  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;

}

}

This entry was posted in Linked list. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *