Ejemplo De Pila En C
Enviado por eliadp • 9 de Febrero de 2014 • 597 Palabras (3 Páginas) • 246 Visitas
#include <stdio.h>
#include <stdlib.h>
struct Node{
char c;
struct Node* next;
};
void push(struct Node** Stack, char c){
struct Node* NewNode;
if(*Stack == NULL){ //Si la pila esta vacia
*Stack = (struct Node*)malloc( sizeof(struct Node) );
(*Stack)->c = c;
(*Stack)->next = NULL;
}
else{
NewNode = (struct Node*)malloc( sizeof(struct Node) );
NewNode->c = c;
NewNode->next = *Stack;
*Stack = NewNode;
}
}
char pop(struct Node** Stack){
char c;
struct Node* Temporal;
if(*Stack == NULL)
return '\0';
Temporal = *Stack;
*Stack = (*Stack)->next;
c = Temporal->c;
free(Temporal);
return c;
}
void display(struct Node* Stack){
if(Stack == NULL){
printf("Vacio");
return;
}
while(Stack != NULL){
printf("%c\n", Stack->c);
Stack = Stack->next;
}
}
int main(){
struct Node* Stack = NULL;
char c;
char option = '1';
...