数据结构堆栈实现(C版本)

本文介绍了一个简单的栈数据结构实现,并提供了初始化、判断空栈、入栈、出栈及获取栈顶元素等基本操作的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

再熟悉不过的数据结构了,也是普遍的一个基础

贴代码~~~

#define MAXSIZE 10
typedef struct
{
    int data[MAXSIZE];
    int top;
}SqStack;

SqStack sqt;
int total=4;
void InitStack(SqStack &st)
{
    st.top=-1;
}

int StackEmpty(SqStack st)
{
    return (st.top==-1);
}

int push(SqStack &st,int x)
{
    if(st.top==MAXSIZE-1)
        return 0;
    st.top++;
    st.data[st.top]=x;
    return 1;
}

int pop(SqStack &st,int& x)
{
    if(st.top==-1)
        return 0;
    x=st.data[st.top];
    st.top--;
    return 1;
}

int getTop(SqStack st)
{
    return st.data[st.top];
}

void process(int pos,int path[],int curp)
{
    int m,i,x;
    if(pos<=total)
    {
        push(sqt,pos);
        process(pos+1,path,curp);
        pop(sqt,x);
    }
    if(!StackEmpty(sqt))
    {
        pop(sqt,m);
        path[curp]=m;
        curp++;
        process(pos,path,curp);
        push(sqt,m);
    }
    if(pos>total && StackEmpty(sqt))
    {
        printf("  ");
        for(i=0;i<curp;i++)
            printf("%d  ",path[i]);
        printf("/n");
    }
}

 

然后来评价这自己写的代码

----------------------------------------

兼容性太差,风格不好,丫丫··~~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值