我的C

作者在 2010-11-12 01:07:30 发布以下内容
#include<stdio.h>
#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;
}
程序 | 阅读 472 次
文章评论,共0条
游客请输入验证码
文章分类
文章归档
最新评论