Skip to content

Instantly share code, notes, and snippets.

@renzhengeek
Created October 9, 2019 12:13
Show Gist options
  • Save renzhengeek/27c9bef8b97600102a221e86e9e8160f to your computer and use it in GitHub Desktop.
Save renzhengeek/27c9bef8b97600102a221e86e9e8160f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define FALSE 0
#define TRUE 1
#define NULL 0
#define maxsize 10
typedef int datatype;
typedef struct SqStack{
datatype data[maxsize];
int top;
}SqStack;
SqStack *Push(SqStack *S, datatype e) {
S->data[++S->top] = e;
return S;
}
int Empty(SqStack *S) {
if (S->top < 0)
return TRUE;
else
return FALSE;
}
datatype Pop(SqStack *S, datatype *e) {
*e = S->data[S->top--];
return *e;
}
void init(SqStack *S) {
S->top = -1;
}
void conversion(unsigned int num) {
SqStack S;
init(&S);
while (num != 0) {
Push(&S, num%8);
num = num/8;
}
while (!Empty(&S)) {
int e;
Pop(&S, &e);
printf("%d", e);
}
}
int main()
{
unsigned int num;
printf("\n请输入一个十进制数!\n");
scanf("%d", &num);
conversion(num);
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment