Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- struct node
- {
- int data;
- struct node *next;
- };
- void Insertion(struct node *f, struct node *r,int vv);
- void Display(struct node *f);
- void Deletion (struct node *f,struct node *r);
- void Count (struct node *f);
- int main()
- {
- int c,v;
- struct node *front, *rear;
- front=(struct node*)malloc(sizeof (struct node));
- rear =(struct node*)malloc(sizeof (struct node));
- front ->data=0;
- front ->next=NULL;
- rear ->next=NULL;
- while(1)
- {
- printf("\n -----Menu-----\n");
- printf("\n 0 For Exit\n");
- printf ("\n 1 For Insertion\n");
- printf("\n 2 For Deletion\n");
- printf ("\n 3 For Display\n");
- printf ("\n 4 For Count\n");
- printf("\n Enter Your choice\n");
- scanf ("%d",&c);
- switch(c)
- {
- case 0: exit(0);
- break;
- case 1:printf("\n choice =Insertion\n");
- printf("\n Enter New Value\n");
- scanf ("%d",&v);
- Insertion (front,rear,v);
- break;
- case 2:printf("\n choice=Deletion\n");
- if(front->next!=NULL)
- Deletion(front,rear);
- else
- printf("\n The QUEUE is Empty");
- break;
- case 3:printf("\n choice=Display\n");
- if(front ->next!=NULL)
- Display(front);
- else
- printf("\n The Queue is Empty\n\n");
- break;
- case 4:printf("\n choice=Count\n");
- Count(front);
- break;
- default: printf("\n Wrong choice");
- }
- }
- }
- void Insertion(struct node *f, struct node *r,int vv)
- {
- struct node *temp;
- temp=(struct node*)malloc(sizeof (struct node));
- temp->data=vv;
- temp->next=NULL;
- if(f->next==NULL)
- {
- f->next=temp;
- r->next=temp;
- }
- else
- {
- r->next->next=temp;
- r->next=temp;
- }
- }
- void Display(struct node *f)
- {
- while (f->next!=NULL)
- {
- printf("\t %d",f->next->data);
- f=f->next;
- }
- }
- void Count (struct node *f)
- {
- int t=0;
- while(f->next!=NULL)
- {
- t=t+1;
- f=f->next;
- }
- printf("\n Total node=%d \n\n",t);
- }
- void Deletion (struct node *f,struct node *r)
- {
- struct node*temp;
- temp=f->next;
- if(f->next==r->next)
- {
- f->next=NULL;
- r->next=NULL;
- }
- else
- {
- f->next=temp->next;
- }
- printf("\n THE DELETED NODE=%d\n\n",temp->data);
- free(temp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement