ACM学习<3>
1.冒泡排序:
| #include <iostream> #include <time.h> #define SIZE 10 using namespace std; void BubbleSort(int *a,int len) { int temp; for(int i=0;i<len-1;i++) { for(int j=len-1;j>i;j--) { if(a[j-1]>a[j]) { temp=a[j]; a[j]=a[j-1]; a[j-1]=temp; } } cout<<i<<":"; for(int k=0;k<len;k++) { cout<<a[k]<<" "; } cout<<endl; } } int main() { int shuzu[SIZE]; srand(time(NULL));//随机种子 for(int i=0;i<SIZE;i++) { shuzu[i]=rand()/1000+100; } cout<<"old:"; for(int i=0;i<SIZE;i++) { cout<<shuzu[i]<<" "; } cout<<endl; BubbleSort(shuzu,SIZE); cout<<"now:"; for(int i=0;i<SIZE;i++) { cout<<shuzu[i]<<" "; } cout<<endl; } |
| #include <iostream> #include <time.h> using namespace std; #define SIZE 10 void SelectionSort(int *a,int len) { int temp,k; for(int i=0;i<len-1;i++) { k=i; for(int j=i+1;j<len-1;j++) { if(a[j]<a[k]) k=j; } if(k!=i)//交换 { temp=a[k]; a[k]=a[i]; a[i]=temp; } } } int main() { int shuzu[SIZE]; srand(time(NULL)); for(int i=0;i<SIZE;i++) { shuzu[i]=rand()/1000+100; } cout<<"old:"; for(int i=0;i<SIZE;i++) { cout<<shuzu[i]<<" "; } cout<<endl; SelectionSort(shuzu,SIZE); cout<<"now:"; for(int i=0;i<SIZE;i++) { cout<<shuzu[i]<<" "; } cout<<endl; } |
| #include <iostream> #include <time.h> #define SIZE 10 using namespace std; void InsertionSort(int *a,int len) { int temp,j,i,k; for(i=1;i<len;i++) { //temp=a[i],a[j+1]=a[j];a[j+1]=temp;就是个交换。 判断 j-- 为逻辑 temp=a[i], j=i-1; while(j>=0 && temp<a[j]) { a[j+1]=a[j]; j--; } a[j+1]=temp; } } int main() { int arr[SIZE]; srand(time(NULL)); for(int i=0;i<SIZE;i++) { arr[i]=rand()/1000+100; } cout<<"old:"; for(int j=0;j<SIZE;j++) { cout<<arr[j]<<" "; } cout<<endl; InsertionSort(arr,SIZE); cout<<"now:"; for(int k=0;k<SIZE;k++) { cout<<arr[k]<<" "; } cout<<endl; } |
| #include <iostream> #include <time.h> using namespace std; #define SIZE 10 void ShellSrot(int *a,int len) |
ACM学习<3>的更多相关文章
- ACM学习-POJ-1143-Number Game
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1143-Number Game Number Game Time Limit: 1000MS Memory ...
- ACM学习-POJ-1125-Stockbroker Grapevine
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1125-Stockbroker Grapevine Stockbroker Grapevine Time Li ...
- ACM学习-POJ-1003-Hangover
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1003-Hangover Hangover Time Limit: 1000MS Memory Limit ...
- ACM学习-POJ-1004-Financial Management
菜鸟学习ACM,纪录自己成长过程中的点滴. 学习的路上,与君共勉. ACM学习-POJ-1003-Financial Management Financial Management Time Limi ...
- acm学习指引
acm学习心得及书籍推荐 一般要做到50行以内的程序不用调试.100行以内的二分钟内调试成功.acm主要是考算法的,主要时间是花在思考算法上,不是花在写程序与debug上. 下面给个计划练练: 第 ...
- ACM学习
转:ACM大量习题题库 ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库. US ...
- 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始
以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告
- ACM学习历程—HDU 5512 Pagodas(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...
- ACM学习历程—HDU5521 Meeting(图论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...
- ACM学习网站、
转载:http://www.cnblogs.com/zhourongqing/archive/2012/05/24/2516180.html http://61.187.179.132/JudgeOn ...
随机推荐
- js 加减乘除失精
js 计算失精是因为js 先将10十进制代码转化为2进制,再计算导致 具体解决方案: 1. 加 function accAdd(arg1,arg2){ var r1,r2,m; ].length}} ...
- node.js中Buffer缓冲器的使用
一.什么是Buffer Buffer缓冲器是用来存储输入和输出数据的一段内存.js语言没有二进制数据类型,在处理TCP和文件流的时候,就不是很方便了. 所以node.js提供了Buffer类来处理二进 ...
- VS中程序包错误,引用错误该如何解决
1.找到包的文件.packages.config 对应于: 2.删除掉 packages.config 报错的项.然后再重新添加一次.就没有解决的不了的问题. 是不是很爽.....
- linux学习第八天 (Linux就该这么学)
今天学了,mount 挂载,umount撤销挂载,.fdisk 命令 管理硬盘 交换分区swap,硬盘配额 xfs_quota命令 今天工作,手机看了,看的不全,回头看录播了.
- C++ 提取网页内容系列之三
标 题: C++ 提取网页内容系列作 者: itdef链 接: http://www.cnblogs.com/itdef/p/4171659.html 欢迎转帖 请保持文本完整并注明出处 这次继续下载 ...
- xsd
2018-10-08 <xsd:annotation> <xsd:documentation> <![CDATA[ 说明文档 ]]> </xsd:docume ...
- IJ配置项目的TOMCAT
参考文档: IJ里配置TOMCAT http://jingyan.baidu.com/album/0a52e3f43d9f69bf62ed72f9.html?picindex=11 源发行版1.8 需 ...
- 顺序栈的基本操作(C语言)
由于现在只学了C语言所以就写这个C语言版的栈的基本操作 这里说一下 :网上和书上都有这种写法 int InitStack(SqStack &p) &p是取地址 但是这种用法好像C并不 ...
- spring生命周期流程图
Spring作为当前Java最流行.最强大的轻量级框架,受到了程序员的热烈欢迎.准确的了解Spring Bean的生命周期是非常必要的.我们通常使用ApplicationContext作为Spring ...
- Programming | 中/ 英文词频统计(MATLAB实现)
一.英文词频统计 英文词频统计很简单,只需借助split断句,再统计即可. 完整MATLAB代码: function wordcount %思路:中文词频统计涉及到对"词语"的判断 ...