| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 461 人关注过本帖
标题:[求助]: there is something wrong with my Stack....what should I do ?
只看楼主 加入收藏
毛毛小虫
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-11-1
收藏
 问题点数:0 回复次数:0 
[求助]: there is something wrong with my Stack....what should I do ?


#include <stdio.h>
#include <malloc.h>
#define null 0

typedef struct stacknode
{
int data;
struct stacknode *next;
}stacklink;
typedef struct
{
int stacksize;
stacklink *top;
}linkstack;


void initlink(linkstack *s)
{
s->top=(stacklink *)malloc(sizeof(stacklink));
s->top->data=0;
s->top->next=null;
}

void pushlink(linkstack *s,int x)
{
stacklink *p;
p=(stacklink *)malloc(sizeof(stacklink));
p->data=x;
p->next=s->top->next;
s->top->next=p;

}

int poplink(linkstack *s)
{
int x;
stacklink *p;
if(s->top->next==null)
printf("the stack is empty\n");
else
{
x=s->top->next->data;
p=s->top->next;
s->top=s->top->next;
free(p);

}
return x;
}


void display(linkstack *s)
{
stacklink *p;
p=s->top->next;
printf("打印出该栈为:\n");
if (s->top=null) printf("the stacklink is empty!\n");
else {while(p)
{printf("-----%d",p->data);
p=p->next;}
}
}


void main()
{
int n,k,i,select,h,x1;
linkstack *p = (linkstack *)malloc(sizeof(linkstack));
initlink(p);

printf("请输入你所要创建的站长度:\n");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
printf("请输入值:\n");
scanf("%d",&k);
pushlink(p,k);
}
printf("select 1:打印出该栈为\n");
printf("select 2:进栈操作\n");
printf("select 3:出栈操作\n");

printf("请选择:\n");
scanf("%d",&select);

switch(select)
{
case 1:{display(p);break;}
case 2:{printf("请输入值 :\n");
scanf("%d",&h);
pushlink(p,h);
display(p);
break;}
case 3:{x1=poplink(p);printf(" %d\n",x1);
display(p);
break;}

}
}

/*Thank you for your help!!*/

搜索更多相关主题的帖子: Stack wrong something 
2007-11-01 19:13
快速回复:[求助]: there is something wrong with my Stack....what should I d ...
数据加载中...
 
   



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

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