You are on page 1of 2

//display of circular linked list

#include<iostream>

using namespace std;

class node

public:

int data;

node *next;

};

void display(node *n);

int main()

int n;

cout<<"enter the no of nodes "<<endl;

cin>>n;

int a[n];

cout<<"enter the data of the linked list "<<endl;

for(int i=0;i<n;i++)

cin>>a[i];

node *head;

node *temp;

node *last;

head=new node();

head=new node();

head->data=a[0];

head->next=NULL;

last=head;

for(int i=1;i<n;i++)
{

temp=new node();

temp->data=a[i];

temp->next=NULL;

last->next=temp;

last=temp;

last->next=head;

display(head);

void display(node *n)

node *p=n;

do

cout<<p->data<<" ";

p=p->next;

while(p!=head);

cout<<endl;

You might also like