Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "fifo_fun.h"
- #include <cstdlib>
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- Queue* QCreate()
- {
- Queue* q = (Queue*)calloc(1, sizeof(Queue));
- return q;
- }
- int QEmpty( Queue* q ) // Sprawdza, czy kolejka jest pusta
- {
- return !(q->pHead);
- }
- void QEnqueue( Queue* q, int x ) // Włóż do kolejki
- {
- tagQItem* tmp = (tagQItem*)malloc(sizeof(tagQItem));
- tmp->nKey = x;
- if(q->pTail != NULL)
- q->pTail->pNext = tmp;
- q->pTail = tmp;
- if(q->pHead == NULL)
- q->pHead = q->pTail;
- printf("We have added %d to queue.\n", x);
- }
- int QDequeue( Queue* q ) // Wyrzuć z kolejki
- {
- if( !q )
- {
- printf("ERROR\n");
- return 3;
- }
- if(QEmpty(q))
- {
- printf("Queue is empty!\n");
- return INT_MIN;
- }
- tagQItem* tmp = (tagQItem*)calloc(1, sizeof(tagQItem));
- if( !tmp )
- {
- printf("ERROR");
- return 3;
- }
- int ret = q->pHead->nKey;
- tmp = q->pHead;
- q->pHead = tmp->pNext;
- printf("We have dequeued %d from queue.\n", ret);
- free(tmp);
- return ret;
- /*tagQItem* tmp = q->pHead;
- q->pHead = q->pHead->pNext;
- int ret = tmp->nKey;
- printf("We have dequeued %d from queue.\n", ret);
- free(tmp);
- return ret;*/
- }
- void QClear( Queue* q ) // Czyści wszystko, zostawia kolejkę jako strukturę
- {
- while(!QEmpty(q))
- QDequeue(q);
- printf("Everything from queue was deleted but not structure!\n");
- }
- void QDel( Queue* q ) // Usunięcie całej kolejki
- {
- QClear(q);
- free(q);
- q = NULL;
- printf("Queue was deleted with structure!\n");
- }
- void QWrite( Queue* q )
- {
- QItem* tmp = q->pHead;
- printf("Queue has the form: ");
- while(tmp != q->pTail->pNext)
- {
- printf("%d ", tmp->nKey);
- tmp = tmp->pNext;
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement