标题:如何才能解决数据的插入?
只看楼主
萧潇潇
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2015-10-7
结帖率:0
 问题点数:0 回复次数:0 
如何才能解决数据的插入?
#include<stdio.h>
#include<stdlib.h>
#define StackSize 100
typedef int DataType;
typedef struct {

    DataType data[StackSize];
    int top;
}SeqStack;


void InitStack(SeqStack *S)
{

    S->top=-1;
}

void Push(SeqStack *S,DataType x )
{

    if(S->top==StackSize-1){printf("上溢"); exit(-1);}
    S->data[++S->top]=x;
}

DataType Pop(SeqStack *S){
int x;
    if(S->top==-1 ) {printf("下溢");exit(-1);}
    x=S->data[S->top--];
    return x;
}

DataType GetTop(SeqStack *S)
{

    if(S->top==-1){printf("下溢");exit(-1);}
    return S->data[S->top];
}

int Empty(SeqStack *S)
{

    if(S->top==-1) return 1;
    else return 0;
}


main (){
    int t;
    int x,y;
SeqStack S;
printf("请输入您要进行的操作:");
printf("1:入栈 2:出栈 3:取栈顶元素 4:栈遍历 \n ");
scanf("%d ",&t);
     switch(t)
     {
case 1:  printf("请输入入栈的数\n");
    scanf("%d",&x);
    Push(&S,x);
case 2: x=Pop(&S);printf("%d",x);
case 3: y=GetTop(&S); printf("%d",y);
case 4: Empty(&S);

     }

}
搜索更多相关主题的帖子: include return 如何 
2015-10-27 21:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-458614-1-1.html




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

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