一个新的算法:珠排序
来源:互联网 发布:淘宝贷款怎么回事 编辑:程序博客网 时间:2024/05/23 11:46
其实在c++里面,有很多鲜为人知的算法。比如说这个,珠排序,就是我翻了很久才找到的。
珠排序到底是什么呢?其实原理跟他的名字一样简单,大概是这样的:
首先,你要找到一个算盘
上面有几根柱子,可以放一些珠子。
输入呢就是有几就那一行有几个珠子。
然后呢类似于一个把这个算盘用力一震,使所有珠子子落下。
最后得到的就是上面小下面大的有序排列。
代码:
#include <stdio.h>#include <ctype.h>int temp1,temp2;int main(){int times = 2;int counter = 0;int i = 0;int j = 0;printf("How many numbers do you want to add in? ");do{printf("Please add in a number:");scanf("%d",×);}while(times <= 0);printf("\n");int numbers[times];for (int k = 0;k < times;k++){printf("Please enter number %d :",k+1);scanf("%d",&numbers[k]);}/************************Find the largest number*************************/int max = numbers[0];for (int h = 0;h < times;h++){if(max < numbers[h]){max = numbers[h];}} /**************************Sort the numbers[1]***************************/int temp3 = 0;int numbers1[max];do{temp3 = 0;for(j = 0;j < times;j++){if(numbers[j] < i + 1){temp3++;}}numbers1[i] = temp3;i++;}while(i < max);/**************************Print the numbers[1]**************************/printf("\nHere is the numbers after the first sorting: ");for (int k = 0;k < i;k++){printf("%d , ",numbers1[k]);}printf("\b\b \n");/**************************Sort the numbers[2]***************************/int numbers2[times];int temp4 = 0;int n = 0;for(int l = 0 ;l < times;l++){for(n = 0;n < i;n++){if(numbers1[n] < l + 1){temp4++;}}numbers2[l] = temp4;temp4 = 0;}/**************************Print the numbers[2]**************************/printf("\nHere is the numbers after the second sorting: ");for (int m = 0;m < times;m++){printf("%d , ",numbers2[m]);}printf("\b\b \n");/****************************Restart or End******************************/printf("\n\n\nRestart or End?\n");char RorE;do{printf("Please enter \"R\"or\"E\". ");scanf(" %c",&RorE);if(RorE == 0){continue;}RorE = toupper(RorE);}while(RorE != 'R' && RorE != 'E');if(RorE=='R'){printf("\n\nRestarting...\n\n\n");main();}}
好吧,到这
阅读全文
0 0
- 一个新的算法:珠排序
- 一种新的排序算法
- 一种新排序算法的探讨
- 一个快速排序的算法
- 一个快速排序的算法
- 一个有意思的排序算法
- 一个新奇的排序算法
- 一个简单的排序算法
- 一个简单的排序算法
- 自己写的【新的】【排序算法】-【二分对调排序】
- 一个C#的冒泡排序算法
- 一个满有技巧性的排序算法
- 一个有趣的排序算法视频
- 一个关于各种排序算法的网站
- 一个很有意思的排序算法
- 一个简单的二叉树排序算法
- 位图排序算法的一个实践
- 【算法】快速排序的一个实现
- 当我们谈论计算机科学
- Java中ArrayList集合嵌套存储和遍历
- Activity
- Python网络编程--TCP
- [jzoj1408][vijos1472] 教主的集合序列
- 一个新的算法:珠排序
- javascript节点的操作 创建、添加、移除、移动、复制
- ListView id的使用
- Git Your branch is ahead of 'origin/master' by X commits解决方法
- html常规写法
- hashmap 深入分析 转载AlphaWang 博主的 但是写的真的很好。
- Python 函数的高级用法
- Elasticsearch的distinct项查询(去重查询)
- 小测验:解密文件——题解