Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int data;
- node *next;
- };
- struct list
- {
- node *head;
- int len;
- void list_ini( )
- {
- head = new node;
- head->next = NULL;
- }
- void list_end( )
- {
- node *tmp;
- node *cur=head;
- while(cur->next != NULL)
- {
- tmp= cur;
- cur=cur->next;
- delete tmp;
- }
- }
- void insert(node *x)
- {
- node *cur=head;
- while(cur->next!=NULL)
- cur=cur->next;
- cur->next=x;
- x->next = NULL;
- }
- void show()
- {
- node *cur=head;
- while(cur->next!=NULL){
- printf("data %d\n",cur->next->data);
- cur=cur->next;}
- }
- void remove(node *y)
- {
- node *cur=head->next;
- if(cur)
- {
- head->next=head->next->next;
- printf("\n%d removed\n",cur->data);
- delete cur;
- }
- else
- printf("\n Q empty \n");
- }
- };
- int main()
- {
- int ch,x;
- node *y,*q;
- list ob;
- ob.list_ini();
- while(1)
- {
- printf("\n1.Enqueue\n2.show\n3.Dequeue\n4.exit\n");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1:
- {
- printf("enter no. ");
- scanf("%d",&x);
- y=new node;
- y->data=x;
- ob.insert(y);
- printf("data inserted....\n");
- break;
- }
- case 2:
- {
- ob.show();
- break;
- }
- case 3:
- {
- ob.remove(y);
- break;
- }
- case 4:
- {
- exit(0);
- }
- default:
- printf("wrong index\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement