Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Circular linked list

Objective

In this project, our main goal will be to understand the fundamentals of a circular linked list, and their operations.

Concepts

Use the provided resources for a better understanding.

Concept Resources
What is a circular linked list Introduction to Circular Linked List
Inserting node at the end Insert node of a circular singly linked list
Circular linked list implementation Creation and Display

Problem

Create an add() method to add to the CircularLinkedList class and a display() method to print the data values.

Implementation

In the add() method follow the provided steps:

  • It first checks if the head is null. If it is, the new node becomes both the head and tail of the list and its next reference is set to itself.
  • If the head is not null, the new node is added at the end of the list by updating the tail's next reference to the new node, and the new node becomes the new tail.
  • The circularity of the list is maintained by making the tail's next reference point back to the head.

In the display() method follow the provided steps:

  • It checks if the head is null. If it is, it prints a message indicating that the list is empty.
  • If the head is not null, it creates a new node called current and initializes it to the head.
  • It then loops through the list, printing the data of each node pointed to by the current node, until the current node points back to the head.
public class CreateList {
   public Node head = null;  
   public Node tail = null;   
 /* your code here */
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages