2017-07-16 07:00:51 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2020-05-29 23:23:24 +03:00
|
|
|
// INCLUDES
|
2021-10-15 19:28:04 +03:00
|
|
|
#include "include.h";
|
2017-07-16 07:00:51 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2020-05-29 23:23:24 +03:00
|
|
|
// GLOBAL VARIABLES
|
2017-07-16 07:00:51 +03:00
|
|
|
int count;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2020-05-29 23:23:24 +03:00
|
|
|
// MAIN ENTRY POINT
|
2017-07-16 07:00:51 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
int main(int argc, char const *argv[])
|
|
|
|
{
|
2017-07-16 07:00:51 +03:00
|
|
|
create();
|
|
|
|
enque(5);
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
return 0;
|
2017-07-16 07:00:51 +03:00
|
|
|
}
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
void create()
|
|
|
|
{
|
2017-07-16 07:00:51 +03:00
|
|
|
head = NULL;
|
|
|
|
tail = NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-18 04:37:58 +03:00
|
|
|
/**
|
|
|
|
* Puts an item into the Queue.
|
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
void enque(int x)
|
|
|
|
{
|
|
|
|
if (head == NULL)
|
|
|
|
{
|
2020-10-01 17:28:19 +03:00
|
|
|
head = (struct node *)malloc(sizeof(struct node));
|
2017-07-16 07:00:51 +03:00
|
|
|
head->data = x;
|
|
|
|
head->pre = NULL;
|
|
|
|
tail = head;
|
2020-05-29 23:23:24 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-01 17:28:19 +03:00
|
|
|
tmp = (struct node *)malloc(sizeof(struct node));
|
2017-07-16 07:00:51 +03:00
|
|
|
tmp->data = x;
|
|
|
|
tmp->next = tail;
|
|
|
|
tail = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-18 05:13:45 +03:00
|
|
|
/**
|
|
|
|
* Takes the next item from the Queue.
|
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
int deque()
|
|
|
|
{
|
2020-04-21 13:38:03 +03:00
|
|
|
int returnData = 0;
|
2020-05-29 23:23:24 +03:00
|
|
|
if (head == NULL)
|
|
|
|
{
|
2017-07-16 07:00:51 +03:00
|
|
|
printf("ERROR: Deque from empty queue.\n");
|
|
|
|
exit(1);
|
2020-05-29 23:23:24 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-16 07:00:51 +03:00
|
|
|
returnData = head->data;
|
2020-05-29 23:23:24 +03:00
|
|
|
if (head->pre == NULL)
|
2017-07-16 07:00:51 +03:00
|
|
|
head = NULL;
|
|
|
|
else
|
|
|
|
head = head->pre;
|
|
|
|
head->next = NULL;
|
|
|
|
}
|
2020-05-29 23:23:24 +03:00
|
|
|
return returnData;
|
2017-07-16 07:00:51 +03:00
|
|
|
}
|
2017-07-18 05:13:45 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the size of the Queue.
|
|
|
|
*/
|
2020-10-01 17:28:19 +03:00
|
|
|
int size() { return count; }
|