Advertisement
Guest User

Untitled

a guest
Apr 7th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 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.     // q - указатель на очередь или указатель на next
  12.     //последнего ненулевого элемента.
  13.     while ((elem = ∗q) != NULL)
  14.         q = &elem->next;
  15.     elem = malloc(sizeof(∗elem));
  16.     if (elem) {
  17.         elem->info = item;
  18.         elem->next = NULL;
  19.         ∗q = elem;
  20.     }
  21. }
  22. int main()
  23. {
  24.     queue *q1 = (queue*) malloc(sizeof(queue));
  25.     q1->next = NULL;
  26.     insert(&q1, 1);
  27.     insert(&q1, 2);
  28.     insert(&q1, 3);
  29.     insert(&q1, 4);
  30.     insert(&q1, 5);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement