求c语言实现数据结构中堆栈功能的源程序

yuji 2002-07-09 11:05:59
在线等待
...全文
265 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
DaNiao 2002-07-10
  • 打赏
  • 举报
回复
I think the chinese word "堆栈" means "heap and stack"
Is there any one can write a data structure which is both a heap
and a stack?
yuji 2002-07-10
  • 打赏
  • 举报
回复
smart_boy1(失败)的代码考虑了溢出和空栈的情况,比较实用,我决定用他的,同时感谢 abcpanpeng(badboy)
wjjabc 2002-07-09
  • 打赏
  • 举报
回复
我也看看
nwpujiashu 2002-07-09
  • 打赏
  • 举报
回复
关注!·
chongling 2002-07-09
  • 打赏
  • 举报
回复
堆栈一般都是用数组来实现的
================================================================

CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!

★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。

★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。

Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]

heimeng 2002-07-09
  • 打赏
  • 举报
回复
数组还是链表
q_v_i_t 2002-07-09
  • 打赏
  • 举报
回复
请关注:
http://www.csdn.net/expert/topic/861/861257.xml?temp=.7040522
q_v_i_t 2002-07-09
  • 打赏
  • 举报
回复
我把我的贴给你看看
#define STACK_INIT_SIZE 5
#define STATCK_INCREMENT 5
#include <stdio.h>
struct stack
{ int *base;
int *top;
int stacksize;
};

void initstack(struct stack *s_init);
int push(struct stack *s_push,int e_push);
int pop(struct stack *s_pop,int e_pop);
main()
{ struct stack *st; //struct stack st;
int i,e;
initstack(st); //initstack(&st);
printf("\ninput:\n");
for(i=0;i<st->stacksize;i++) //for(i=0;i<st.stacksize;i++)
{ scanf("%d",&e);
push(st,e); //push(&st,e);
}
printf("\noutput\n");
for(i=0;i<st->stacksize;i++) //for(i=0;i<st.stacksize;i++)
printf("%d",pop(st,e)); //printf("%d",pop(&st,e));
}

void initstack(struct stack *s_init)
{ s_init->base=(int *)malloc(STACK_INIT_SIZE * sizeof(int));
s_init->top=s_init->base;
s_init->stacksize=STACK_INIT_SIZE;
}

int push(struct stack *s_push,int e_push)
{ if(s_push->top==s_push->base+s_push->stacksize)
{ printf("overflow!");
return(0);
}
*s_push->top=e_push;
s_push->top++;
return(1);
}

int pop(struct stack *s_pop,int e_pop)
{ if(s_pop->top==s_pop->base)
{ printf("stack empty");
return(0);
}
s_pop->top--;
e_pop=*s_pop->top;
return(e_pop);
}
abcpanpeng 2002-07-09
  • 打赏
  • 举报
回复
#include "stdio.h"
#include "malloc.h"

typedef struct node
{
int value;
struct node *next;
}NODE;
NODE *top,*s,*head;

void empty()
{
// x=(NODE *)malloc(sizeof(NODE));
//x->value=0;
top=NULL;
//x->next=top;
}

NODE *push(int w,int i)
{

s=(NODE *)malloc(sizeof (NODE));
s->value=w;
s->next=top;
top=s;
if(i==1)
{
head=top;
}
return top;

}
void pop(NODE **top)
{
int y;
s=*top;
y=(*top)->value;
*top=(*top)->next;
free(s);
printf("%d\t",y);

}

main()
{
int b,n,i;
empty();
printf("How many times do you want to push and to pop?\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the %d time's value:",i);
scanf("%d",&b);
push(b,i);
}
printf("\nThe value of head=%d\n",head->value);
for(i=1;i<=n;i++)
{
pop(&top);
}

getch();
}

yuji 2002-07-09
  • 打赏
  • 举报
回复
不管什么,能用就行

69,387

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧