Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int data;
- struct node *next;
- }node;
- typedef struct
- {
- node *last;
- }head;
- void insertend(head *t,int ele)
- {
- node *p;
- p = (node*)malloc(sizeof(node));
- p->data=ele;
- p->next=NULL;
- if(t->last==NULL)
- {
- t->last=p;
- t->last->next=t->last;
- return;
- }
- p->next = t->last->next;
- t->last->next=p;
- t->last = p;
- return ;
- }
- void count(head *t)
- {
- node *q;
- int c=0;
- if(t->last==NULL)
- {
- printf("Linked List is empty");
- return;
- }
- q=t->last->next;
- do
- {
- c=c+1 ;
- q=q->next;
- }while(q!=t->last->next);
- printf("Total no. of elements in Linked list is %d",c);
- return;
- }
- void deletebeg(head *t)
- {
- int z;
- node *p;
- if(t->last==NULL)
- {
- printf("Linked list is Empty");
- return;
- }
- p = t->last->next;
- z = p->data;
- if(p == p->next)
- t->last=NULL;
- else t->last->next = p->next;
- printf("deleted element in Linked list %d",z);
- return;
- }
- void display(head *t)
- {
- node *q;
- if(t->last==NULL)
- {
- printf("\nLinked list is empty");
- return;
- }
- q = t->last->next;
- printf("\nElement of Linked list is given below\n");
- do
- {
- printf("%d\t",q->data);
- q=q->next;
- }while(q!=t->last->next);
- return;
- }
- int main()
- {
- head x;
- int ch,ele;
- x.last=NULL;
- printf("\nImplementation of Circular Linked list with function insertend,display,deletebeg,count\n");
- while(1)
- {
- printf("\nenter choice \n1.InsertEnd 2.Deletebeg 3.Count 4.display 5.Exit\n");
- scanf_s("%d",&ch);
- if(ch==5)
- {
- break;
- }
- else
- {
- switch(ch)
- {
- case 1:printf("\nenter element to insert");
- scanf_s("%d",&ele);
- insertend(&x,ele);
- break;
- case 2:deletebeg(&x);
- break;
- case 3:count(&x);
- break;
- case 4:display(&x);
- break;
- default:printf("\ninvalid input");
- }
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement