• 栈——十进制转八进制


    顺序栈的基本操作

    //"SqStack.h"
    #include<iostream>
    using namespace std;

    #define SElemType int
    #define MAXSIZE 100

    typedef struct{
        SElemType *base;
        SElemType *top;
        int stacksize;
    }SqStack;

    string InitStack(SqStack &S){
        S.base = new SElemType[MAXSIZE];
        S.top = S.base;
        S.stacksize=MAXSIZE;
        return "OK";
    }

    string Push(SqStack &S,SElemType e){
        if(S.top-S.base == S.stacksize) return "ERROR";
        *S.top=e;
        S.top++;
        return "OK";
    }

    string pop(SqStack &S,SElemType &e){
        if(S.base == S.top) return "ERROE";
        S.top--;
        e = *S.top;
        return "OK";
    }

    SElemType GetTop(SqStack S){
        if(S.top != S.base){
            return *(S.top-1);
        }

    int StackEmpty(SqStack S){
        if(S.top == S.base) return 1;
        return 0;
    }
    #include<iostream>
    #include"SqStack.h"
    using namespace std;
    
    /*
        十进制转八进制
    */
    
    int main(){
    
        SqStack S ;
        InitStack(S);
    
        cout <<"Input the number to conver";
        int N;
        cin >> N;
    
      
    
        while(N){
            Push(S,N%8);                //将除8余数存进栈中
            N = N/8;
        }
        while (!StackEmpty(S))
        {
            SElemType e;
            pop(S,e);                   //按栈的顺序逐个输出  
            cout<<e;
        }
        system("pause");
        return 0;
    }
  • 相关阅读:
    Java Web总结十Jsp
    当前结果
    QFontMetrics的一个问题
    设想的用户交互流程
    多视图工作
    改进函数、变量的表示
    接口测试Session/Cookie笔记(二)
    接口测试笔记(一)
    创业公司心力交瘁
    禅道BUG管理工具使用链接存储
  • 原文地址:https://www.cnblogs.com/LuMinghao/p/14002580.html
Copyright © 2020-2023  润新知