Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //D.B.John PC
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int data;
- struct node *next;
- };
- struct node *top=NULL,*temp;
- 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 count(struct node *head);
- // void Insertion_last_position(struct node *head, int value);
- // void Insertion_specific_position(struct node *head, int vv, int pp);
- // void Deletion_specific_position(struct node *head, int pp);
- 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->data=0;
- rear->next=NULL;
- while(1)
- {
- printf("\n ....Menu....\n");
- printf("\n press 0 Quit\n");
- printf("\n press 1 for Insertion \n");
- printf("\n press 2 Deletion \n");
- printf("\n press 3 Display\n");
- printf("\n press 4 Count\n");
- printf("\n Enter your choise \n");
- scanf("%d",&c);
- switch(c)
- {
- case 0:exit (0);
- break;
- case 1:printf("\n choise=Insertion \n ");
- printf("\n Enter NEW value\n");
- scanf("%d",&v);
- Insertion(front,rear,v);
- break;
- case 3: printf("\n Choise=Display \n");
- if(front->next !=NULL)
- Display(front);
- else
- printf("\n NO data to display \n Queue \n is Empty \n");
- break;
- case 2: printf("\n choise=deletion\n");
- if(front->next!=NULL)
- Deletion(front,rear);
- else
- printf("\n NO data to delete the queu is empty\n");
- break;
- case 4: printf("\n choise=count\n");
- count(front);
- break;
- default:printf("\n Wrong Choise\n");
- break;
- }
- }
- }
- //user define
- 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("\n \t %d",f->next->data);
- f=f->next;
- }
- }
- 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 is =%d\n\n",temp->data);
- free(temp);
- }
- 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);
- }
Add Comment
Please, Sign In to add comment