-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10-Sanidade.c
96 lines (77 loc) · 2.05 KB
/
10-Sanidade.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
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
long unsigned int curr;
long unsigned int prev;
long unsigned int post;
} node;
typedef node* Item;
typedef struct no_st{
Item item;
struct no_st *prox;
}No;
typedef struct header_St{
No *inicio;
No *final;
}Header;
int list_initialize(Header *H){
H -> inicio = NULL;
H -> final = NULL;
return 1;
}
int push_back(Header *H, Item insert){
No *temp = malloc(sizeof(No));
if(temp == NULL)return 0;
temp -> item = insert;
temp -> prox = NULL;
if(H -> final == NULL){H -> final = temp;}
else{
H -> final -> prox = temp;
H -> final = temp;
}
if(H -> inicio == NULL){H -> inicio = H -> final;}
return 1;
}
void checkSanity(long unsigned int * firstNode, long unsigned int * lastNode, Header *h) {
if (firstNode[2] == lastNode[0]) {
if (firstNode[0] == lastNode[1]) {
printf("sana\n");
return;
}
else {
printf("insana\n");
return;
}
}
No *temp = h->inicio;
while (firstNode[2] != temp->item->curr && temp->prox != NULL) {
temp = temp->prox;
}
if (firstNode[2] == temp->item->curr) {
firstNode[0] = temp->item->curr;
firstNode[1] = temp->item->prev;
firstNode[2] = temp->item->post;
checkSanity(firstNode, lastNode, h);
}
else if (temp->prox == NULL) {
printf("insana\n");
return;
}
}
int main() {
Header *h = malloc(sizeof(Header));
list_initialize(h);
long unsigned int curr, prev, post;
long unsigned int firstNode[3];
long unsigned int lastNode[3];
scanf("%lx %lx %lx", &firstNode[0], &firstNode[1], &firstNode[2]);
scanf("%lx %lx %lx", &lastNode[0], &lastNode[1], &lastNode[2]);
while (scanf("%lx %lx %lx", &curr, &prev, &post) == 3) {
node *n = malloc(sizeof(node));
n->curr = curr;
n->prev = prev;
n->post = post;
push_back(h, n);
}
checkSanity(firstNode, lastNode, h);
}