zzblee

//十进制转化为八进制

#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();
}

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-01-02
  • 2022-02-02
  • 2022-03-05
猜你喜欢
  • 2021-07-25
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2022-12-23
  • 2021-11-05
相关资源
相似解决方案