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