Enviado em 02/04/2013 - 00:19h
Galera estou tentando entender as pilhas e estou estudando este codigo retirado do livro do Tenenbaum. So que nao estou conseguindo testar as funcoes pop e push..
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
enum boolean {
TRUE = 1, FALSE=0
};
typedef enum boolean bool;
#define STACKSIZE 100
struct stack {
int top;
int items[STACKSIZE]
};
struct stack s;
//FUNCAO PARA SABER SE PILHA ESTA VAZIA
empty(ps)
struct stack *ps;
{
if (ps->top == NULL) {
return(TRUE);
} else {
return(FALSE);
}
}
//FUNCAO 01 PARA RETIRAR ELEMENTOS DA PILHA
pop(ps)
struct stack *ps;
{
if (empty(ps)) {
printf("%s", "stack underflow");
exit(1);
}
return (ps->items[ps->top~]);
}
//FUNCAO 02 PARA RETIRAR ELEMENTOS DA PILHA
/*
pop(ps)
struct stack *ps;
{
if (!empty(&s)) {
int x = pop(&s);
} else {
printf("\nSTACK UNDERFLOW - Pilha Vazia!!\n");
}
}
*/
//FUNCAO PARA ADD ELEMENTOS NA PILHA
push(ps, x)
struct stack *ps;
int x;
{
if (ps->top == STACKSIZE-1) {
printf("%s", "\nestouro de pilha\n\n");
exit(1);
} else {
ps->items[++(ps->top)]=x;
printf("\nItem inserido\n");
return;
}
}
int main() {
if (empty(&s)) {
printf("\nPilha vazia!!\n\n");
} else {
printf("\nPilha com elementos!!\n");
}
//push(ps, 5);
if (empty(&s)) {
printf("\nPilha vazia!!\n\n");
} else {
printf("\nPilha com elementos!!\n");
}
return 0;
}
Como gerar um podcast a partir de um livro em PDF
Automatizando digitação de códigos 2FA no browser
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Como Instalar o Microsoft Teams no Linux Ubuntu
Músicas de Andrew Hulshult no DOOM (WAD)
Instalar o Apache, MySQL e PHP no Oracle Linux 8
Bloqueando telemetria no Deepin 23.1
Como converter imagens PNG/JPEG para SVG em linha de comando