Advertisement
ledrose

queue

Jan 28th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct element {
  5.     int data;
  6.     struct element *p;
  7. };
  8.  
  9. void addElement(struct element **cur) {
  10.     struct element *memory;
  11.     memory=(struct element *) malloc(sizeof(struct element));
  12.     memory->data=rand()%100+1;
  13.     memory->p=NULL;
  14.     if (*cur) {
  15.         (*cur)->p=memory;
  16.     }
  17.     *cur=memory;
  18. }
  19.  
  20. void removeElement(struct element **cur) {
  21.     struct element *memory=(*cur)->p;
  22.     free(*cur);
  23.     *cur=memory;
  24. }
  25.  
  26.  
  27. int main()
  28. {
  29.     struct element *start=NULL, *end=NULL;
  30.     addElement(&end);
  31.     start=end;
  32.     addElement(&end);
  33.     addElement(&end);
  34.     addElement(&end);
  35.     removeElement(&start);
  36.     removeElement(&start);
  37.     while (end) {
  38.         printf("%d\n",start->data);
  39.  
  40.         start=start->p;
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement