zoukankan      html  css  js  c++  java
  • 十进制转化为八进制--栈实现

    //十进制转化为八进制

    #include <iostream>
    using namespace std;
    #define OK 1
    #define MAXSIZE 100
    #define ERROR 0
    #define OVERFLOW -1
    typedef int Status;
    typedef int SElemtype;

    typedef struct Stacknode{
        SElemtype data;
        struct Stacknode *next;
    }Stacknode,*Linkstack;

    Status Initstack(Linkstack &S){
        S=NULL;
        return OK;
    }

    Status Push(Linkstack &S,SElemtype e){
        Stacknode *p;
        p=new Stacknode;
        p->data=e;
        p->next=S;
        S=p;
        return OK;
    }

    Status Pop(Linkstack &S,SElemtype e){
        Stacknode *p;
        p=new Stacknode;
        if(S==NULL) return ERROR;
        e=S->data;
        p=S;S=S->next;
        delete p;
        return OK;
    }
    Status Stackempty(Linkstack &S){
        Stacknode *p;
        if(S==NULL) return 0;
        return 1;
        
    }

    void conversion(){
        Linkstack S;
        Initstack(S);
        int N;
        SElemtype e;
        cin>>N;
        while(N){
            Push(S,N%8);
            N=N/8;
        }
        while(!Stackempty(S)){
            Pop(S, e);
            cout<<e;
        }
    }

    int main(){
        conversion();
    }

  • 相关阅读:
    PHP学习笔记十二【数组排序】
    PHP学习笔记十一【数组】
    PHP学习笔记十【数组】
    PHP学习笔记九【数组二】
    PHP学习笔记八【数组】
    Codeforces 612E
    Codeforces 616E
    codeforce #339(div2)C Peter and Snow Blower
    poj 1113 Mall
    poj 2187 Beauty Contest
  • 原文地址:https://www.cnblogs.com/zzblee/p/3823466.html
Copyright © 2011-2022 走看看