标签:就是 换问题 链栈 code 输出 十进制 out += --
输入只有一行,就是十进制整数。
转换后的二进制数。
10
1010
#include <iostream> #include<stdlib.h> #define Max_Size 100 #define STACKINCRMENT 10 using namespace std; typedef int Elemtype; typedef struct SqStack { Elemtype *base; Elemtype *top; int stacksize; }SqStack; void InitStack(SqStack &S) { S.base = (Elemtype*)malloc(sizeof(Elemtype)*Max_Size); S.top = S.base; S.stacksize = Max_Size; } void Push(SqStack &S, Elemtype e) { if (S.top - S.base >= S.stacksize) { S.base = (Elemtype*)realloc(S.base, (S.stacksize + STACKINCRMENT) * sizeof(Elemtype)); S.top = S.base + S.stacksize; S.stacksize += STACKINCRMENT; } *(S.top) = e; S.top++; } void Pop(SqStack &S, Elemtype &e) { if (S.top == S.base) { return; } S.top--; e = *(S.top); } void conversation(SqStack &S) { int count, radix; InitStack(S); cin >> count; while (count) { Push(S, count % 2); count = count / 2; } while (S.top != S.base) { Pop(S, count); cout << count; } } int main() { SqStack S; conversation(S); return 0; }
标签:就是 换问题 链栈 code 输出 十进制 out += --
原文地址:https://www.cnblogs.com/Lazy-Cat/p/9838443.html