我程序编完了,不会改。谁帮我改好了,我就把所有的分都给谁!
我的题目是:用链栈实现将十进制数转化为八进制数,我编完了,可我不会改啊,都改了无数个日夜了,还是改不好。有哪位好心的人能帮帮我啊?将不胜感激啊!。程序就在下面,帮帮忙,救救我吧,交不上程序我就挂了啊。呜呜呜呜呜,要求输入11输出13#include<stdio.h>
#include<math.h>
typedef struct node
{
int data;
struct node *next;
}LinkStack;
void init_stack(LinkStack *top)
{
top->data='-1';
top->next=NULL;
}
int decide_empty(LinkStack *top)
{
if(top->data=='-1')
return (1);
else
return (0);
}
LinkStack* Enter_stack(LinkStack *top,int x)
{
top=(LinkStack*)malloc(sizeof(LinkStack));
top->data=x;
top->next=NULL;
top=top->next;
printf("\nOK!\n");
return(top);
}
int del_stack(LinkStack *top )
{
LinkStack *p;
int a;
if(top==NULL)
{
printf("\n栈为空!");
return 0;
}
else
{
a=top->data;
p=top;
top=top->next;
free(p);
return a;
}
}
main()
{
LinkStack LS,*L=&LS;
int n,e;
init_stack(L);
printf("please input a decimal number:");
scanf("%d",&n);
if(n<=0)
printf("error due to the wrong input!\n");
while(n)
{
Enter_stack( L ,n%8);
n=n/8;
}
printf("the changed number is:\n");
while(decide_empty(L))
{
e=del_stack(L);
printf("\t%d",e);
}
getch();
}