Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. typedef struct QUEUE
  5. {
  6. int info;
  7. struct QUEUE *next;
  8. }queue;
  9. void insert(queue **q, int item)
  10. {
  11. queue *cur = *q;
  12. queue *pred = 0;
  13. queue *newn;
  14. while (cur)
  15. {
  16. pred = cur;
  17. cur = cur->next;
  18. }
  19. newn = (queue *)malloc(sizeof(queue));
  20. newn->info = item;
  21. if (pred)
  22. {
  23. newn->next = pred->next;
  24. pred->next = newn;
  25. }
  26. else
  27. {
  28. *q = newn;
  29. (*q)->next = 0;
  30. }
  31. }
  32. int main()
  33. {
  34. queue *q1;
  35. insert(&q1, 1);
  36. insert(&q1, 2);
  37. insert(&q1, 3);
  38. insert(&q1, 4);
  39. insert(&q1, 5);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement