-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeste16-17.c
109 lines (102 loc) · 1.64 KB
/
Teste16-17.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
//Parte A
typedef struct slist {int valor;struct slist *prox;} *LInt;
typedef struct nodo {int valor;struct nodo *esq, *dir;} *ABin;
//1
int limpaEspacos (char t[]){
int r=0,i;
for(i=0; t[i] != '\0'; i++){
t[r] = t[i];
if(t[i] != ' ' || t[i+1] != ' ') r++;
}
t[r] = '\0';
return r;
}
//2
void transposta (int N, float m [N][N]){
int i,j;
float aux;
for(i=0; i<N; i++){
for(j=i; j<N; j++){
aux = m[i][j];
m[i][j] = m[j][i];
m[j][i] = aux;
}
}
}
//3
LInt clone (LInt l){
LInt inicio=NULL, *nodo;
nodo = &inicio;
while(l){
*nodo = malloc(sizeof(struct lligada));
(*nodo)->valor = l->valor;
nodo = &((*nodo)->prox);
l = l->prox;
}
*nodo = NULL;
return inicio;
}
//4
int nivelV (ABin a, int n, int v[]){
int c=0;
if(a){
if(n==1){
v[c] = a->valor;
c++;
}
else{
c += nivelV(a->esq,n-1,v+c);
c += nivelV(a->dir,n-1,v+c);
}
}
return c;
}
//5
void removeMaiorA (ABin *a){
ABin aux;
while((*a)->dir) a = &((*a)->dir);
aux = (*a)->esq;
free (*a);
*a = aux;
}
//Parte B
typedef struct chunk {
int vs [MAXc];
struct chunk *prox;
} *CList;
typedef struct stackC {
CList valores;
int sp;
} StackC;
//1
int push (StackC *s, int x){
int r=0;
if(s->sp == MAXc){
CList novo = malloc(sizeof(struct chunk));
novo->vs[0] = x;
novo->prox = s->valores;
s->valores = novo;
s->sp = 1;
}
else {
s->(valores->vs[(s->sp]) = x;
s->sp ++;
}
return r;
}
//2
int pop (StackC *s, int *x){
int r=0;
CList aux;
if(s->valores){
if(s->sp == 1){
aux = s->(valores->prox);
free(s->valores);
s->valores = aux;
sp = MAXc;
}
else s->sp --;
}
else r=1;
return r;
}