#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node *next;
}Stack;
#define Maxsize 1000000 //定义一个特大的数
void Push(Stack **top,int data)
{
Stack *p;
p=(Stack *)malloc(sizeof(Stack));
p->data=data;
p->next=*top;
*top=p;
}
void print(Stack *top)
{
while(top!=NULL)
{
printf("%3d",top->data);
top=top->next;
}
printf("\n");
}
int Pop(Stack **top)
{
int x;
if(*top==NULL)
{
printf("此时栈为空");
return -1;
}
else
{
x=(*top)->data;
(*top)=(*top)->next;
return x;
}
}
int min(Stack *top)
{
int min=Maxsize;
while(top!=NULL)
{
if(min>top->data)
{
min=top->data;
}
top=top->next;
}
return min;
}
int main()
{
Stack *s=NULL;
Push(&s,6);
Push(&s,7);
Push(&s,1);
Push(&s,3);
printf("%d\n",Pop(&s));
print(s);
printf("%d\n",min(s));
min(s);
system("pause");
return 0;
}
结果: