#include<stdio.h> #include<stdlib.h> typedef struct Node{ int Data; struct Node *Next; } LinkStack ; LinkStack *CreateStack(){ LinkStack *S; S = (LinkStack *)malloc(sizeof(LinkStack)); S->Next = NULL; return S; } int isEmpty(LinkStack *S){ return (S->Next == NULL) ; //若为空 返回1 } LinkStack *Push(LinkStack *S,int item){ LinkStack *TempCell; TempCell = (LinkStack *)malloc(sizeof(LinkStack)); TempCell->Data = item; TempCell->Next = S->Next; S->Next = TempCell; // free(TempCell); /* 一开始在这里出错了 这里的不能把调用free(TempCell) */ } int Pop(LinkStack *S){ LinkStack *FirstCell; int TopElem; if(isEmpty(S)){ printf("堆栈空\n"); return 0 ; }else{ FirstCell = S->Next; S->Next = FirstCell->Next; TopElem = FirstCell->Data; free(FirstCell); return TopElem; } } void conversion(){ LinkStack *s; int n; int item; s = CreateStack(); scanf("%d",&n); while(n){ Push(s,n%8); n = n/8; } while(!isEmpty(s)){ int item; item = Pop(s); printf("%d", item); } printf("\n"); } int main(){ conversion(); return 0; } ———————————————— 版权声明:本文为CSDN博主「DecadeScript」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/u010703975/article/details/45146299
3ewqeqw