Created
October 9, 2019 12:13
-
-
Save renzhengeek/27c9bef8b97600102a221e86e9e8160f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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