Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct node
  5. {
  6.     int data;
  7.     struct node* next;
  8. }grill;
  9.  
  10. grill* fst = NULL;
  11. grill* rear = NULL;
  12.  
  13. void Insert(int);
  14. void Remove();
  15.  
  16. int main()
  17. {  
  18.     Insert(7);
  19.     Insert(10);
  20.     Insert(200);
  21.     Remove();
  22.    
  23.     printf("%d\n", fst->data);
  24.     printf("%d\n", rear->data);
  25.    
  26.     system("pause");
  27.     return 0;
  28. }
  29.  
  30. void Insert(int value) /*Insert one list to the last of the Queue*/
  31. {
  32.     grill* crt;
  33.    
  34.     crt = (grill*)malloc(sizeof(grill));
  35.     crt->data = value;
  36.     crt->next = NULL;  
  37.    
  38.     if(rear == NULL) /*No data*/
  39.     {
  40.         fst = crt;   /*Let crt be the first data*/
  41.     }
  42.     else            
  43.     {
  44.         rear->next = crt;
  45.     }
  46.    
  47.     rear = crt;
  48. }
  49.  
  50. void Remove()       /*Remove the first list of the Queue*/
  51. {
  52.     grill* crt;
  53.    
  54.     if(fst == NULL)
  55.     {
  56.         printf("Queue is empty!\n");
  57.     }
  58.     else
  59.     {
  60.         crt = fst;
  61.         fst = fst->next;      /*Let crt point to fst, and make fst point to the next list*/
  62.     }
  63.    
  64.     free(crt);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement