作者在 2010-11-12 01:07:30 发布以下内容
#include<stdio.h>
#include "malloc.h"
#define MAX 100
typedef struct {
int data[MAX];
int top;
}SeqStack;
#include "malloc.h"
#define MAX 100
typedef struct {
int data[MAX];
int top;
}SeqStack;
SeqStack* Init_SeqStack(){
SeqStack *s;
if( (s=(SeqStack*)malloc(sizeof(SeqStack)))==NULL)
return NULL;
s->top=-1;
return s;
}
int Push_SeqStack(SeqStack * s,int x){
if(s->top==MAX-1)
return 0;
else{
s->data [++s->top]=x;
return 1;
}
}
int Pop_SeqStack(SeqStack *s,int *x){
if(s->top==-1)
return 0;
*x= s->data[s->top];
s->top--;
return 1;
}
int main(){
SeqStack newStack;
int num;
newStack.top=-1;
printf("请输入您要插入的数字: ");
for(int i=0;i<5;i++){
scanf("%d",&num);
Push_SeqStack(&newStack,num);
}
int x;
printf("\n");
while(newStack.top!=-1){
Pop_SeqStack(&newStack,&x);
printf("%d ",x);
}
printf("\n");
return 0;
}
SeqStack *s;
if( (s=(SeqStack*)malloc(sizeof(SeqStack)))==NULL)
return NULL;
s->top=-1;
return s;
}
int Push_SeqStack(SeqStack * s,int x){
if(s->top==MAX-1)
return 0;
else{
s->data [++s->top]=x;
return 1;
}
}
int Pop_SeqStack(SeqStack *s,int *x){
if(s->top==-1)
return 0;
*x= s->data[s->top];
s->top--;
return 1;
}
int main(){
SeqStack newStack;
int num;
newStack.top=-1;
printf("请输入您要插入的数字: ");
for(int i=0;i<5;i++){
scanf("%d",&num);
Push_SeqStack(&newStack,num);
}
int x;
printf("\n");
while(newStack.top!=-1){
Pop_SeqStack(&newStack,&x);
printf("%d ",x);
}
printf("\n");
return 0;
}