VOOZH about

URL: https://www.geeksforgeeks.org/dsa/convert-array-to-circular-doubly-linked-list/

⇱ Convert an Array to a Circular Doubly Linked List - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Convert an Array to a Circular Doubly Linked List

Last Updated : 11 Jul, 2025

Prerequisite: Doubly Linked list, Circular Linked List, Circular Doubly Linked List
Given an array of N elements. The task is to write a program to convert the array into a circular doubly linked list.
 

👁 Image Representation


 


The idea is to start traversing the array and for every array element create a new list node and assign the prev and next pointers of this node accordingly. 
 

  • Create a pointer start to point to the starting of the list which will initially point to NULL(Empty list).
  • For the first element of the array, create a new node and put that node's prev and next pointers to point to start maintaining the circular fashion of the list.
  • For the rest of the array elements, insert those elements to the end of the created circular doubly linked list.


Below is the implementation of the above idea: 
 


Output: 
The list is: 1 2 3 4 5

 

Time Complexity: O(n), as we are using a loop to traverse n times. Where n is the number of nodes in the linked list.

Auxiliary Space: O(1), as we are not using any extra space.

Comment