• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » DS » Linked Lists » Circularly-linked list vs. linearly-linked list
Next →
← Prev

Circularly-linked list vs. linearly-linked list

By Dinesh Thakur

Circularly linked lists are useful to traverse an entire list starting at any point. In a linear linked list, it is required to know the head pointer to traverse the entire list. The linear linked list cannot be traversed completely with the help of an intermediate pointer.

 

Access to any element in a doubly circularly linked list is much easier than in a linearly linked list since the particular element can be approached in two directions. For example to access an element present in the fourth node of a circularly linked list having five elements, it is enough to start from the last node and traverse the list in the reverse direction to get the value in the fourth node.

 

Implementation of a circular linked list:

 

Creating the list

 

while (input_element != -999)

{

new_node=(struct node *) malloc (size);

new_node->info=input_element;

if ( root_node==NULL )

root_node=new_node;

else

( *last_node )->next=new_node;

(*last_node)=new_node;

scanf(“%d”,&input_element);

}

if(root!=NULL)

new->next=root;

return root;

 

Inserting elements into the list

 

After getting the position and value to be inserted, the following code can be followed:

 

new_node=(struct node *)malloc(sizeof(struct node));

new_node-> info=input_element;

 

if((position==1)||((*root_node)==NULL))

{

new_node->next =*root_node;

*root_node = new_node;

if((*last_node)!=NULL)

(*last_node)->next=*root_node;

else

*last_node=*start_node;

}

else

{

temp_node=*root_node;

counter=2;

while ( (counter<position) && (temp_node->next !=

(*root_node) ) )

{

temp_node=temp_node->next;

++counter;

}

if(temp_node->next==(*root_node))

*last_node=new_node;

new_node->next=temp_node->next;

temp_node->next=new_node;

}

 

Deleting an element from the list

 

After getting the element to be deleted, the following code can be used:

 

If(*front_node != NULL)

{

printf(“The item deleted is %d”,(*front_node->info));

If (*front_node == *rear_node)

{

*front_node = *rear_node = NULL;

}

else

{

*front_node = *front_node->next;

*rear_node->link = *front_node;

}

}

You’ll also like:

  1. What is Doubly-circularly-linked list
  2. What is Singly-circularly-linked list
  3. What is Doubly Linked List
  4. What is Linked lists? How Many Type of Link List
  5. Short Note on Single Linked List
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Data Structure

Data Structure Tutorials

  • DS - Home
  • DS - Sorting
  • DS - Shortest Path Algorithm
  • DS - free() Function
  • DS - Graph Traversals
  • DS - Linear Search
  • DS - Heap Sort
  • DS - Searching
  • DS - Linked Lists
  • DS - Algorithms
  • DS - Bubble Sort
  • DS - Quick Sort
  • DS - Binary Search
  • DS - realloc() Vs free()
  • DS - Steps to Plan Algorithm
  • DS - Record Structure
  • DS - Single Linked List
  • DS - Purpose of realloc()
  • DS - Use malloc()
  • DS - calloc() Vs malloc()

Other Links

  • Data Structure - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW