pop.c
来自「建立学生记录」· C语言 代码 · 共 38 行
C
38 行
#include<stdio.h>
struct node
{ int data;
struct node * next;
};
void pushs(struct node **top,int x)
{struct node *p;
p=(struct node *)malloc(4);
p->data=x;
p->next=(*top);
(*top)=p;
}
int pops(struct node **top)
{struct node *p;
int x;
if (*top==NULL)
{printf("The stack is underflow");
return(NULL);
}
else x=(*top)->data;
p=(*top);
(*top)=(*top)->next;
free(p);
return(x);
}
main()
{ int i,x;
struct node * h;
printf("please input an int number:\n");
scanf("%d",&i);
while(i!=-1)
{ pushs(&h,i);
printf("please input again:\n");
scanf("%d",&i);
}
x=pops(&h);
printf("%d",x);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?