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

📄 stackapp.c

📁 数据结构学习点滴
💻 C
字号:
/***十进制转换为三进制***Created by YYF at 20041215***/

#include "myhdr.h"
#define BIT 3
typedef struct node{
	int data;
	struct node *next;
}stacknode;

typedef struct{
	stacknode *top;
}stacklist;

void print(int newnum[],int length);
int
main()
{	
	stacklist stackhead;
	stacknode *node_p;
	stacknode *nodeout_p;
	int i=0;
	int newnum[32];
	int top_value;
	int num;
	memset(newnum,0,sizeof(newnum));
	printf("______1_____\n");
	sleep(1);
	stackhead.top=NULL;
        printf("______2_____\n");
        sleep(1);

	printf("input the value to convert\n");
	scanf("%d",&num);
	printf("______3_____\n");
	sleep(1);
	printf("haha\n");
	while(num!=0)
	{
		node_p=(stacknode *)malloc(sizeof(stacknode));
		if(node_p==NULL)
		{
			printf("allocted memmory error\n");
			return -1;
		}
		node_p->data=num%BIT;
		node_p->next=stackhead.top;
		stackhead.top=node_p;
		num=num/BIT;
	}
	
	while(stackhead.top!=NULL)
	{
		nodeout_p=stackhead.top;
		top_value=nodeout_p->data;
		newnum[i]=top_value;
		stackhead.top=nodeout_p->next;
		free(nodeout_p);
		i++;
	}
	print(newnum,i);
	return 0;
}

void
print(int newnum[],int length)
{
	int i;
	printf("the %d bit num is:\n",BIT);
	for(i=0;i<length;i++)
	{
		printf("%d",newnum[i]);
	}
	printf("\n");
	printf("哈哈,成功了\n");
}

⌨️ 快捷键说明

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