当前位置:网站首页>Bubble sort and selection sort
Bubble sort and selection sort
2022-07-21 08:49:00 【Orange ꦿ ๓】
/**
* Bubble sort
*
*/
public static void main(String[] args) {
int[] arr = { 12, 9, 23, 77, 6, 34 };
Demo4.sort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
}
public static void sort(int[] arr) {
for (int x = 0; x < arr.length-1; x++) {
for (int y = 0; y < arr.length-1-x; y++) {
if (arr[y] > arr[y+1]) {
int temp;
temp = arr[y];
arr[y] = arr[y+1];
arr[y+1] = temp;
}
}
}
}
/**
* Selection sort
*
*/
public static void main(String[] args) {
int[] arr = { 12, 9, 23, 77, 6, 34 };
Demo3.sort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]);
}
}
public static void sort(int[] arr) {
for (int x = 0; x < arr.length - 1; x++) {
for (int y = x + 1; y < arr.length; y++) {
if (arr[x] > arr[y]) {
int temp;
temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
}
}
}
边栏推荐
- This ide plug-in 3.0 makes you the most security aware programmer in the company
- 关于let变量提升的问题
- 实战演练升级!创宇安全托管,助您定向爆破防守难题
- 【微信小程序】radio单选框(83/100)
- 乐扣乐扣澄清欠税事件:不存在欠税,将一如既往合规经营
- 抖音爱奇艺宣布合作,长短视频握手和解?
- How much do you know about the questions often asked by redis in Alibaba's interview?
- HJ18 识别有效的IP地址和掩码并进行分类统计
- Nacos手摸手教学【一】Nacos动态配置
- HJ107 求解立方根
猜你喜欢
败走IPO的年轻人
从八皇后问题看回溯法(暴力枚举)
Design microservice security architecture
Looking back from the eight queens problem (violent enumeration)
ython中if __name__ == ‘__main__‘:的作用和原理
乐扣乐扣澄清欠税事件:不存在欠税,将一如既往合规经营
How to solve the RSA public key not find problem in Navicat
【开发教程10】疯壳·开源蓝牙智能健康手表-OTA镜像制作及下载技术文档
Scala 高阶(七):集合内容汇总(上篇)
自定义类型
随机推荐
MySQL基礎(多錶查詢、事務)
Looking back from the eight queens problem (violent enumeration)
五.uni-app API[路由与跳转、网络请求、数据缓存]
基于CLIP的色情图片识别;油管最新ML课程大合集;交互式编写shell管道;机器人仓库环境增量感知数据集;最新AI论文 | ShowMeAI资讯日报
Netease game Flink SQL platform practice
The fathers of programming languages are too bored to retire and choose to return to the workplace
When business goes out to sea, you should "get your hands dirty" before inspiration appears
设计微服务安全架构
Limit the input type and length in the input box
HJ107 solve cube root
行业现状令人失望,工作之后我又回到UC伯克利读博了
Hj13 sentence reverse order
Hj14 string sorting
Active Data Guard 备用数据库可以运行查询操作或只读应用程序吗?
Scala 高阶(七):集合内容汇总(上篇)
Klocwork部署的安全最佳实践
How many months did you write your first SCI?
分布式事务
网易游戏 Flink SQL 平台化实践
罗敏成不了董宇辉