You are on page 1of 2

#include<iostream.h> #include<alloc.

h> struct node { int data; struct node * link; }*n,*first=NULL,*temp; void createnode() { n=new node; cout<<"enter the data"; cin>>n->data; n->link=NULL; } void insertfront() { createnode(); if(first == NULL) { first=n; first->link=first; } else { n->link=first->link; first->link=n; } } void insertend(){ createnode(); if(first == NULL) { first=n; first->link=first; } else { temp=first; while(temp->link!=first) { temp=temp->link; } temp->link=n; n->link=first; } } void display() { if(first==NULL) { cout<<"The list is empty"<<endl; return; } temp=first->link; while(temp!=first) { cout<<temp->data<<endl; temp=temp->link; } cout<<temp->data<<endl;

} void del() { if(first==NULL) { cout<<"The list is empty"<<endl; return; } else if(first->link==first) { delete first; first=NULL; } else { temp=first->link; first->link=temp->link; delete temp; } } void main(){ int ch; do{ cout<<"1. Insertfront 2. insert end 3.Display 4. Delete"<<endl; cout<<"enter a choice"<<endl; cin>>ch; switch(ch){ case 1: insertfront(); break; case 2: insertend(); break; case 3: display(); break; case 4: del(); break; } }while(ch<=4); }

You might also like