-
Notifications
You must be signed in to change notification settings - Fork 0
/
5-Turne.c
89 lines (75 loc) · 1.63 KB
/
5-Turne.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct node {
char value[27];
struct node *next;
} node;
node *head;
node *tail;
int queueInitialize(node *n) {
if (n == NULL) {
return 0;
}
node* head = NULL;
node* tail = NULL;
return 1;
}
char * check(node *n) {
return head->value;
}
void enqueue(node *n, char valueToEnqueue[]) {
node *temp = malloc(sizeof(node));
strcpy(temp->value, valueToEnqueue);
temp->next = NULL;
if (head == NULL && tail == NULL) {
head = temp;
tail = temp;
}
else {
tail->next = temp;
tail = temp;
}
}
void dequeue(node *n) {
if (head != NULL && head != tail) {
node *temp = head;
char *value = temp->value;
head = temp->next;
free(temp);
}
else if (head == tail && head != NULL && tail != NULL) {
node *temp = head;
char *data = head->value;
head = NULL;
tail = NULL;
free(temp);
}
else {
printf("You cannot remove a node from an empty list.\n");
}
}
int isEmpty(node *n) {
return head == NULL && tail == NULL;
}
int main(){
char leitura[27];
node *n = malloc(sizeof(node));
queueInitialize(n);
while (scanf("%s", leitura) == 1) {
enqueue(n, leitura);
}
while (!isEmpty(n)) {
node *temp = malloc(sizeof(node));
strcpy(temp->value, check(n));
printf("%s\n", temp->value);
dequeue(n);
if (isEmpty(n)) {
break;
}
if (temp->value[strlen(temp->value) - 1] == check(n)[0]+32) {
enqueue(n, check(n));
dequeue(n);
}
}
}