Some refactoring.

This commit is contained in:
2023-11-10 12:56:21 -08:00
parent f6688acfc7
commit fe5cd908f8
5 changed files with 153 additions and 106 deletions

37
queue.c Normal file
View File

@@ -0,0 +1,37 @@
#include "queue.h"
void qinit(queue *item)
{
item->first = NULL;
item->last = NULL;
}
void qput(queue *item, particle data)
{
if(!item->first) {
item->first = malloc(sizeof(struct node));
item->last = item->first;
} else {
item->last->next = malloc(sizeof(struct node));
item->last = item->last->next;
}
item->last->data = data;
item->last->next = NULL;
}
void qget(queue *item, particle *data)
{
if(data)
*data = item->first->data;
struct node *tmp = item->first;
item->first = item->first->next;
if(!item->first)
item->last = NULL;
free(tmp);
}
int qempty(queue *item)
{
return !item->first;
}