
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;
}
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Como impedir exclusão de arquivos por outros usuários no (Linux)
Cirurgia no Linux Mint em HD Externo via USB
Anúncio do meu script de Pós-Instalação do Ubuntu
Duas Pasta Pessoal Aparecendo no Ubuntu 24.04.3 LTS (8)
Alguém pode me indicar um designer freelancer? [RESOLVIDO] (5)
Alguém executou um rm e quase mata a Pixar! (3)
Formas seguras de instalar Debian Sid (1)
Por que passar nas disciplinas da faculdade é ruim e ser reprovado é b... (6)









