Potreboval by som poradiť maam Doplniť do tejto implementácie frontu v C s využitím štruktúry funkciu void QUEUEdestroy(p_QUEUE queue), ktorá vhodne deštruuje front = dealokuje pamäť alokovanú frontom. nejako si s tym neviem dať rady :(
typedef int itemType;
typedef struct QUEUEnode* p_QUEUEnode;
struct QUEUEnode
{
itemType item;
p_QUEUEnode next;
};
void QUEUEinit();
void QUEUEdestroy();
int QUEUEisempty();
void QUEUEput(itemType i);
itemType QUEUEget();
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
p_QUEUEnode head, tail;
p_QUEUEnode NEW(itemType item, p_QUEUEnode next)
{
p_QUEUEnode x = malloc(sizeof *x);
x->item = item; x->next = next;
return x;
}
void QUEUEinit()
{
head = NULL;
}
int QUEUEisempty()
{
return head == NULL;
}
void QUEUEput(itemType item)
{
if (head == NULL)
{
head = (tail = NEW(item, head));
return;
}
tail->next = NEW(item, tail->next);
tail = tail->next;
}
itemType QUEUEget()
{
itemType item = head->item;
p_QUEUEnode t = head->next;
free(head); head = t;
return item;
}#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
p_QUEUEnode head, tail;
p_QUEUEnode NEW(itemType item, p_QUEUEnode next)
{
p_QUEUEnode x = malloc(sizeof *x);
x->item = item; x->next = next;
return x;
}
void QUEUEinit()
{
head = NULL;
}
int QUEUEisempty()
{
return head == NULL;
}
void QUEUEput(itemType item)
{
if (head == NULL)
{
head = (tail = NEW(item, head));
return;
}
tail->next = NEW(item, tail->next);
tail = tail->next;
}
itemType QUEUEget()
{
itemType item = head->item;
p_QUEUEnode t = head->next;
free(head); head = t;
return item;
}
#include <stdio.h>
#include "queue.h"
int main (int argc, char *argv[])
{
QUEUEinit(100);
for (int i=0; i<10; i++)
QUEUEput(i);
while (!QUEUEisempty())
printf("Item from queue: %d\n", QUEUEget());
return 0;
}