| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 972 人关注过本帖
标题:[求助]程序有错误,请帮改一改。
只看楼主 加入收藏
zhaobing
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-10-3
收藏
 问题点数:0 回复次数:2 
[求助]程序有错误,请帮改一改。

#include<iostream.h> #include<stdlib.h> #define STACK_INIT_SIZE 100; #define STACKINCREMENT 10; #define OVERFLOW -2; #define ERROR -1; #define OK 1; #define FALSE 0; #define TRUE 1; typedef int Status; typedef char SElemType;

typedef struct{ SElemType * base; SElemType * top; int stacksize; }SqStack; Status InitStack(SqStack &S) { S.base=(SElemType*)malloc(STACK_INIT_SIZE * sizeof(SElemType)) ; if (!S.base) exit (OVERFLOW); S.top=S.base; S.stacksize=STACK_INIT_SIZE; return OK; } Status Push(SqStack &S,SElemType &e){ if(S.top-S.base>=S.stacksize) { S.base=(SElemType * )realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!S.base)exit(OVERFLOW); S.top=S.base+S.stacksize; S.stacksize+=STACKINCREMENT; } *S.top++=e; return OK; } Status Pop(SqStack &S,SElemType &e) { if(S.top==S.base)return ERROR; e=*--S.top; return OK; } Status StackEmpty(SqStack S); { if(S.top==S.base) return TRUE; else return FALSE; }

void main(){ SqStack S; SElemType x,y; InitStack(S); x='c';y='k'; Push(S,x); Push(S,'a'); Push(S,y); Pop(S,x);Push(S,'a'); Push(S,x); Pop(S,x); Push(S,'s'); while (!StackEmpty(S)){Pop(S,y);cout<<y;} cout<<x; }

搜索更多相关主题的帖子: include 
2004-10-17 19:27
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 

#include <iostream.h> #include <stdlib.h>

#define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 #define OVERFLOW -2 #define ERROR -1 #define OK 1 #define FALSE 0 #define TRUE 1

typedef int Status; typedef char SElemType;

typedef struct SqStack { SElemType * base; SElemType * top; int stacksize; }SqStack;

Status InitStack(SqStack & S) { S.base=(SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType)); if (!S.base) exit(OVERFLOW); S.top=S.base; S.stacksize=STACK_INIT_SIZE; return OK; } Status Push(SqStack &S,const SElemType e) { if(S.top-S.base>=S.stacksize) { S.base=(SElemType * )realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType)); if(!S.base) exit(OVERFLOW); S.top=S.base+S.stacksize; S.stacksize+=STACKINCREMENT; } *S.top++=e; return OK; }

Status Pop(SqStack &S,SElemType &e) { if(S.top==S.base) return ERROR; e=*--S.top; return OK; }

Status StackEmpty(SqStack S) { if(S.top==S.base) return TRUE; else return FALSE; }

void main() { SqStack S; SElemType x,y; InitStack(S); x='c'; y='k'; Push(S,x); Push(S,'a'); Push(S,y); Pop(S,x); Push(S,'a'); Push(S,x); Pop(S,x); Push(S,'s'); while (!StackEmpty(S)) { Pop(S,y); cout<<y; } cout<<x; }


自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2004-10-17 19:59
zhaobing
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-10-3
收藏
得分:0 

谢谢!

2004-10-17 22:41
快速回复:[求助]程序有错误,请帮改一改。
数据加载中...
 
   



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

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