-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96f1006
commit 8418c82
Showing
21 changed files
with
492 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package Basic | ||
|
||
fun main(args: Array<String>) { | ||
|
||
var a = 5; | ||
var b = 10 | ||
var max = if (a > b) { | ||
println("a is max") | ||
a | ||
} else { | ||
println("b is max") | ||
b | ||
} | ||
print("value= $max") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package Basic | ||
|
||
/** | ||
* Created by Aman gautam on 12-Jul-17. | ||
*/ | ||
|
||
fun sum(a: Int, b: Int): Int { | ||
return a + b | ||
} | ||
|
||
fun add(vararg num: Int) = num.sum() | ||
|
||
fun sub(a: Int, b: Int) = a - b | ||
|
||
fun main(args: Array<String>) { | ||
println("Basic.sum of digits is : ${sum(3, 5)}") | ||
println(sub(a = 3, b = 5)) | ||
println(sub(b = 3, a = 5)) | ||
println(add(1, 2, 3, 4)) | ||
println(add(21, 32, 12)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
package Basic | ||
|
||
/** | ||
* Created by Aman gautam on 12-Jul-17. | ||
*/ | ||
|
||
fun sum(a :Int, b:Int): Int{ | ||
return a+b | ||
fun add(a: Int, b: Int): Int { | ||
return a + b; | ||
} | ||
fun add(vararg num:Int) = num.sum() | ||
|
||
fun sub(a:Int, b:Int) =a-b | ||
fun substract(a: Int, b: Int) = a - b | ||
|
||
fun defAdd(a: Int = 10, b: Int): Int { | ||
return a + b; | ||
} | ||
|
||
fun main(args : Array<String>){ | ||
println("Basic.sum of digits is : ${sum(3, 5)}") | ||
println(sub(a = 3, b = 5)) | ||
println(sub(b = 3, a = 5)) | ||
println(add(1, 2, 3, 4)) | ||
println(add(21, 32, 12)) | ||
fun name(name: String) { | ||
print(name) | ||
} | ||
|
||
fun main(arg: Array<String>) { | ||
var result = add(10, 20) | ||
println(result) | ||
result = sub(20, 10) | ||
println(result) | ||
result = defAdd(b = 10) | ||
println(result) | ||
name("Aman") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Created by Aman gautam on 25-Nov-17. | ||
*/ | ||
fun main(args: Array<String>) { | ||
println("Basic Calculator using Kotlin!") | ||
println("Enter two values ") | ||
print("a = ") | ||
var a = readLine()!!.toDouble() | ||
print("b = ") | ||
var b = readLine()!!.toDouble() | ||
println("1. Addition \n2. Substraction \n3. Multiplication \n4. Divide") | ||
print("Enter Choice : ") | ||
var ch = readLine()!!.toInt() | ||
print("Result : ") | ||
when (ch) { | ||
1 -> print("a+b = ${a + b}") | ||
2 -> print("a-b = ${a - b}") | ||
3 -> print("a*b = ${a * b}") | ||
4 -> print("a/b = ${a / b}") | ||
else -> print("Wrong Choice") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package Basic | ||
|
||
fun main(arr: Array<String>) { | ||
|
||
for (i in 1..10) { | ||
print(i) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package Data_Structure | ||
|
||
var heapSize = 0 | ||
|
||
fun left(i: Int): Int { | ||
return 2 * i | ||
} | ||
|
||
fun right(i: Int): Int { | ||
return 2 * i + 1 | ||
} | ||
|
||
fun swap(A: Array<Int>, i: Int, j: Int) { | ||
var temp = A[i] | ||
A[i] = A[j] | ||
A[j] = temp | ||
} | ||
|
||
fun max_heapify(A: Array<Int>, i: Int) { | ||
var l = left(i); | ||
var r = right(i); | ||
var largest: Int; | ||
|
||
if ((l <= heapSize - 1) && (A[l] > A[i])) { | ||
largest = l; | ||
} else | ||
largest = i | ||
|
||
if ((r <= heapSize - 1) && (A[r] > A[l])) { | ||
largest = r | ||
} | ||
|
||
if (largest != i) { | ||
swap(A, i, largest); | ||
max_heapify(A, largest); | ||
} | ||
} | ||
|
||
fun buildMaxheap(A: Array<Int>) { | ||
heapSize = A.size | ||
for (i in heapSize / 2 downTo 0) { | ||
max_heapify(A, i) | ||
} | ||
} | ||
|
||
fun heap_sort(A: Array<Int>) { | ||
buildMaxheap(A) | ||
for (i in A.size - 1 downTo 1) { | ||
swap(A, i, 0) | ||
heapSize = heapSize - 1 | ||
max_heapify(A, 0) | ||
|
||
} | ||
} | ||
|
||
fun main(arg: Array<String>) { | ||
print("Enter no. of elements :") | ||
var n = readLine()!!.toInt() | ||
|
||
println("Enter elements : ") | ||
var A = Array(n, { 0 }) | ||
for (i in 0 until n) | ||
A[i] = readLine()!!.toInt() | ||
|
||
heap_sort(A) | ||
|
||
println("Sorted array is : ") | ||
for (i in 0 until n) | ||
print("${A[i]} ") | ||
} | ||
|
Oops, something went wrong.