数据结构堆栈实现(C版本)
来源:互联网 发布:亲戚是明星知乎 编辑:程序博客网 时间:2024/05/09 06:14
再熟悉不过的数据结构了,也是普遍的一个基础
贴代码~~~
#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");
}
}
然后来评价这自己写的代码
----------------------------------------
兼容性太差,风格不好,丫丫··~~~~
- 数据结构堆栈实现(C版本)
- 数据结构---堆栈(C#)
- 数据结构:泛型堆栈的实现(C++)
- C语言实现堆栈(栈)的数据结构
- 堆栈数据结构的C语言实现
- 堆栈数据结构的C语言实现
- C 语言堆栈的实现,数组版本,链表版本(大师级的代码值得细细品味。)
- 堆栈数据结构的实现~
- 用链表实现堆栈数据结构
- 数据结构--堆栈的实现
- 《C++实现数据结构》:堆栈
- 数据结构-堆栈-数组实现
- 数据结构与算法——在一个数组中实现两个堆栈(C语言)
- 数据结构与C语言实现(二)——堆栈和队列
- 数据结构C语言实现系列——链式堆栈
- C语言数据结构之堆栈
- 数据结构-堆栈-链表实现
- 简单堆栈实现(C语言)
- 8
- 微笑
- C#.Net的常见面试试题附答案
- typedef --- 给某类型(或类)起个别名
- 网页设计标准尺寸
- 数据结构堆栈实现(C版本)
- 她与父亲的小故事(高考之后)
- 简单的输入输出重定向
- 她与父亲的小故事(我支持你)
- 命令模式(Command Pattern)
- (转)Java获取当前系统时间
- 终于
- 担心
- 看看C++中class里这些奇怪的东西吧