魔兽世界思维敏捷药水:c语言,帮我看我的程序错在哪?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 20:05:47
void stack_entire(Stack *s,SElem *e)
{
Stack h;
if(isempty(s))
printf("This is a empty stack\n");
else
{
while(!isempty(s)){
pop(s,e);
printf("%d",e);
push(&h,e);
}

while(!isempty(&h)){
pop(&h,*e);
push(s,e);
}
}
}
我想显示栈里面所有元素,但是显示不出

以下是完整的程序
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define Max 10

typedef enum bool{TRUE,FALSE}BOOL;
typedef int SElem;
typedef struct stack
{
SElem Elem[Max];
int top;
int base;

}Stack;

void push_data(Stack *s,SElem e);
void pop_data(Stack *s,SElem *e);
void gettop_stack(Stack *s,SElem *e);
void stack_traverse(Stack *s,SElem *e);
void destroy_stack(Stack *s);
void create_stack(Stack *s);
void push(Stack *s,SElem e);
void pop(Stack *s,SElem *e);
void stack_entire(Stack *s,SElem *e);
BOOL isempty(Stack *s);
BOOL isfull(Stack *s);

void push_data(Stack *s,SElem e)
{
int ans;
if(isfull(s))
printf("This is a full stack\n");
else{
printf("Push data into stack:");
scanf("%d%c",&e,&ans);
push(s,e);
}
}

void pop_data(Stack *s,SElem *e)
{

if(isempty(s))
printf("This is a empty stack\n");
else
{
pop(s,e);
printf("Elements:%d\n",*e);
}
}

void gettop_stack(Stack *s,SElem *e)
{
if(isempty(s))
printf("This is a empty stack\n");
else
{
*e=s->Elem[s->top-1];
printf("Data at top of stack:%d",*e);
}
}

void stack_entire(Stack *s,SElem *e)
{
Stack h;
if(isempty(s))
printf("This is a empty stack\n");
else
{
while(!isempty(s)){
pop(s,e);
printf("%d",e);
push(&h,e);
}

while(!isempty(&h)){
pop(&h,*e);
push(s,e);
}
}
}
void destroy_stack(Stack *s)
{
free(s);
}

void create_stack(Stack *s)
{
s->top=0;
s->base=9;
}

void push(Stack *s,SElem e)
{
s->Elem[s->top]=e;
s->top++;
}

void pop(Stack *s,SElem *e)
{
s->top--;
*e=s->Elem[s->top];
}
BOOL isempty(Stack *s)
{
return((BOOL)(s->top==0));
}
BOOL isfull(Stack *s)
{
return((BOOL)(s->top>=Max));
}
void main()
{
Stack h;
SElem e=0;
int num;
create_stack(&h);
do
{
printf("\n\nDemo stack is running\n");
printf("1.Push data\n");
printf("2.Pop data\n");
printf("3.Print data at top of stack\n");
printf("4.Print entire data(From top to base)\n");
printf("5.Print status\n");
printf("6.Number of element\n");
printf("7.Destroy stack and quit\n\n");
printf("Please insert your selection:");
scanf("%d",&num);

switch(num)
{
case 1:push_data(&h,e);break;
case 2:pop_data(&h,&e);break;
case 3:gettop_stack(&h,&e);break;
case 4:stack_entire(&h,&e);break;
case 5:stack_status(&h);break;
case 6:stack_length(&h);break;
case 7:destroy_stack(&h);return;
default:
printf("Selection invalid\n");
}
}while(1);
return;
}

这个题我通了,还有什么问题直接问吧。

void stack_entire(Stack *s,SElem *e)
{
Stack h;
create_stack(&h);
if(isempty(s))
printf("This is a empty stack\n");
else
{
while(!isempty(s)){
pop(s,e);
printf("%d,",*e);
push(&h,*e);
}

while(!isempty(&h)){
pop(&h,e);
push(s,*e);
}
}
}

你的有几个函数没定义啊
stack_status(&h)
stack_length(&h)
destroy_stack(&h)
定义完这些就可以了

你把这几个屏蔽后试试程序没问题的!!!!!!!!