⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 数制转换.cpp

📁 数据结构学习用到的一些程序!!里面有二叉树相关的几个
💻 CPP
字号:
#include<stdio.h>
#include <stdlib.h>
typedef int dataType;

typedef struct stackNode
{
    dataType data;
    struct stackNode *next;
}stackNode;

typedef struct linkStack
{
    stackNode *top;
}linkStack;

void initStack(linkStack *s)
{
    s->top=NULL;
}

void push(linkStack *s,dataType x)
{
     stackNode *p = (stackNode *)malloc(sizeof(stackNode));
     p->data=x;
     p->next=s->top;
     s->top=p;  /*top is point to top struct stackNode of the stack.*/
}

dataType pop(linkStack *s)
{
     dataType tmp;
     stackNode *p=s->top;
     if(s->top==NULL)
	 {
        printf("This seqStack is empty and exit.\n");
        exit(0);
	 }
	 else
	 {
        tmp=s->top->data;
        s->top=s->top->next;
        free(p);
        return tmp;
	 }
}

int stackEmpty(linkStack *s)
{
    return s->top==NULL;
}

void multiBaseOutput(int x,int y)
{
     int i,n,b;
     linkStack s;
     n=x;
     b=y;
     initStack(&s);
     while(n)
	 {
          push(&s,n%b);
          n=n/b;
	 }
     printf("The result of %d used by %d is: ",x,y);
     while(!stackEmpty(&s))
	 {
          i=pop(&s);
          printf("%d",i);
	 }
     printf("\nThis multiBase is over!\n");
}

int main(void)
{
	int m,n;
	printf("请输入要转换的数值及进制\n");
	scanf("%d%d",&m,&n);
	multiBaseOutput(m,n);
} 
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -