真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

17種編程語言實現(xiàn)排序算法-快速排序-創(chuàng)新互聯(lián)

開源地址

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++)、鴻蒙

目前創(chuàng)新互聯(lián)已為近1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站運營、企業(yè)網(wǎng)站設(shè)計、建湖網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

image

1. 安卓Java版

開發(fā)工具:下載Android Studio

private static void sort(int[] array) {sortMe(array, 0, array.length - 1);
}

private static void sortMe(int[] array, int low, int high) {if (low >= high) {return;
    }
    int pivot = array[low];
    int l = low;
    int r = high;
    int tmp;
    while (l< r) {while (l< r && array[r] >= pivot) {r--;
        }
        while (l< r && array[l]<= pivot) {l++;
        }
        if (l< r) {tmp = array[l];
            array[l] = array[r];
            array[r] = tmp;
        }
    }
    array[low] = array[l];
    array[l] = pivot;
    if (low< l) {sortMe(array, low, l - 1);
    }
    if (r< high) {sortMe(array, r + 1, high);
    }
}

2. 安卓Kotlin版

開發(fā)工具:下載Android Studio

private fun sort(array: IntArray) {sortMe(array, 0, array.size - 1)
}

private fun sortMe(array: IntArray, low: Int, high: Int) {if (low >= high) {return
    }
    val pivot = array[low]
    var l = low
    var r = high
    var tmp: Int
    while (l< r) {while (l< r && array[r] >= pivot) {r--
        }
        while (l< r && array[l]<= pivot) {l++
        }
        if (l< r) {tmp = array[l]
            array[l] = array[r]
            array[r] = tmp
        }
    }
    array[low] = array[l]
    array[l] = pivot
    if (low< l) {sortMe(array, low, l - 1)
    }
    if (r< high) {sortMe(array, r + 1, high)
    }
}

3. NodeJS

開發(fā)工具:下載Visual Studio Code

function sort() {sortMe(0, array.length - 1);
  return convertToStr(array);
}

function sortMe(slow, fast) {let base = array[slow];
  array[slow] = 0;
  let left = slow;
  let right = fast;
  while (left< right) {if (array[left] === 0) {  if (array[right]< base) {array[left] = array[right];
        array[right] = 0;
        left = left + 1;
      }
      else {right = right - 1;
      }
    } else if (array[right] === 0) {  if (array[left] >= base) {array[right] = array[left];
        array[left] = 0;
        right = right - 1;
      }
      else {left = left + 1;
      }
    }
  }
  array[left] = base;
  if ((left - 1) - slow >0) {sortMe(slow, left - 1);
  }
  if (fast - (right + 1) >0) {sortMe(right + 1, fast);
  }
  return
}

4. Php

開發(fā)工具:下載Visual Studio Code

public function sort()
    {$array = [2, 1, 5, 4, 3];
        $result = $this->sortMe($array);
        return var_dump($result);
    }

    public function sortMe($arr)
    {$length = count($arr);
        if (!is_array($arr) || $length<= 1) {return $arr;
        }
        $baseValue = $arr[0];
        $leftArr = array();
        $rightArr = array();
        for ($i = 1; $i< $length; $i++) {if ($arr[$i]< $baseValue) {$leftArr[] = $arr[$i];
            } else {$rightArr[] = $arr[$i];
            }
        }
        $leftArr = $this->sortMe($leftArr);
        $rightArr = $this->sortMe($rightArr);
        return array_merge($leftArr, array($baseValue), $rightArr);
    }

5. Python

開發(fā)工具:下載PyCharm

array = [2, 1, 5, 4, 3]


def sort(array, low, high):
    if low >= high:
        return array
    i = low
    j = high
    pivot = array[low]
    while i< j:
        while i< j and array[j] >pivot:
            j -= 1
        array[i] = array[j]
        while i< j and array[i]< pivot:
            i += 1
        array[j] = array[i]
    array[j] = pivot

    sort(array, low, j - 1)
    sort(array, j + 1, high)

    return

6. Swift(SwiftUI版)

開發(fā)工具:XCode(mac電腦自帶)

var array = [2, 1, 5, 4, 3]
func sort() {sortMe(array: &array, left: 0, right: array.count - 1)
}

func sortMe(array: inout [Int], left: Int, right: Int) {if right - left<= 0 {return
    }
    
    var flagIndex = left
    let flagValue = array[left]
    
    for index in stride(from: left + 1, to: right + 1, by: 1) {let value = array[index]
        if value< flagValue {array[flagIndex] = value
            flagIndex += 1
            array[index] = array[flagIndex]
            array[flagIndex] = flagValue
        }
    }
    
    sortMe(array: &array, left: left, right: flagIndex - 1)
    sortMe(array: &array, left: flagIndex + 1, right: right)
}

7. uni-app

開發(fā)工具:下載HBuilderX

sort() {let array = this.array;
	this.sortMe(array, 0, array.length - 1);
	this.array = array
	this.arrayStr = this.convertToStr(array)
},
sortMe(array: number[], low: number, high: number) {if (low >= high) {return;
	}
	var index = array[low];
	var i = low;
	var j = high;
	while (i< j) {while (i< j && array[j] >= index) {	j--;
		}
		if (i< j) {	array[i] = array[j];
			i++;
		}
		while (i< j && array[i]< index) {	i++;
		}
		if (i< j) {	array[j] = array[i];
			j--;
		}
	}
	array[i] = index;
	this.sortMe(array, low, i - 1);
	this.sortMe(array, i + 1, high);
},

8. vue

開發(fā)工具:下載Visual Studio Code

9. 微信小程序

開發(fā)工具:下載微信開發(fā)者工具

sort() {let array = this.data.array;
  this.sortMe(array, 0, array.length - 1);
  this.setData({array: array,
    arrayStr: this.convertToStr(array),
  })
},
sortMe(array: number[], low: number, high: number) {if (low >= high) {return;
  }
  var index = array[low];
  var i = low;
  var j = high;
  while (i< j) {while (i< j && array[j] >= index) {  j--;
    }
    if (i< j) {  array[i] = array[j];
      i++;
    }
    while (i< j && array[i]< index) {  i++;
    }
    if (i< j) {  array[j] = array[i];
      j--;
    }
  }
  array[i] = index;
  this.sortMe(array, low, i - 1);
  this.sortMe(array, i + 1, high);
},

10. 鴻蒙(ArkTS)

開發(fā)工具:下載DevEco Studio

sort() {let array = this.array;
    this.sortMe(array, 0, array.length - 1);
    this.array = array
  }

  sortMe(array: number[], low: number, high: number) {if (low >= high) {  return;
    }
    var index = array[low];
    var i = low;
    var j = high;
    while (i< j) {  while (i< j && array[j] >= index) {j--;
      }
      if (i< j) {array[i] = array[j];
        i++;
      }
      while (i< j && array[i]< index) {i++;
      }
      if (i< j) {array[j] = array[i];
        j--;
      }
    }
    array[i] = index;
    this.sortMe(array, low, i - 1);
    this.sortMe(array, i + 1, high);
  }

11. Go語言

開發(fā)工具:下載Visual Studio Code

func sort(left int, right int, array *[5]int) {l := left
	r := right
	pivot := array[(left+right)/2]
	tmp := 0
	for l< r {for array[l]< pivot {	l++
		}
		for array[r] >pivot {	r--
		}
		if l >= r {	break
		}
		tmp = array[l]
		array[l] = array[r]
		array[r] = tmp
		if array[l] == pivot {	r--
		}
		if array[r] == pivot {	l++
		}
	}
	if l == r {l++
		r--
	}
	if left< r {sort(left, r, array)
	}
	if right >l {sort(l, right, array)
	}
}

12. Java

開發(fā)工具:下載IntelliJ IDEA

private static void sort(int[] array) {sortMe(array, 0, array.length - 1);
}

public static void sortMe(int[] array, int low, int high) {if (low >= high) {return;
    }
    int pivot = array[low];
    int l = low;
    int r = high;
    int tmp;
    while (l< r) {while (l< r && array[r] >= pivot) {r--;
        }
        while (l< r && array[l]<= pivot) {l++;
        }
        if (l< r) {tmp = array[l];
            array[l] = array[r];
            array[r] = tmp;
        }
    }
    array[low] = array[l];
    array[l] = pivot;
    if (low< l) {sortMe(array, low, l - 1);
    }
    if (r< high) {sortMe(array, r + 1, high);
    }
}

13. Kotlin

開發(fā)工具:下載IntelliJ IDEA

private fun sort(array: IntArray) {sortMe(array, 0, array.size - 1)
}

fun sortMe(array: IntArray, low: Int, high: Int) {if (low >= high) {return
    }
    val pivot = array[low]
    var l = low
    var r = high
    var tmp: Int
    while (l< r) {while (l< r && array[r] >= pivot) {r--
        }
        while (l< r && array[l]<= pivot) {l++
        }
        if (l< r) {tmp = array[l]
            array[l] = array[r]
            array[r] = tmp
        }
    }
    array[low] = array[l]
    array[l] = pivot
    if (low< l) {sortMe(array, low, l - 1)
    }
    if (r< high) {sortMe(array, r + 1, high)
    }
}

14. Flutter

開發(fā)工具:下載IntelliJ IDEA

Listsort(Listlist) {if (list.length< 2) {return list;
  } else {var pivot = list[0];
    var less =[];
    var greater =[];
    list.removeAt(0);
    for (var i in list) {  if (i<= pivot) {less.add(i);
      } else {greater.add(i);
      }
    }
    return sort(less) + [pivot] + sort(greater);
  }
}

15. C語言

開發(fā)工具:下載Visual Studio

void sortMe(int* array, int low, int high)
{if (low >= high)
    {return;
    }
    int index = array[low];
    int i = low;
    int j = high;
    while (i< j)
    {while (i< j && array[j] >= index)
        {j--;
        }
        if (i< j)
        {array[i] = array[j];
            i++;
        }
        while (i< j && array[i]< index)
        {i++;
        }
        if (i< j)
        {array[j] = array[i];
            j--;
        }
    }
    array[i] = index;
    sortMe(array, low, i - 1);
    sortMe(array, i + 1, high);
}

void sort(int* array, int count)
{sortMe(array, 0, count - 1);
}

16. C++

開發(fā)工具:下載Visual Studio

void sortMe(int* array, int low, int high)
{if (low >= high)
    {return;
    }
    int index = array[low];
    int i = low;
    int j = high;
    while (i< j)
    {while (i< j && array[j] >= index)
        {j--;
        }
        if (i< j)
        {array[i] = array[j];
            i++;
        }
        while (i< j && array[i]< index)
        {i++;
        }
        if (i< j)
        {array[j] = array[i];
            j--;
        }
    }
    array[i] = index;
    sortMe(array, low, i - 1);
    sortMe(array, i + 1, high);
}


void sort(int* array, int count)
{sortMe(array, 0, count - 1);
}

17. C#

開發(fā)工具:下載Visual Studio

private static void Sort(int[] array)
{SortMe(array, 0, array.Length - 1);
}
private static void SortMe(int[] array, int low, int high)
{if (low >= high)
    {return;
    }
    int index = array[low];
    int i = low;
    int j = high;
    while (i< j)
    {while (i< j && array[j] >= index)
        {j--;
        }
        if (i< j)
        {array[i] = array[j];
            i++;
        }
        while (i< j && array[i]< index)
        {i++;
        }
        if (i< j)
        {array[j] = array[i];
            j--;
        }
    }
    array[i] = index;
    SortMe(array, low, i - 1);
    SortMe(array, i + 1, high);
}

關(guān)于

廈門大學(xué)計算機專業(yè)|華為八年高級工程師
專注《零基礎(chǔ)學(xué)編程系列》 http://lblbc.cn/blog
包含:Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鴻蒙
公眾號:藍不藍編程

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧


文章題目:17種編程語言實現(xiàn)排序算法-快速排序-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://weahome.cn/article/csccgj.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部