数学与计算机学院计算机系实验报告
课程名称:数据结构
年级:2011
实验成绩:
指导教师:黄襄念
姓名:王豪
实验教室:6A-413
实验名称:栈或队列的建立与出入操作
学号:3120**********
实验日期:2 栈底
算法特点(优缺点,与可选或同类算法作对比)
栈:先进后出
队列:后进先出
程序说明
系统流程图(各个函数或类的调用流程图)
创建栈/队列
进栈/入队
出栈/出队
输出结果
程序模块(类或函数)代码:包括注释说明、模块功能、I/O参数等
typedef struct //建立结构体
{
ElemType *arr;
int top;
int size;
}SeqStack,*pSeqStack;
pSeqStack SeqStack_Init(pSeqStack sp,int n)//动态创建一个顺序栈
{
sp->arr=new char[n]; //栈数组
sp->size=n; //栈最多可存储n个元素
sp->top=-1; //-1;栈空
return(sp); //返回栈sp;
}
pSeqStack SeqStack_Clear(pSeqStack sp)//将栈sp置成空
{
sp->top=-1; //栈空
return sp;
}
bool SeqStack_isEmpty(pSeqStack sp)//测试栈sp是否为空
{
if(sp->top==-1) //栈空
return true;
else
return false;
}
bool SeqStack_isFull(pSeqStack sp)//判断栈满
{
if(sp->top==(sp->size-1)) //栈满
return true;
else
return false;
}
bool SeqStack_Push(pSeqStack sp,ElemType x)//将元素X入栈sp
{ //x成为新的栈顶元素
if(sp->top==(sp->size-1)) //栈满
return false;
sp->top++;
sp->arr[sp->top]=x; //将元素x赋给栈顶元素
return true;
}
bool SeqStack_Pop(pSeqStack sp,ElemType &x)//将栈顶元素出栈
{
if(sp->top==-1) //栈空
return false;
x=sp->arr[sp->top];
sp->top--;
return true;
}//链队列
pLQueue LinkedQueueCreate()//对队列进行创建
{
pNODE head=new NODE;
head->next=NULL;
pLQueue Q=new LQueue;//LQueue Q
Q->front=Q->rear=head;//
实验2—报告 来自淘豆网m.daumloan.com转载请标明出处.