Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define ILOSC 5
- float wynik;
- struct fifo_node
- {
- int data;
- struct fifo_node *next,*previous;
- };
- struct fifo_pointers
- {
- struct fifo_node *head, *tail,*prev;
- }fifo;
- void enqueueFront(struct fifo_pointers *fifo, int data)
- {
- struct fifo_node *new_node = (struct fifo_node *)malloc(sizeof(struct fifo_node));
- if(new_node)
- {
- new_node->data = data;
- new_node->next = NULL;
- new_node->previous=NULL;
- if(fifo->head==NULL)
- fifo->head = fifo->tail = fifo->prev = new_node;
- else
- {
- fifo->tail->next=new_node;
- fifo->tail=new_node;
- }
- } else
- fprintf(stderr,"Nowy element nie zosta³ utworzony!\n");
- }
- void enqueueBack(struct fifo_pointers *fifo, int data)
- {
- struct fifo_node *new_node = (struct fifo_node *)malloc(sizeof(struct fifo_node));
- if(new_node)
- {
- new_node->data = data;
- new_node->next = NULL;
- new_node->previous=NULL;
- if(fifo->head==NULL)
- fifo->head = fifo->tail = fifo->prev = new_node;
- else
- {
- fifo->head->previous =new_node;
- new_node->next=fifo->head;
- fifo->head=new_node;
- }
- } else
- fprintf(stderr,"Nowy element nie zosta³ utworzony!\n");
- }
- int dequeueBegin(struct fifo_pointers *fifo)
- {
- if(fifo->head) {
- struct fifo_node *tmp = fifo->head->next;
- int data = fifo->head->data;
- free(fifo->head);
- fifo->head=tmp;
- if(tmp==NULL)
- fifo->tail = NULL;
- return data;
- }
- return -1;
- }
- void print_queue(struct fifo_pointers fifo)
- {
- while(fifo.head)
- {
- printf("%d ",fifo.head->data);
- fifo.head = fifo.head->next;
- }
- puts("");
- }
- void print_queue_with_for(struct fifo_pointers fifo)
- {
- for(;fifo.head;fifo.head=fifo.head->next)
- printf("%d ",fifo.head->data);
- puts("");
- }
- int main(void)
- {
- int liczba;
- int i;
- enqueueBack(&fifo,4);
- enqueueBack(&fifo,5);
- enqueueFront(&fifo,3);
- enqueueFront(&fifo,8);
- enqueueBack(&fifo,3);
- while(fifo.head)
- {
- printf("%d",dequeueBegin(&fifo));
- }
- puts("");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement