把十进制的数转化为八进制的数然后输出。求大神告诉我是哪里出问题了,怎么改,蟹蟹!!! - 爱问答

(爱问答)

把十进制的数转化为八进制的数然后输出。求大神告诉我是哪里出问题了,怎么改,蟹蟹!!!

#include<iostream>

using namespace std;

#define OK 1

#define ERROR 0

#define OVERFLOW -2

typedef struct LNode{

  int data; 

struct LNode *next;

}LNode,*LinkLi;

Status Push(SqStack &S,SElemType e)

{  p=new StackNode; 

   p->next=S;

   S=p;

   return OK;

}

Status Pop(SqStack &S,SElemType &e)

 if(S==NULL)

 return ERROR; 

 e=S->data;

  p=S; 

 S=S->next; 

 delete p; 

return OK;

}

void conversion(int N)

{   Initstack(S); 

while(N) 

 {    Push(S,N%8);

 N=N/8;

  } 

 while(!StackEmpty(S)) 

 {    Pop(S,e);

 printf("%d",e); 

 }

}

int main()

{   printf("请输入十进制的整数:");

  scanf("%3d",&N); 

 Push(S,e);  Pop(S,e); 

 printf("输出八进制的数为:"); 

 conversion(N)

}

 

你的程序结构定义部分“完全”不对,若你是要用栈来做,可以参考以下程序

#include <stdio.h>
#define  StackSize 20  /*假定预分配的栈空间最多为10*/
typedef  int DataType;  /*栈的元素类型设为整型*/
typedef  struct
{
   DataType  data[StackSize];
   int  top;
} SeqStack;
void  InitStack(SeqStack  *S)  /*初始栈*/
{
   S->top = -1;
}
int  StackEmpty(SeqStack  *S)  /*判栈空*/
{
   if(S->top == -1)
       return 1;
   else
       return 0;
}
int  StackFull(SeqStack  *S)  /*判栈满*/
{
   if(S->top == StackSize - 1)
       return 1;
   else
       return 0;
}
void  Push(SeqStack *S,  DataType  x)  /*进栈*/
{
   if(StackFull(S))
       printf("Stack  overflow");  /*上溢退出*/
   else
       S->data[++(S->top)] = x; /*栈顶指针加1后将x进栈*/
}
DataType  Pop(SeqStack *S)  /*出栈*/
{
   if(StackEmpty(S))
       printf("Stack  underflow");  /*下溢退出*/
   else
       return   S->data[(S->top)--]; /*栈顶指针返回后将栈顶指针减1*/
}

void conversion(int N)
{
   
   SeqStack S;
   DataType e;    
   InitStack(&S);
   while(N)
       {
           Push(&S,N%8);
           N=N/8;
       }
   while(!StackEmpty(&S))
       {
           e=Pop(&S);
           printf("%d",e);
       }
}
int main()
{
   int N;
   printf("请输入十进制的整数:");
   scanf("%3d",&N);
    printf("输出八进制的数为:");
   conversion(N);
}


相关标签:大神

下一篇:易语言网页填表,初始化句柄后系统日期时间也被初始化了

上一篇:Dim的变量可以写什么

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?