mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
Add cpp codes for the chapter
computational complexity, sorting, searching.
This commit is contained in:
@ -47,10 +47,10 @@ public class bubble_sort {
|
||||
public static void main(String[] args) {
|
||||
int[] nums = { 4, 1, 3, 1, 5, 2 };
|
||||
bubbleSort(nums);
|
||||
System.out.println("排序后数组 nums = " + Arrays.toString(nums));
|
||||
System.out.println("冒泡排序完成后 nums = " + Arrays.toString(nums));
|
||||
|
||||
int[] nums1 = { 4, 1, 3, 1, 5, 2 };
|
||||
bubbleSortWithFlag(nums1);
|
||||
System.out.println("排序后数组 nums1 = " + Arrays.toString(nums));
|
||||
System.out.println("冒泡排序完成后 nums1 = " + Arrays.toString(nums));
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,6 @@ public class insertion_sort {
|
||||
public static void main(String[] args) {
|
||||
int[] nums = { 4, 1, 3, 1, 5, 2 };
|
||||
insertionSort(nums);
|
||||
System.out.println("排序后数组 nums = " + Arrays.toString(nums));
|
||||
System.out.println("插入排序完成后 nums = " + Arrays.toString(nums));
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ public class merge_sort {
|
||||
|
||||
public static void main(String[] args) {
|
||||
/* 归并排序 */
|
||||
int[] nums = { 2, 4, 1, 0, 3, 5 };
|
||||
int[] nums = { 7, 3, 2, 6, 0, 1, 5, 4 };
|
||||
mergeSort(nums, 0, nums.length - 1);
|
||||
System.out.println("归并排序完成后 nums = " + Arrays.toString(nums));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user