Menu - Mi codigo compila pero no funciona y me gustaria saber por que
Publicado por Mariel (1 intervención) el 05/05/2016 23:33:03
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
include <memory.h>
#include <stdlib.h>
typedef struc#include "librerias.h"
t tCell {
int payload;
void* next;
} Cell;
Cell* agregar(Cell *root, int numero){ //Agrega nodo
Cell *nuevo_nodo;
nuevo_nodo = (Cell*)malloc(sizeof(Cell));
nuevo_nodo -> payload= numero;
nuevo_nodo->next = NULL;
Cell *cursor = root;
while(cursor->next!= NULL){
cursor = (Cell *)cursor -> next;
}
cursor -> next = (void*)nuevo_nodo;
return root;
}
void imprime_lista(Cell *root){ //Imprime Lista
while ((root = (root->next)) != NULL){
printf("--> %d", root->payload);
root = root->next;
}
}
Cell *pop(Cell *root){ //Salir
Cell *cursor = root;
if(root->next == NULL) return root;
while(((Cell*)cursor->next)->next != NULL){
cursor = (Cell*)cursor->next;
}
free(cursor->next);
cursor->next = NULL;
return root;
}
Cell *erase(Cell *root){ //Borrar
while (root->next != NULL){
pop(root);
}
return root;
}
int imprime_menu(){
int menu;
printf("Elige una opcion: \n 0 - Agrega nodo \n 1 - Borra ultimo nodo \n 2 - Imprime Lista \n 3 - Salir \n");
scanf("%d", &menu);
return menu;
}
int main(int argc, char* argv[]){
Cell root;
int menu_final;
root.payload = -1;
root.next = NULL;
int menu = imprime_menu();
while(menu != 3){
if(menu == 0){
printf("Escribe un numero (ya sea 0, 1, 2 ó 3): ");
scanf("%d", &menu_final);
agregar(&root, menu_final);
printf("\n");
}
else if(menu == 1){
pop(&root);
}
else if(menu == 2){
imprime_lista(&root);
}
printf("\n");
menu = imprime_menu();
}
erase(&root);
return 0;
}
//Mi codigo compila pero no funciona y me gustaria saber por que
Valora esta pregunta


0