Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- typedef struct QUEUE
- {
- int info;
- struct QUEUE *next;
- }queue;
- void insert(queue **q, int item)
- {
- queue *cur = *q;
- queue *pred = 0;
- queue *newn;
- while (cur)
- {
- pred = cur;
- cur = cur->next;
- }
- newn = (queue *)malloc(sizeof(queue));
- newn->info = item;
- if (pred)
- {
- newn->next = pred->next;
- pred->next = newn;
- }
- else
- {
- *q = newn;
- (*q)->next = 0;
- }
- }
- int main()
- {
- queue *q1;
- insert(&q1, 1);
- insert(&q1, 2);
- insert(&q1, 3);
- insert(&q1, 4);
- insert(&q1, 5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement