zoukankan      html  css  js  c++  java
  • 栈——十进制转八进制

    顺序栈的基本操作

    //"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;
    }
  • 相关阅读:
    在宝塔中升级mysql版本
    测试winform程序到树莓派运行
    winserver2012远程桌面进入只有CMD窗口,无桌面解决方法
    一七年春末
    Linux 上通过rpm安装mysql
    Linux 上关于iptables
    Linux环境下安装JDK
    Linux上安装tomcat
    Linux 下安装redis
    Map集合按照value和key进行排序
  • 原文地址:https://www.cnblogs.com/LuMinghao/p/14002580.html
Copyright © 2011-2022 走看看