So I'm doing this stack program , and basically when I try to print the elements in the stack, nothing happens... I'm totally lost : ( , any help would be appreciated.
Oh and some function names are in spanish, llena means full, vacia means empty, the variable cuenta is basically the top of the stack. and imprime means print :)
#include <stdio.h>
#include <stdlib.h>
#define N 10
typedef int elem;
struct pila{
elem datos[N];
int cuenta;
}p;
typedef struct pila tpila;
tpila inicializa(tpila p){
p.cuenta=-1;
return p;
}
int vacia(tpila p){
if(p.cuenta==-1)
return 1;
return 0;
}
int llena(tpila p){
if(p.cuenta==N-1)
return 1;
return 0;
}
elem tope(tpila p){
if(!vacia(p))
return p.datos[p.cuenta];
}
tpila push(tpila p,elem x){
if(!llena(p)){
p.datos[p.cuenta+1]=x;
++p.cuenta;
}
return p;
}
tpila pop(tpila p){
if(!vacia(p))
p.cuenta--;
return p;
}
void imprime(tpila p){
int i;
for(i=p.cuenta;i>=0;i--)
printf("\n%i\n",p.datos[i]);
}
int main()
{
int op,x;
inicializa(p);
do {
printf("Selecciona una opcion:\n1-Push\n2-Pop\n3-Tope\n4-Imprime\n5-Copiar a Pila 2\n6-Imprime Pila 2\n7-Salir\n");
scanf("%i",&op);
switch(op){
case 1:
printf("Escribe el numero a insertar\n");
scanf("%i",&x);
push(p,x);
break;
case 2:pop(p);
break;
case 3: tope(p);
break;
case 4: imprime(p);
break;
}
}while(op!=7);
return 0;
}