# 开源地址
[https://gitee.com/lblbc/simple-works/tree/master/sort/](https://gitee.com/lblbc/simple-works/tree/master/sort/)
> 覆盖语言:C、C++、C#、Java、Kotlin、Dart、Go、JavaScript(JS)、TypeScript(TS)、ArkTS、swift、PHP。
> 覆盖平台:安卓(Java、Kotlin)、iOS(SwiftUI)、Flutter(Dart)、Window桌面(C#)、前端(微信小程序、uni-app、vue)、后端(Java、Kotlin、NodeJS、Python、PHP、Go、C、C++)、鸿蒙
![](https://img-blog.csdnimg.cn/f7ba5b3299a24d338b8a71eb8cbd99b7.png)
![image](https://img-blog.csdnimg.cn/img_convert/38c89e2baadeed40e6c5353768ae6cf0.png)
# 1. 安卓Java版
开发工具:[下载Android Studio](https://cxyxy.blog.csdn.net/article/details/107098873)
```java
public static void sort(int[] array) {
int first = 0;
int last = array.length - 1;
mergeSort(array, first, last);
}
private static void mergeSort(int[] array, int first, int last) {
if (first < last) {
int mid = (first + last) / 2;
mergeSort(array, first, mid);
mergeSort(array, mid + 1, last);
binaryMerge(array, first, mid, last);
}
}
public static void binaryMerge(int[] array, int first, int mid, int last) {
int[] tmpArray = new int[array.length];
int left, right, index;
for (index = first; index <= last; index++) {
tmpArray[index] = array[index];
}
index = first;
left = first;
right = mid + 1;
for (; left <= mid && right <= last && index <= last; index++) {
if (tmpArray[left] <= tmpArray[right]) {
array[index] = tmpArray[left++];
} else {
array[index] = tmpArray[right++];
}
}
while (left <= mid) {
array[index++] = tmpArray[left++];
}
while (right <= last) {
array[index++] = tmpArray[right++];
}
}
```
![image](https://img-blog.csdnimg.cn/img_convert/8a816baa9ad1e0cbd5bd0f503cd38601.png)
# 2. 安卓Kotlin版
开发工具:[下载Android Studio](https://cxyxy.blog.csdn.net/article/details/107098873)
```kotlin
fun sort(array: IntArray) {
val first = 0
val last = array.size - 1
mergeSort(array, first, last)
}
private fun mergeSort(array: IntArray, first: Int, last: Int) {
if (first < last) {
val mid = (first + last) / 2
mergeSort(array, first, mid)
mergeSort(array, mid + 1, last)
binaryMerge(array, first, mid, last)
}
}
fun binaryMerge(array: IntArray, first: Int, mid: Int, last: Int) {
val tmpArray = IntArray(array.size)
var left: Int
var index = first
while (index <= last) {
tmpArray[index] = array[index]
index++
}
index = first.also { left = it }
var right = mid + 1
while (left <= mid && right <= last && index <= last) {
if (tmpArray[left] <= tmpArray[right]) {
array[index] = tmpArray[left++]
} else {
array[index] = tmpArray[right++]
}
index++
}
while (left <= mid) array[index++] = tmpArray[left++]
while (right <= last) array[index++] = tmpArray[right++]
}
```
![image](https://img-blog.csdnimg.cn/img_convert/f3a5f272743f38ec5f3d8e6ec4940a02.png)
# 3. NodeJS
开发工具:[下载Visual Studio Code](https://cxyxy.blog.csdn.net/article/details/128722652)
```js
function sort() {
let array = [2, 1, 5, 4, 3]
var first = 0
var last = array.length - 1
mergeSort(array,first, last)
}
function mergeSort(array,first, last) {
if (first < last) {
var mid = Math.floor((first + last) / 2)
mergeSort(array,first, mid)
mergeSort(array,mid + 1, last)
binaryMerge(array,first, mid, last)
}
}
function binaryMerge(array,first, mid, last) {
var tmpArray = Array(array.length).fill(0)
var left, right, index
for (index = first; index <= last; index++) {
tmpArray[index] = array[index]
}
index = first
left = first
right = mid + 1
for (; left <= mid && right <= last && index <= last; index++) {
if (tmpArray[left] <= tmpArray[right]) {
array[index] = tmpArray[left++]
} else {
array[index] = tmpArray[right++]
}
}
while (left <= mid) {
array[index++] = tmpArray[left++]
}
while (right <= last) {
array[index++] = tmpArray[right++]
}
}
```
![image](https://img-blog.csdnimg.cn/img_convert/f92c98533aaf6264fdaf8227f94de76b.png)
# 4. Php
开发工具:[下载Visual Studio Code](https://cxyxy.blog.csdn.net/article/details/128722652)
```php
public function sort()
{
$array = [2, 1, 5, 4, 3];
$start = 0;
$end = count($array) - 1;
$this->sortMe($array, $start, $end);
return var_dump($array);
}
private function sortMe(&$arr, $start, $end)
{
if ($start < $end) {
$mid = floor(($start + $end) / 2);
$this->sortMe($arr, $start, $mid);
$this->sortMe($arr, $mid + 1, $end);
$this->mergeSort($arr, $start, $mid, $end);
}
}
private function mergeSort(&$arr, $start, $mid, $end)
{
$i = $start;
$j = $mid + 1;
$tmp = [];
while ($i <= $mid && $j <= $end) {
if ($arr[$i] <= $arr[$j]) {
$tmp[] = $arr[$i++];
} else {
$tmp[] = $arr[$j++];
}
}
while ($i <= $mid) {
$tmp[] = $arr[$i++];
}
while ($j <= $end) {
$tmp[] = $arr[$j++];
}
for ($k = 0; $k < count($tmp); $k++) {
$arr[$k + $start] = $tmp[$k];
}
}
```
![image](https://img-blog.csdnimg.cn/img_convert/749b42523743051e6bb61f899664e4e8.png)
# 5. Python
开发工具:[下载PyCharm](https://cxyxy.blog.csdn.net/article/details/128722649)
```python
array = [2, 1, 5, 4, 3]
def merge(left, mid, right):
start = mid - left + 1
end = right - mid
left_arr = [0] * start
right_arr = [0] * end
for i in range(0, start):
left_arr[i] = array[left + i]
for j in range(0, end):
right_arr[j] = array[mid + 1 + j]
i = 0
j = 0
k = left
while i < start and j < end:
if left_arr[i] <= right_arr[j]:
array[k] = left_arr[i]
i += 1
else:
array[k] = right_arr[j]
j += 1
k += 1
while i < start:
array[k] = left_arr[i]
i += 1
k += 1
while j < end:
array[k] = right_arr[j]
j += 1
k += 1
def sort(left, right):
if left < right:
m = int((left + (right - 1)) / 2)
sort(left, m)
sort(m + 1, right)
merge(left, m, right)
```
![image](https://img-blog.csdnimg.cn/img_convert/5c9aa2875387231270deb615fea84aec.png)
# 6. Swift(SwiftUI版)
开发工具:XCode(mac电脑自带)
```swift
var array = [2, 1, 5, 4, 3]
func sort() {
sortMe(arr: &array, left: 0, right: array.count - 1)
}
func sortMe(arr:inout [Int],left:Int,right:Int) {
if left == right {
return
}
let mid = left + (right - left) >> 1
sortMe(arr: &arr, left: left, right: mid)
sortMe(arr: &arr, left: mid + 1, right: right)
mergeSort(arr: &arr, left: left, mid: mid, right: right)
}
func mergeSort(arr:inout [Int],left:Int,mid:Int,right:Int){
var tmpArr:[Int] = [Int]()
var leftLocation:Int = left
var rightLocation:Int = mid + 1
while (leftLocation <= mid && rightLocation <= right) {
if arr[leftLocation] <= arr[rightLocation] {
tmpArr.append(arr[leftLocation])
leftLocation += 1
}else{
tmpArr.append(arr[rightLocation])
rightLocation += 1
}
}
while leftLocation <= mid {
tmpArr.append(arr[leftLocation])
leftLocation += 1
}
while rightLocation <= right {
tmpArr.append(arr[rightLocation])
rightLocation += 1
}
var index = left
没有合适的资源?快使用搜索试试~ 我知道了~
排序算法: 冒泡排序,桶排序,计数排序,堆排序,插入排序,合并排序,快速排序,基数排序,选择排序,希尔排序 实现语言: C++
共95个文件
md:12个
gitignore:11个
filters:10个
0 下载量 151 浏览量
2024-01-15
10:37:38
上传
评论
收藏 261KB ZIP 举报
温馨提示
快速排序
资源推荐
资源详情
资源评论
收起资源包目录
sort_algorithm_cpp-master.zip (95个子文件)
sort_algorithm_cpp-master
README_CN.md 869B
radixSort
sort_C++
Lblbc.dSYM
Contents
Resources
DWARF
Lblbc 89KB
Info.plist 634B
.vscode
tasks.json 714B
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 1KB
Sort.vcxproj.user 165B
.gitignore 7B
Lblbc 45KB
README.MD 19KB
Sort.vcxproj 6KB
quickSort
sort_C++
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 1KB
Sort.vcxproj.user 165B
.gitignore 7B
README.MD 13KB
Sort.vcxproj 6KB
shellSort
sort_C++
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 1KB
Sort.vcxproj.user 165B
.gitignore 7B
README.MD 12KB
Sort.vcxproj 6KB
bucketSort
sort_C++
Lblbc.dSYM
Contents
Resources
DWARF
Lblbc 89KB
Info.plist 634B
.vscode
settings.json 62B
tasks.json 714B
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 1KB
Sort.vcxproj.user 165B
.gitignore 7B
Lblbc 45KB
README.MD 15KB
Sort.vcxproj 6KB
LICENSE 70B
countSort
sort_C++
Lblbc.dSYM
Contents
Resources
DWARF
Lblbc 89KB
Info.plist 634B
.vscode
tasks.json 714B
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 1KB
Sort.vcxproj.user 165B
.gitignore 7B
Lblbc 45KB
README.MD 14KB
Sort.vcxproj 6KB
heapSort
sort_C++
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 1KB
Sort.vcxproj.user 165B
.gitignore 7B
README.MD 16KB
Sort.vcxproj 6KB
.gitignore 16B
bubbleSort
sort_C++
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 854B
Sort.vcxproj.user 165B
.gitignore 7B
README.MD 8KB
Sort.vcxproj 6KB
mergeSort
sort_C++
Lblbc.dSYM
Contents
Resources
DWARF
Lblbc 89KB
Info.plist 634B
.vscode
tasks.json 714B
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 1KB
Sort.vcxproj.user 165B
.gitignore 7B
Lblbc 45KB
README.MD 21KB
Sort.vcxproj 6KB
README.md 883B
insertionSort
sort_C++
Lblbc.dSYM
Contents
Resources
DWARF
Lblbc 88KB
Info.plist 634B
.vscode
tasks.json 714B
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 909B
Sort.vcxproj.user 165B
.gitignore 7B
Lblbc 45KB
README.MD 10KB
Sort.vcxproj 6KB
selectionSort
sort_C++
Sort.vcxproj.filters 946B
Sort.sln 1KB
Lblbc.cpp 1KB
Sort.vcxproj.user 165B
.gitignore 7B
README.MD 13KB
Sort.vcxproj 6KB
共 95 条
- 1
资源评论
十小大
- 粉丝: 9123
- 资源: 2552
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功