Sunday, 18 January 2026

LINKED list questions circular linked list

                  CIRCULAR LINKED LIST


#include <iostream>
using namespace std;
class cll{
    public:
        int val;
        cll* next;
        cll(int num){
         val=num;
          
           
        }
};
void insert(cll*&head,int num){
    if(!head){
         head=new cll(num);
         head->next=head;
         return;
    }
    cll* temp=new cll(num);
    cll*tra=head;
    do{
        tra=tra->next;
    }while(tra->next!=head);
    tra->next=temp;
    temp->next=head;
    
}
void traverse(cll*head){
    cll*temp=head;
    do{
        cout<<temp->val<<" ";
        temp=temp->next;
        
    }while(temp!=head);
}

int main()
{
   cll* head=NULL;
   insert(head,4);
   insert(head,5);
   insert(head,5);
   traverse(head); 
   
   
    
  
    
    
}LLIKED list questions circular linked list

No comments:

Post a Comment

SDE floyd-warshall algorithm

 // User function template for C++ class Solution {   public:     void floydWarshall(vector<vector<int>> &dist) {         //...