手记

具体实现代码@数据结构探险——栈篇 进制转换

#include <iostream>
#include <string>
#include "MyStack.hpp"
#define BINARY 2
#define OCTAlk 8
#define HEXADECIMAL 16

using namespace std;

int main(void){

    char num[] = "0123456789ABCDEF";

    MyStack<int> *pStack = new MyStack<int>(30);

    int N = 2017;

    int remainder = 0;
    while(N != 0){
        remainder = N % HEXADECIMAL;
        pStack->push(remainder);
        N = N / HEXADECIMAL;
    }

    while(!pStack->stackEmpty()){
        int elem = 0;
        pStack->pop(elem);
        cout << num[elem];
    }
    cout << endl;

    delete pStack;
    pStack = NULL;

}
0人推荐
随时随地看视频
慕课网APP