首页 > 其他分享 >Convert a number from decimal to binary【1月19日学习笔记】

Convert a number from decimal to binary【1月19日学习笔记】

时间:2024-01-19 13:11:07浏览次数:16  
标签:node binary Convert prev run 19 next int NULL

点击查看代码
//Convert a number from decimal to binary
#include<iostream>
using namespace std;
struct node {
	int data;
	node* next;
};
node* A;

void insert(int x) {
	node* temp = new node;
	temp->data = x;
	temp->next = NULL;
	if (A == NULL) {
		A = temp;
		return;
	}
	node* run = A;
	while (run->next != NULL) {
		run = run->next;
	}
	run->next = temp;

}

void reverse(node* prev) {
	if (prev->next == NULL) {
		A = prev;
		return;
	}
	reverse(prev->next);
	node* back = prev->next;
	back->next = prev;
	prev->next = NULL;
}

void print() {
	node* run = A;
	while (run != NULL) {
		cout << run->data << " ";
		run = run->next;
	} cout << endl;
}

void FindDigiteInDecimal(int n) {
	A = NULL;
	int rem;//余数
	while (n > 0) {
		rem = n % 10;//每个位数上的数字,倒序
		insert(rem);
		n = n / 10;//商
	}
	reverse(A);//反转
	print();
}

void FindDigiteInBinary(int n) {
	A = NULL;
	int rem;
	while (n > 0) {
		rem = n % 2;
		insert(rem);
		n = n / 2;
	}
	reverse(A);
	print();
}

int main() {
	int n;
	cin >> n;
	FindDigiteInDecimal(n);
	FindDigiteInBinary(n);
}

标签:node,binary,Convert,prev,run,19,next,int,NULL
From: https://www.cnblogs.com/whvivy/p/17974399

相关文章

  • 1.19学习进度
    1.standalone是一个完整的分布式集群环境;standalone集群在进程上主要有三类进程:主节点master及昵称、从节点的worker进程、历史服务器哦historyserver(可选)2.4040:是一个运行的application在运行的过程中临时绑定的端口,用以查看当前任务的状态。4040被占用会顺延到4041、4042等。404......
  • Quick sort【1月19日学习笔记】
    点击查看代码//Quicksort#include<iostream>usingnamespacestd;intpartition(intA[],intstart,intend){ intpivot=A[end];//默认选取末尾为主元 intpIndex=start;//分区索引初始化 for(inti=start;i<end;i++){//从索引start开始扫描 if(A[i]<......
  • 2024-1-19事件绑定,input与hover事件
    目录事件绑定,input与hover事件事件绑定hover事件input事件事件绑定.on()方法注意:off()方法事件绑定,input与hover事件在jQ内很多中事件常用的事件有下面的click(function(){...})//绑定一个点击事件hover(function(){...})//悬停触发事件blur(function(){...})//失焦事件处理......
  • 2024.1.19日报
    本质:启动一个JVMProcess进程(一个进程里有多个线程),执行任务TaskLocal模式可以限制模拟Spark集群环境的线程数量,即Local[N]或Local[*]其中N代表可以使用N个线程,每个线程拥有一个cpucore,如果不指定N,则默认是1个线程(该线程有一个core)。通常Cpu有几个core,就指定几个线程,最大化利用......
  • 2024-1-19事件绑定,input与hover事件
    目录事件绑定,input与hover事件事件绑定hover事件input事件事件绑定,input与hover事件在jQ内很多中事件常用的事件有下面的click(function(){...})//绑定一个点击事件hover(function(){...})//悬停触发事件blur(function(){...})//失焦事件处理focus(function(){...})//焦点......
  • SpiderFlow爬虫平台漏洞利用分析(CVE-2024-0195)
    1.漏洞介绍SpiderFlow爬虫平台项目中spider-flow-web\src\main\java\org\spiderflow\controller\FunctionController.java文件的FunctionService.saveFunction函数调用了saveFunction函数,该调用了自定义函数validScript,该函数中用户能够控制 functionName、parameters 或 sc......
  • 1978:扩号匹配问题C
    #include<stdio.h>intmain(){chars[101];while(scanf("%s",s)!=EOF){printf("%s\n",s);chartem[101];inta[101]={0};inttop=0;inti=0;for(;s[i]!='\0';i++){......
  • 2024年1月【考试战报】|ORACLE OCP 19C考试通过
    2023年12月【考试战报】ORACLEOCP19C考试通过2023年11月【考试战报】|ORACLEOCP19C考试通过2024年10月【考试战报】|ORACLEOCP19C考试通过203年8月【考试战报】|ORACLEOCP19C考试通过数据库工程师-OracleOCP19C认证介绍ORACLE 2024年新年考试战报恭喜顺利拿证新......
  • 19条MySQL优化
    一善用EXPLAIN 做MySQL优化,我们要善用 EXPLAIN 查看SQL执行计划。下面来个简单的示例,标注(1,2,3,4,5)我们要重点关注的数据•type列: 连接类型。一个好的sql语句至少要达到range级别。杜绝出现all级别•key列: 使用到的索引名。如果没有选择索引,值是NULL。可以采取强制......
  • [c][cpp]: decimal to binary
    [c][cpp]: decimaltobinary    一、源码1#include<stdio.h>2#include<stdlib.h>3#include<string.h>456//decialtobinary;10->27voiddec2bin(longintnum)8{9intfinal[1000];1011longintsave......