当前位置:网站首页>Tri rapide + Tri par bulle + Tri par insertion + Tri par sélection
Tri rapide + Tri par bulle + Tri par insertion + Tri par sélection
2022-06-23 07:43:00 【L'âne de l'équipe de production】
Code
Sélectionner le tri
public class Solution {
/** * @param a: an integer array * @return: nothing */
public void sortIntegers(int[] a) {
// write your code here
int n = a.length;
for (int i = 0; i < n - 1; i++){
int min = i;
for (int j = i + 1; j < n; j++){
if (a[j] < a[min]){
min = j;
}
}
swap(a, i, min);
}
}
public void swap(int[] a, int index1, int index2){
int temp = a[index1];
a[index1] = a[index2];
a[index2] = temp;
}
}
Tri des bulles
// bubble sort
public class Solution{
public void sortIntegers(int[] a){
int n = a.length;
for (int i = 0; i < n- 1;i++){
for (int j = 0; j < n - 1 - i; j++){
if (a[j] > a[j+1]) swap(a, j, j+1);
}
}
}
public void swap(int[] a, int index1, int index2){
int temp = a[index1];
a[index1] = a[index2];
a[index2] = temp;
}
}
Tri rapide
public class Solution{
public void sortIntegers(int[] a) {
int low = 0;
int hight = a.length - 1;
quickSort(a, low, hight);
}
public void quickSort(int[] a, int low, int hight){
if (low > hight) return;
int left, right, pivot;
left = low;
right = hight;
pivot = a[left];
while(left < right){
while(left < right && a[right] >= pivot) right--;
if (left < right) a[left] = a[right];
while(left < right && a[left] <= pivot) left++;
if (left < right) a[right] = a[left];
if (left == right) a[left] = pivot;
}
quickSort(a, low, right - 1);
quickSort(a, right + 1, hight);
}
}
Tri rapide Vidéo de Regarde la vidéo. ,Ne regardez pas le Code,Regardez le Code. Pas facile à comprendre
Un soldat à cheval ou quelque chose comme ça , Ce n'est pas facile à comprendre ,Regarde ça.
Insérer un tri
public class Solution{
public void sortIntegers(int[] a){
int n = a.length;
for (int i = 1; i < n; i++){
int temp = a[i];
int j = i;
while (j > 0 && a[j - 1] > temp){
a[j] = a[j - 1];
j--;
}
a[j] = temp;
}
}
}
https://www.bilibili.com/video/BV1at411T75o?spm_id_from=333.337.search-card.all.click&vd_source=8d8fef6cad2875d6b6b4c08c3a9ac66d
边栏推荐
- Both are hard disk partitions. What is the difference between C disk and D disk?
- [interface automation] software testing the core skills of salary increase to increase salary by 200%
- Deploy kubersphere in kubernetes
- . H5 file forgets the database name and uses h5py to print
- [deep learning] [original] how to detect targets and draw map and other parameter maps without yolov5 weights or models
- 3dmax插件开发环境配置及FileExport和Utilities模板测试
- vs在连接SQL时出现的问题myconn.OPen();无法运行
- 在线JSON转CSharp(C#)Class工具
- [AI practice] xgb Xgbregression multioutputregressor parameter 1
- [Planet selection] how to efficiently build fine-grained two-way links between roam and thebrain?
猜你喜欢

Qt工程报错:-1: error: Cannot run compiler ‘clang++‘. Output:mingw32-make.exe

基于51单片机的温度检测监测报警系统设计
![[pyqt5 series] modify the counter to realize control](/img/de/c997a19ad72619b0fd2fcd0124ee1a.png)
[pyqt5 series] modify the counter to realize control

Make a record of glib2.14 upgrading glib2.18 and the principle of the steps

Operation on a bit of binary

The Sandbox 与《足球小将》达成合作,将流行的足球漫画及动画带入元宇宙

1278_FreeRTOS_借助prvAddCurrentTaskToDelayedList接口理解delayed task

Friends of the week

The road to hcip MPLS

【星球精选】如何高效构建 Roam 与 theBrain 间细粒度双向链接?
随机推荐
[AI practice] xgbgressor model accelerates training and uses GPU to train xgbgressor in seconds
csrf攻击在laravel中如何解决
MySQL summary
SimpleDateFormat 线程安全问题
Intelligence Education - how to merge codes when code conflicts occur in multi person collaborative development?
What is the experience of being a data product manager in the financial industry
[Laoke] how should ordinary people learn technology?
快速排序 + 冒泡排序 + 插入排序 + 选择排序
CIRIUM(睿思誉)逐渐成为航空公司二氧化碳排放报告的标准
MySQL (VIII) - explain
Nacos adapts Oracle11g create table DDL statement
MIT CMS.300 Session 12 – IDENTITY CONSTRUCTION 虚拟世界中身份认同的建立 part 2
作为思摩尔应对气候变化紧急事件的一项举措,FEELM加入碳披露项目
JS to determine the added and decreased elements of two arrays
To conquer salt fields and vegetable fields with AI, scientific and technological innovation should also step on the "field"
The original cloud landed in deep water, and the cloud product family of Boyun container released four values
Ffplay realizes user-defined input stream playback
MySQL transaction isolation level
Decoding and practice of cmaf Technology
Simpledateformat thread safety issues