-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamicQueue.c
121 lines (96 loc) · 2.1 KB
/
dynamicQueue.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <stdlib.h>
#include <stdio.h>
#include "dynamicQueue.h"
struct node{
struct student data;
struct node *next;
};
typedef struct node Node;
struct descriptor{
struct node *begin ,*end;
int size;
};
dynamicQueue* create(){
dynamicQueue* ptr = (dynamicQueue*) malloc(sizeof(dynamicQueue));
if(ptr != NULL){
ptr->begin = NULL;
ptr->end = NULL;
ptr->size = 0;
}
return ptr;
}
void release(dynamicQueue* q){
if(q != NULL){
Node* n;
while(q->begin != NULL){
n = q->begin;
q->begin = q->begin->next;
free(n);
}
free(q);
}
}
int size(dynamicQueue* q){
if(q == NULL) return -1;
return q->size;
}
int empty(dynamicQueue* q){
if(q == NULL) return -1;
return (q->size == 0);
}
int full(dynamicQueue* q){
if(q == NULL) return -1;
return 0;
}
int push(dynamicQueue* q, struct student student){
if(q == NULL) return 0;
Node* n = (Node*) malloc(sizeof(Node));
if(n == NULL) return 0;
n->data = student;
n->next = NULL;
if(empty(q)){
q->begin = n;
}else{
q->end->next = n;
}
q->end = n;
q->size++;
return 1;
}
int pop(dynamicQueue* q){
if(q == NULL) return 0;
if(empty(q)) return 0;
Node* aux = q->begin;
q->begin = q->begin->next;
if(q->begin == NULL) q->end = NULL;
free(aux);
q->size--;
return 1;
}
int front(dynamicQueue* q, struct student* student){
if(q == NULL) return 0;
if(empty(q)) return 0;
*student = q->begin->data;
return 1;
}
int back(dynamicQueue* q, struct student* student){
if(q == NULL) return 0;
if(empty(q)) return 0;
*student = q->end->data;
return 1;
}
int show(dynamicQueue* q){
if(q == NULL) return 0;
if(empty(q)) return 0;
Node* current = q->begin;
printf("\n=-=-=-=-=-=-=-=-=-Queue of Students-=-=-=-=-=-=-=-=-=\n");
while(current != NULL){
printf("Name: %s", current->data.name);
printf("Enrollment: %d\n", current->data.enrollment);
printf("Pontuation 1: %.2f\n", current->data.p1);
printf("Pontuation 2: %.2f\n", current->data.p2);
printf("Pontuation 3: %.2f\n\n", current->data.p3);
current = current->next;
}
return 1;
}