Skip to content

Commit 07f4033

Browse files
Merge pull request #139 from AkhzarFarhan/master
bubble sort added in kotlin
2 parents 402cf8e + ae27b4c commit 07f4033

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.*
2+
fun bubbleSort(arr:IntArray){
3+
for(i in 0 until arr.size-1){
4+
for(j in 0 until arr.size-i-1){
5+
if(arr[j]>arr[j+1]){
6+
var temp = arr[j]
7+
arr[j] = arr[j+1]
8+
arr[j+1] = temp
9+
}
10+
}
11+
}
12+
}
13+
fun main(args:Array<String>) {
14+
var scanner = Scanner(System.`in`)
15+
print("enter the size to be sorted ")
16+
var sizeOfList = scanner.nextInt()
17+
val array = IntArray(sizeOfList)
18+
print("start entering values to be sorted ")
19+
for (i in 0 until sizeOfList) {
20+
array[i] = scanner.nextInt();
21+
}
22+
bubbleSort(array)
23+
for (i in 0 until sizeOfList){
24+
print(array[i])
25+
print(" ")
26+
}
27+
}

0 commit comments

Comments
 (0)