数据结构-栈-进制转换

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef struct sqstack{
   int *base;
   int *top;
   int sizestack;
}sqstack;
void creat_stack(sqstack &a){
  a.base=(int*)malloc(100*sizeof(int));
  a.top=a.base;
  a.sizestack=100;
}
void push(sqstack &a,int e){
   *a.top++=e;
}
void pop(sqstack &a){
   if (a.base==a.top){
    return ;
   }else {
     a.top--;
   }
}
int get_top(sqstack a){
   if (a.top==a.base){
      return -1;
   }else {
      return *(a.top-1);
   }
}
bool isempty(sqstack a){
    if (a.base==a.top){
        return 1;
    }else {
        return 0;
    }
}
int main(){
  sqstack a;
  creat_stack(a);
  int num;
  scanf("%d",&num);
  while(num!=0){
    push(a,num%2);
    num/=2;
  }
  while(!isempty(a)){
     printf("%d ",get_top(a));
     pop(a);
  }

  return 0;
}
有不懂欢迎咨询 QQ:1326487164(添加时记得备注)
原文地址:https://www.cnblogs.com/bluefly-hrbust/p/10187972.html