-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.c
51 lines (50 loc) · 935 Bytes
/
queue.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
void create(queue *q)
{
q->start = NULL;
q->end = NULL;
}
int insert(queue *q, int data)
{
struct node *aux;
aux = (struct node*) malloc(sizeof(struct node));
if(aux == NULL)
return FALSE;
aux->data = data;
aux->next = NULL;
if(q->start == NULL)
q->start = aux;
if(q->end != NULL)
q->end->next = aux;
q->end = aux;
return TRUE;
}
int removee(queue *q, int *data)
{
struct node *aux;
if(q->start == NULL)
return FALSE;
aux = q->start;
q->start = aux->next;
if(q->start == NULL)
q->end = NULL;
*data = aux->data;
free(aux);
return TRUE;
}
int isEmpty(queue q)
{
if(q.start == NULL)
return TRUE;
return FALSE;
}
void showQueue(queue q)
{
while(!isEmpty(q))
{
printf("%d\n", q.start->data);
q.start = q.start->next;
}
}