#include<stdio.h>
#include<iostream>
using namespace std;
#define FALSE -1
typedef struct Node{
int data;
Node *next;
}Node,*Stack;
Stack top=(Node *)malloc(sizeof(Node));
void InitialStack()
{
top->next=NULL;
}
bool IsEmpty()
{
bool flag;
top->next==NULL?flag=true:flag=false;
return flag;
}
int PopNode()
{
Node *temp=(Node *)malloc(sizeof(Node));
temp=top->next;
if(top->next==NULL) return FALSE;
int data=temp->data;
top->next=temp->next;
free(temp);
return data;
}
void Push(int data)
{
Node *temp=(Node *)malloc(sizeof(Node));
temp->data=data;
temp->next=top->next;
top->next=temp;
}
void procOutput()
{
cout<<"转换后的值为:\n";
while(!IsEmpty())
{
cout<<PopNode();
}
cout<<"\n";
}
int main()
{
int N;
while(cin>>N)
{
InitialStack();
while(N!=0)
{
Push(N%2);
N=N/2;
}
procOutput();
}
return 0;
}
链式栈实现进制转化
最新推荐文章于 2022-12-06 14:21:33 发布
1094

被折叠的 条评论
为什么被折叠?



