课后习题 3.12(改进) 双精度正数进制转换,输入数值和base,输出转换数据
原题是正整数的转换,只能练习到栈。但小数部分恰好是队列实现的,所以加上小数部分,可以一道题练习一整章的核心知识点 Stack.h #pragma once #include<iostream> using namespace std; class Stack { public: int* elements; int maxSize; int top; Stack(int size = 20) { maxSize = size; elements = new int[maxSize]; top = -1; } void overflow() { int* arr; arr = new int[maxSize * 2]; for (int i = 0; i <= top; i++) { arr[i] = elements[i]; } int* p = elements; elements = arr; maxSize *= 2; delete[]p; } void push(int elem) { if (top == maxSize - 1) { overflow(); } elements[++top] = elem; } bool pop(int& e) { bool res = true; if (top == -1) { res = false; } else { e =