C语言——<算法>_冒泡算法的使用及理解
对数组内数值进行有规则排序时,就要用冒泡算法,也是比较简单的一个算法
#include <stdio.h>
#include <stdlib.h>
int main() {
int a[] = { 5,26,7,22,3,36,30,12,80,15,32 };
// printf("%d",_countof(a));
for (int i = 0; i < _countof(a) -1;++i) {
for (int j =0; j < _countof(a) -i-1;++j) {
if (a[j] > a[j+1]) {
int k = a[j];
a[j] = a[j + 1];
a[j + 1] = k;
}
}
}
for (int i = 0; i < _countof(a);++i) {
printf("%d\n",a[i]);
}
return 0;
}
C语言——<算法>_冒泡算法的使用及理解的更多相关文章
- cb34a_c++_STL_算法_查找算法_(7)_lower_bound
cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...
- cb33a_c++_STL_算法_查找算法_(6)binary_search_includes
cb33a_c++_STL_算法_查找算法_(6)binary_search_includes//针对已序区间的查找算法,如set,multiset关联容器-自动排序binary_search(b,e ...
- cb32a_c++_STL_算法_查找算法_(5)adjacent_find
cb32a_c++_STL_算法_查找算法_(5)adjacent_findadjacent_find(b,e),b,begin(),e,end()adjacent_find(b,e,p),p-par ...
- cb31a_c++_STL_算法_查找算法_(4)find_first_of
cb31a_c++_STL_算法_查找算法_(4)find_first_offind_first_of(b,e,sb,se),sb,second begin, se,second end();find ...
- cb30a_c++_STL_算法_查找算法_(3)search_find_end
cb30a_c++_STL_算法_查找算法_(3)search_find_endsearch()pos = search(ideq.begin(), ideq.end(), ilist.begin() ...
- cb29a_c++_STL_算法_查找算法_(2)search_n
cb29a_c++_STL_算法_查找算法_(2)search_n//比如:连续查找连续的n个8search_n(b,e,c,v),迭代器b,begin(),e,end().连续的c个vpos=sea ...
- cb28a_c++_STL_算法_查找算法_(1)find_find_if
cb28a_c++_STL_算法_查找算法_(1)find_find_iffind() //线性查找,比较慢.pos1 = find(ilist.begin(), ilist.end(), 5);fi ...
- 前端面试题解密:经典算法之冒泡算法(ES6版)及优化
前言 随着前端的飞速发展,前端业务开发给前端工程师提出了更高的要求,因而算法题也越来越高频次的出现在前端面试中.有很多的小伙伴找胡哥苦诉,在前端实际开发中(除了涉及游戏开发方面),算法使用有很多吗?大 ...
- STL_算法_查找算法(lower_bound、upper_bound、equal_range)
C++ Primer 学习中. .. 简单记录下我的学习过程 (代码为主) //全部容器适用(O(log(n))) 已序区间查找算法 lower_bound() //找第一个符合的 ...
随机推荐
- 使用vs code开发纸壳CMS并启用Razor智能提示
关于纸壳CMS 纸壳CMS是一个开源免费的,可视化设计,在线编辑的内容管理系统.基于ASP .Net Core开发,插件式设计: 下载代码 GitHub:https://github.com/Seri ...
- JSON 数据转成Table
public static DataTable JsonToDataTable(string strJson) { //转换json格式 strJson = strJson.Replace(" ...
- The service definition selected is invalid
吐槽下 最近在学Java 听闻Java生态很好 社区很多 但实际操作起来确实另一番风景 不多说了 说正事 添加WebService服务Client时有密码认证得服务 Eclipse抛出 The ser ...
- 2.jquery在js中写标准的ajax请求
$(function(){ $.ajax({ url:"http://www.microsoft.com", //请求的url地址 dataType:"json" ...
- MySQL(分组、连表操作、备份数据库)
day58 分组 参考:https://www.cnblogs.com/xp796/p/5262187.html select dept, max(salary) from department gr ...
- 【JS深入学习】——animationend 事件兼容性说明
animationend 1.兼容性 animationend只有两种形式:animationend和webkitAnimationEnd webkitAnimationEnd 中 w 一定要小写,a ...
- centos7 防火墙与端口设置、linux端口范围
防火墙 启动防火墙: systemctl start firewalld 查看防火墙状态: systemctl status firewalld 关闭防火墙: systemctl stop firew ...
- Vim编辑器与shell脚本
目录 Vim文本编辑器 Shell脚本 Shell编程变量 流程控制语句 计划任务 ...
- webstorm 添加css前缀(兼容)自动添加
Webstorm自动添加css前缀( 兼容) 百度了很多在webstorm中添加css前缀(兼容)自动添加,autoprefixer插件是首选,对于基本的css,还有less都支持,所以就选择了aut ...
- Neko and Aki's Prank CodeForces - 1152D (括号序列,dp)
大意: 将所有长度为2*n的合法括号序列建成一颗trie树, 求trie树上选出一个最大不相交的边集, 输出边集大小. 最大边集数一定不超过奇数层结点数. 这个上界可以通过从底层贪心达到, 所以就转化 ...