HmHimu

QueUe

Feb 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<stdlib.h>
  4. using namespace std;
  5. struct Node
  6. {
  7.     int data;
  8.     struct Node *next;
  9. }*node,*temp;
  10. struct Head
  11. {
  12.     int count;
  13.     struct Node *rear, *frnt;
  14. }*head;
  15.  
  16. void creat_head()
  17. {
  18.     head=(struct Head*)malloc(sizeof(struct Head));
  19.     head->count=0;
  20.     head->frnt=NULL;
  21.     head->rear=NULL;
  22.  
  23. }
  24.  
  25. void creat_1st_node()
  26. {
  27.     node=(struct Node*)malloc(sizeof(struct Node));
  28.     scanf("%d",&node->data);
  29.     node->next=NULL;
  30.     head->frnt=node;
  31.     head->rear=node;
  32.     head->count++;
  33.  
  34. }
  35.  
  36. void creat_node()
  37. {
  38.     node=(struct Node*)malloc(sizeof(struct Node));
  39.     scanf("%d",&node->data);
  40.     node->next=NULL;
  41.     head->rear->next=node;
  42.     head->rear=node;
  43.     head->count++;
  44. }
  45.  
  46. void delet_node()
  47. {
  48.     temp=head->frnt;
  49.     head->frnt=temp->next;
  50.     free(temp);
  51.     head->count--;
  52.  
  53. }
  54. void display()
  55. {
  56.     temp=head->frnt;
  57.     for(int i=0; i<head->count; i++)
  58.     {
  59.         cout<<temp->data<<endl;
  60.         temp=temp->next;
  61.     }
  62.  
  63. }
  64.  
  65. int main()
  66. {
  67.  
  68.     creat_head();
  69.     cout<<"creat 1st node"<<endl;
  70.  
  71.     creat_1st_node();
  72.     cout<<"Add node"<<endl;
  73.     creat_node();
  74.     cout<<"Add node"<<endl;
  75.     creat_node();
  76.  
  77.     cout<<"Add node"<<endl;
  78.     creat_node();
  79.  
  80.     cout<<"first node deleted"<<endl;
  81.     delet_node();
  82.  
  83.     cout<<"Queue display"<<endl;
  84.     display();
  85.  
  86.  
  87.  
  88.     return 0;
  89. }
Add Comment
Please, Sign In to add comment