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++)、鸿蒙
开发工具:下载Android Studio
private void sort(int[] array) {for (int i = 0; i< array.length - 1; i++) {for (int j = 0; j< array.length - 1 - i; j++) {if (array[j] >array[j + 1]) {int tmp = array[j + 1];
array[j + 1] = array[j];
array[j] = tmp;
}
}
}
}
2. 安卓Kotlin版开发工具:下载Android Studio
private fun sort(array: IntArray) {for (i in 0 until array.size - 1) {for (j in 0 until array.size - 1 - i) {if (array[j] >array[j + 1]) {val tmp = array[j + 1]
array[j + 1] = array[j]
array[j] = tmp
}
}
}
}
3. NodeJS开发工具:下载Visual Studio Code
function sort() {let array = [2, 1, 5, 4, 3]
for (let i = 0; i< array.length - 1; i++) {for (let j = 0; j< array.length - 1 - i; j++) { if (array[j] >array[j + 1]) {let tmp = array[j + 1]
array[j + 1] = array[j]
array[j] = tmp
}
}
}
return convertToStr(array)
}
4. Php开发工具:下载Visual Studio Code
public function sort()
{$array = [2, 1, 5, 4, 3];
for ($i = 0; $i< count($array) -1; $i++) {for ($j = 0; $j< count($array) -1 -$i; $j++) {if ($array[$j] >$array[$j + 1]) {$tmp = $array[$j];
$array[$j] = $array[$j + 1];
$array[$j + 1] = $tmp;
}
}
}
return var_dump($array);
}
5. Python开发工具:下载PyCharm
array = [2, 1, 5, 4, 3]
def sort():
count = len(array)
for i in range(count):
for j in range(0, count - i - 1):
if array[j] >array[j + 1]:
array[j], array[j + 1] = array[j + 1], array[j]
6. Swift(SwiftUI版)开发工具:XCode(mac电脑自带)
var array = [2, 1, 5, 4, 3]
func sort() {for i in 0...array.count-2 {for j in 0...array.count-2-i {if (array[j] >array[j + 1]) {let tmp = array[j + 1];
array[j + 1] = array[j];
array[j] = tmp;
}
}
}
}
7. uni-app开发工具:下载HBuilderX
sort() {let array = [2, 1, 5, 4, 3]
for (let i = 0; i< array.length - 1; i++) {for (let j = 0; j< array.length - 1 - i; j++) { if (array[j] >array[j + 1]) {let tmp = array[j + 1]
array[j + 1] = array[j]
array[j] = tmp
}
}
}
}
8. vue开发工具:下载Visual Studio Code
sort() {let array = [2, 1, 5, 4, 3]
for (let i = 0; i< array.length - 1; i++) {for (let j = 0; j< array.length - 1 - i; j++) { if (array[j] >array[j + 1]) {let tmp = array[j + 1]
array[j + 1] = array[j]
array[j] = tmp
}
}
}
}
9. 微信小程序开发工具:下载微信开发者工具
sort() {let array = [2, 1, 5, 4, 3]
for (let i = 0; i< array.length - 1; i++) {for (let j = 0; j< array.length - 1 - i; j++) { if (array[j] >array[j + 1]) {let tmp = array[j + 1];
array[j + 1] = array[j];
array[j] = tmp;
}
}
}
}
10. 鸿蒙(ArkTS)开发工具:下载DevEco Studio
sort() {let array = this.array
for (let i = 0; i< array.length - 1; i++) {for (let j = 0; j< array.length - 1 - i; j++) { if (array[j] >array[j + 1]) {let tmp = array[j + 1]
array[j + 1] = array[j]
array[j] = tmp
}
}
}
this.array = array
}
11. Go语言开发工具:下载Visual Studio Code
var array = []int{2, 1, 5, 4, 3}
func sort() {for i := 0; i< len(array)-1; i++ {for j := 0; j< len(array)-1-i; j++ { if array[j] >array[j+1] { tmp := array[j+1]
array[j+1] = array[j]
array[j] = tmp
}
}
}
}
12. Java开发工具:下载IntelliJ IDEA
private static void sort(int[] array) {for (int i = 0; i< array.length - 1; i++) {for (int j = 0; j< array.length - 1 - i; j++) {if (array[j] >array[j + 1]) {int tmp = array[j + 1];
array[j + 1] = array[j];
array[j] = tmp;
}
}
}
}
13. Kotlin开发工具:下载IntelliJ IDEA
private fun sort(array: IntArray) {for (i in 0 until array.size - 1) {for (j in 0 until array.size - 1 - i) {if (array[j] >array[j + 1]) {val tmp = array[j + 1]
array[j + 1] = array[j]
array[j] = tmp
}
}
}
}
14. Flutter开发工具:下载IntelliJ IDEA
void sort(Listlist) {for (int i = 0; i< list.length - 1; i++) {for (int j = 0; j< list.length - 1 - i; j++) { if (list[j] >list[j + 1]) {var tmp = list[j + 1];
list[j + 1] = list[j];
list[j] = tmp;
}
}
}
}
15. C语言开发工具:下载Visual Studio
void sort(int* array, int count)
{for (int i = 0; i< count - 1; i++)
{for (int j = 0; j< count - 1 - i; j++)
{ if (array[j + 1]< array[j])
{ int tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
}
}
16. C++开发工具:下载Visual Studio
void sort(int* array, int count)
{for (int i = 0; i< count - 1; i++)
{for (int j = 0; j< count - 1 - i; j++)
{ if (array[j + 1]< array[j])
{ int tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
}
}
17. C#开发工具:下载Visual Studio
private void Sort(int[] array)
{for (int i = 0; i< array.Length - 1; i++)
{for (int j = 0; j< array.Length - 1 - i; j++)
{if (array[j] >array[j + 1])
{int tmp = array[j + 1];
array[j + 1] = array[j];
array[j] = tmp;
}
}
}
}
关于厦门大学计算机专业|华为八年高级工程师
专注《零基础学编程系列》 http://lblbc.cn/blog
包含:Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鸿蒙
公众号:蓝不蓝编程
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧