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;
}
Atenção a quem posta conteúdo de dicas, scripts e tal (2)
Aprenda a criar músicas com Inteligência Artificial usando Suno AI
Entendendo o que é URI, URL, URN e conhecendo as diferenças entre POST e GET
Ativando o Modo Noturno via Linha de Comando no GNOME/Wayland
Manutenção de sistemas Linux Debian e derivados com apt-get, apt, aptitude e dpkg
Como criar um robot em NTSL (Nelogica Trading System Language) para Profitchart
Use o Google PageSpeed Insights para verificar um site
Problema ao configurar Zabbix no ubuntu (5)
Sistema da Coréia do Norte - Red Star OS (32)