双向栈实现
(2011-05-02 21:09:16)
标签:
栈双向栈双向栈实现数据结构杂谈 |
分类: 数据结构 |
**************************************************
实验二 双向栈实现
1、
定义栈的存储结构。
2、
编写程序实现双向栈的基本操作:1)初始化;2)判断栈是否为空;3)判断栈是否已满;4)入栈;5)出栈;6)清空栈;7)取栈顶元素。
3、
所写源代码编程风格良好,有详细注释。
4、
程序运行界面良好,使用菜单实现每个基本操作。
****************************************************
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<cstdlib>
#define
NULL 0
#define
MAX 20
#define
TRUE 1
#define
FALSE 0
typedef
struct
tagstack{
//定义一个双向栈
int
* pStack;//栈底
同base指针
int
lefttop;//左栈栈顶
int
righttop;//右栈栈顶
}STACK;
void
menu();
void
choose(STACK *S,int a);
void
InilStack(STACK * S);
int
EmptyStack(STACK S);
int
FullStack(STACK S);
void
PushStack(STACK
*S,int
e);
int
PopStack(STACK
*S,int*
e);
void
ClearStack(STACK *S);
int
GetData(STACK
S,int*
e);//函数声明
void
main(){
//主函数
int
x=0;
STACK
S;//定义双向栈
while(1)
{
menu();//清屏并显示菜单
scanf("%d",&x);getchar();//输入选项吸收回车符
if(x<1||x>8)
printf("\nThe number you entry in is wrong!\n");//若输入的不是选项
提示出错
else if(x==8)
break; else choose(&S,x);//选择为8则退出 否则进行其他操作
printf("\nPress any key to continue...");getch();
}
}
void
menu(){
//菜单函数
printf("\n");
printf("\n
===================================================================");
printf("\n
|
|");
printf("\n
| Welcome!Here is the
menu..
实验二 双向栈实现
1、
2、
3、
4、
****************************************************
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<cstdlib>
#define
#define
#define
#define
typedef
//定义一个双向栈
}STACK;
void
void
void
int
int
void
int
void
int
void
//主函数
}
void
//菜单函数