数据结构 数制转换有关问题

数据结构 数制转换问题

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

    }

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

}

int main(){

conversion();

return 0;
}



无法正常运行 发现问题出现在conversion()函数的第二个while循环处 但是没有找到解决方法 求助
------解决思路----------------------
引用:
Quote: 引用:

// 把这一行删掉   free(TempCell);

删了之后 可以运行 但是运行的结果不是我想要的了

我试了几个数,结果好像没错。你的数据?