文档介绍:-
. z.
"数据构造"课程实验实训报告
实验名称
栈与队列
实验序号
3
学 号
14302043
姓 名
前方
班 级
信管本二
实验日顶元素并把栈顶元素由参数d带回*/
{
-
. z.
LSNode *p = head->ne*t;
if(p == NULL)
{
printf("堆栈已空出错!");
return 0;
}
*d = p->data;
return 1;
} /*撤销*/
void Destroy(LSNode *head)
{
LSNode *p, *p1;
p = head;
while(p != NULL)
{
p1 = p;
p = p->ne*t;
free(p1);
}
}
void main(void)
-
. z.
{
LSNode *myStack;
int i, *;
StackInitiate(&myStack);
for(i=0;i<5;i++)
{
if(StackPush(myStack,i+1)==0)
{
printf("error!\n");
return;
}
}
if(StackTop(myStack,&*)==0)
{
printf("error!\n");
return;
}
else
printf("The element of local top is :%d\n",*);
printf("The sequence of outing elements is:\n");
while(StackNotEmpty(myStack))
{
-
. z.
StackPop(myStack, &*);
printf("%d ", *);
}
printf("\n");
Destroy(myStack);
printf("This program is made by10273206\n");
}
2.*include<>
*include<>
*define Ma*StackSize 100
typedef int DataType;
-
. z.
typedef struct
{
DataType stack[Ma*StackSize];;
int top;
} SeqStack; /*初始化操作:*/
void StackInitiate(SeqStack *S)
/*初始化带头结点链式堆栈*/
{
S->top=0;
}
int StackNotEmpty(SeqStack S)
{
if(<=0)
return 0;
else
return 1;
} /*入栈操作:*/
int StackPush(SeqStack *S, DataType *) {
if(S->top>=Ma*StackSize)
{
-
. z.
printf("堆栈已满无法插入!\n");
return 0;
}
else
{
S->stack[S->top]=*;
S->top++;
return 1;
}
}
int StackPop(SeqStack *S, DataType *d)
{
if(S->top<=0)
{
printf("堆栈已空无数据元素出栈!\n");
return 0;
}
else
{
S->top--;
*d=S->stack[S->top];
return 1;
-
. z.
}
}
int StackTop(SeqStack S, DataType *d)
{
if(<=0)
{
prin