| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 627 人关注过本帖
标题:[求助]栈的顺序存储小程序运行不了。。。
只看楼主 加入收藏
蚁仔
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2005-11-27
收藏
 问题点数:0 回复次数:2 
[求助]栈的顺序存储小程序运行不了。。。

菜鸟一只,各位大虾看下是为什么运行不了,不知道哪里出错了~~~


/*顺序栈的基本操作*/

#include <stdio.h>
#define MaxSize 100
typedef char ElemType;

typedef struct
{
char stack[MaxSize];
int top;
} stacktype;

void initstack(stacktype *S)
{
S->top=-1;
}

void push(stacktype *S,ElemType x)
{
if (S->top==MaxSize) printf("栈上溢出!\n");
else
{
S->top++;
S->stack[S->top]=x;
}
}

void pop(stacktype *S)
{
if (S->top==-1) printf("栈下溢出!\n");
else S->top--;
}

ElemType gettop(stacktype *S)
{
if (S->top==-1) printf("栈空!\n");
else return(S->stack[S->top]);
}

int empty(stacktype *S)
{
if (S->top==-1) return(1);
else return(0);
}

void display(stacktype *S)
{
int i;
printf("栈中元素:");
for (i=S->top;i>=0;i--)
printf("%c ",S->stack[i]);
printf("\n");
}


main()
{
stacktype *st;
printf("建立一空栈\n");
initstack(st);
printf("栈空:%d\n",empty(st));
printf("依次插入a,b,c,d元素\n");
push(st,'a');
push(st,'b');
push(st,'c');
push(st,'d');
display(st);
printf("退一次栈\n");
pop(st);
printf("栈顶元素:%c\n",gettop(st));
printf("退一次栈\n");
pop(st);
display(st);
}

谢谢~~

搜索更多相关主题的帖子: 运行 顺序 
2005-12-03 13:04
坏孩子
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2005-11-26
收藏
得分:0 

有些地方没有返回值,我用VC6编译的改好就可以了


#include <stdio.h>
#define MaxSize 100
typedef char ElemType;

typedef struct
{
char stack[MaxSize];
int top;
} stacktype;

void initstack(stacktype *S)
{
S->top=-1;
}

void push(stacktype *S,ElemType x)
{
if (S->top==MaxSize) printf("栈上溢出!\n");
else
{
S->top++;
S->stack[S->top]=x;
}
}

void pop(stacktype *S)
{
if (S->top==-1) printf("栈下溢出!\n");
else S->top--;
}

ElemType gettop(stacktype *S)
{
if (S->top==-1) {
printf("栈空!\n");
return 0;
}
else return(S->stack[S->top]);
}

int empty(stacktype *S)
{
if (S->top==-1) return(1);
else return(0);
}

void display(stacktype *S)
{
int i;
printf("栈中元素:");
for (i=S->top;i>=0;i--)
printf("%c ",S->stack[i]);
printf("\n");
}


main()
{
stacktype *st;
printf("建立一空栈\n");
initstack(st);
printf("栈空:%d\n",empty(st));
printf("依次插入a,b,c,d元素\n");
push(st,'a');
push(st,'b');
push(st,'c');
push(st,'d');
display(st);
printf("退一次栈\n");
pop(st);
printf("栈顶元素:%c\n",gettop(st));
printf("退一次栈\n");
pop(st);
display(st);
return 0;
}

2005-12-03 17:30
蚁仔
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2005-11-27
收藏
得分:0 
谢谢~~
可是问题还存在啊。
我在构件的时候没有错误。
在运行时就提示说该文件遇到问题需要关闭的窗口,这是为什么呀?
还是我的用的VC有问题??
2005-12-03 20:32
快速回复:[求助]栈的顺序存储小程序运行不了。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014700 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved