Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define ROZMIAR 5
- struct fifo_node
- {
- char data;
- struct fifo_node *next;
- };
- struct fifo_pointers
- {
- struct fifo_node *head, *tail;
- }fifo;
- void enqueue(struct fifo_pointers *fifo, char data) ///dodawanie elementu do kolejki ( na koniec - ogon)
- {
- struct fifo_node *new_node = (struct fifo_node *)malloc(sizeof(struct fifo_node));
- if(new_node)
- {
- new_node -> data = data;
- new_node -> next = NULL;
- if(fifo -> head == NULL)
- fifo->head=fifo->tail=new_node;
- else {
- fifo->tail->next = new_node ;
- fifo->tail = new_node;
- }
- }
- else
- printf("Nowy element nie zostal utworzony");
- }
- int dequeue(struct fifo_pointers *fifo) ///usuwanie elementu z kolejki ( z poczatku - glowa)
- {
- if(fifo->head)
- {
- struct fifo_node *tmp = fifo->head->next;
- char data = fifo->head->data;
- free(fifo->head);
- fifo->head = tmp;
- if(tmp == NULL)
- fifo->tail= NULL;
- return data;
- }
- return -1;
- }
- int main ()
- {
- char znak;
- printf("Wpisz zdanie/slowo do kolejki: \t");
- do
- {
- scanf("%c", &znak);
- enqueue(&fifo,znak);
- }while(znak != '\n');
- printf("Elementy w kolejce: \t");
- while(fifo.head)
- printf(" %c", dequeue(&fifo));
- puts(" ");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement