Explain circular linked list with example. How do you implement linked list operation in singly linked list? Explain.


This answer is not selected as best answer. This answer may not be sufficient for exam.

Your limit has been exceed. We have implemented this system because, We got difficulty on managing our servers. Please donate some amount to remove this limit.

Quota: 0 / 30


In Singly linked list, each node contains two fields one is info which is used to store data items and another is link field that is used to  point next the next node in the list. The last node has NULL pointer.The following example a singly linked list that contains three elements

Singly linked list | HAMROCSIT

Operations on linked list:

  1. Creation
  2. Insertion
  3. Deletion
  4. Traversing
  5. Searching

a) Creating a Node:

  • To create new node, We use the malloc function to dynamically allocate the memory for new node.
  • After creating the node, We can store the new item in the node using pointer.

Steps to create a new node and store an item:

NodeType *p;
p = (NodeType *)malloc(sizeof(NodeType));
p->info = 50;
p->next = NULL;

b) Insert Node

To insert an element or a node in a linked list, the following three things to be done:

  1. Allocating a node
  2. Assigning a data to info field of the node
  3. Adjusting a pointer and a new node may be inserted

Algorithm to insert a node:

1. Create a node using malloc
     NewNode = (NodeType *) malloc(sizeof(NodeType));
2. Assign data to info field of new Node:
     NewNode->info = newItem;
3. Entering the position of node at which you wantt o insert a new node
4. set temp = head;
5. if(head == NULL) then
      printf("Void insertion") and exit
6. for(i=1; i < pos - 1; i++)
      temp = temp->next;
7. Set NewNode->next = temp->next;
   Set temp->next = NewNode;
8. End

c) Deleting Node

1. IF head  == NULL
     print "Void Deletion" and exit
2. Enter position of node at which you want to delete a new node. Let this position is pos.
3. set temp = head and declare a pointer of structure be *p;
4. for(i=1; i< pos-1; i++)
     temp = temp->next;
5. Print deleted item is temp->next->info;
6. Set p = temp->index;
7. Set temp->next = temp->next->next;
8. free(p);
If you found any type of error on the answer then please mention on the comment or submit your new answer.
Leave your Answer:

Click here to submit your answer.

  Loading . . .