top=p;
return top;
}
/////////////
LinkStack Pop(LinkStack top, int * e)
/*将链栈top中的栈顶元素从栈中删除,并用e返回其值*/
{
LinkStack q;
if (!top) /*如果栈空 , 则函数返回ERROR*/
printf("Stack is ERROR\n");
*e=top-data; /*将被删的栈顶元素的值保存在e中*/
q=top; /*用q记下待删的栈顶元素*/
top=q-next;
/*修改链使待删结点从链中"卸下" ,此时被删结点的后继成为新的栈顶元素结点*/
free(q); /*释放被删结点的存储空间*/
return top;
}
/////////
LinkStack Stack_display(LinkStack top)
{
int e;
while(top)
{
e=top-data;
printf("%4d",e);
top=top-next;
}
return top;
}
/////////////////////
void main()
{
LinkStack top = 0;
int i=0,n,e;
printf("please input the length:");/*输入几个数*/
scanf("%d",n);
printf("please input the Value:\n");/*输入*/
while(in)
{
scanf("%d",e);
top=Push(top,e);
i++;
}
printf("the stack is:\n");
Stack_display(top);
printf("please input the insert node:");
scanf("%d",e);
top=Push(top,e);
printf("the stack after push is:\n");
【Java链栈代码 java链表实现栈】 Stack_display(top);
top=Pop(top,e);
printf("the pop value is:%d\n",e);
printf("the stack after pop is:\n");
Stack_display(top);
}
调好了麻烦采纳一下
java用链表实现栈public Object setEle(Object element)
{
Object oldElement = this.element;
this.element = element;
return oldElement;
}
是啥意思,给值还return??把这函数删了
public Linked()
{
nextNode = null;
element = null;
}
改成
public Linked(Object element)
{
this.element = element;
nextNode = null;
}
用java语言编写算法 输出链栈中的所有元素#includestdio.h
#includestdlib.h
struct node{
int data;
struct node* pre;
};
void print(struct node *p) //打印链栈
{while(p)
{printf("%d ",p-data);
p=p-pre;
}
}
int main()
{int i;
struct node *p,*q;
for(i=1;i11;i++) //1~10依次入栈
{p=(struct node*)malloc(sizeof(struct node));
if(i==1)p-pre=NULL;
else p-pre=q;
p-data=https://www.04ip.com/post/i;
q=p;
}
print(p);
return 0;
}
链栈的入栈出栈代码这是我写的栈,你看看
#includestdio.h
#includeiostream
typedef struct node{
int date;
node * next;
}SeqStack ;
SeqStack * init_SeqStack(SeqStack * top){
top=NULL;
return top;
}
int is_Empty(SeqStack * top){
if(top==NULL)return 1;
else return 0;
}
SeqStack * push_Stack(SeqStack * top){
SeqStack * New;
New=(SeqStack *)malloc(sizeof(SeqStack));
printf("请输入要入栈的元素\n");
scanf("%d",New-date);
New-next=top;
top=New;
return top;
}
SeqStack * pop_Stack(SeqStack * top,int m){
SeqStack * p=NULL;
if(!is_Empty(top)){
m=top-date;
p=top;
top=top-next;
free(p);
return top;
}
}
SeqStack * top_Stack(SeqStack * top,int m){
if(!is_Empty(top)){
m= top-date;
return top;
}
}
int main(){
int m=0;
SeqStack * s=NULL;
init_SeqStack(s);
s=push_Stack(s);
s=push_Stack(s);
s=push_Stack(s);
s=push_Stack(s);
s=top_Stack(s,m);
printf("%d\n",m);
s=top_Stack(s,m);
printf("%d\n",m);
s=pop_Stack(s,m);
推荐阅读
- css3页面左右切换,html左右滑动切换页面
- 3代cpu什么规格,13代CPU用什么系统
- 手机虚拟游戏空间,手机虚拟空间打不开游戏
- oracle导出用户下的表,oracle导出数据表
- ios怎么玩ins,ios怎么玩b服游戏
- 格斗游戏八卦掌实战教学,八卦掌拳术风格
- 3d飞机单机游戏,大型3d飞机游戏大全
- python函数代码例子 函数 python
- 苹果4怎么转word,苹果4怎么转移数据?