Refine kotlin code (#1241)

* style(kotlin): Improve kotlin codes readability.

* remove redundant quotes.

* style(kotlin): improve codes readability.

* style(kotlin): refine kotlin codes.

* Create kotlin.yml

* Create kotlin.yml

* Delete .github/workflows/kotlin

* Delete .github/workflows/main.yml

* Create kotlin.yml

* Update kotlin.yml

* Delete .github/workflows/kotlin.yml

* Create hello_world_workflow.main.kts

* Delete .github/workflows/hello_world_workflow.main.kts

* remove empty line
This commit is contained in:
curtishd
2024-04-09 16:26:58 +08:00
committed by GitHub
parent 41dd677338
commit 896d9a64f6
22 changed files with 158 additions and 112 deletions

View File

@@ -20,7 +20,7 @@ fun <T> printMatrix(matrix: Array<Array<T>>) {
}
/* 打印矩阵List */
fun <T> printMatrix(matrix: List<List<T>>) {
fun <T> printMatrix(matrix: MutableList<MutableList<T>>) {
println("[")
for (row in matrix) {
println(" $row,")
@@ -31,7 +31,7 @@ fun <T> printMatrix(matrix: List<List<T>>) {
/* 打印链表 */
fun printLinkedList(h: ListNode?) {
var head = h
val list = ArrayList<String>()
val list = mutableListOf<String>()
while (head != null) {
list.add(head.value.toString())
head = head.next
@@ -91,16 +91,17 @@ fun showTrunks(p: Trunk?) {
/* 打印哈希表 */
fun <K, V> printHashMap(map: Map<K, V>) {
for ((key, value) in map) {
println(key.toString() + " -> " + value)
println("${key.toString()} -> $value")
}
}
/* 打印堆 */
fun printHeap(queue: Queue<Int>?) {
val list = queue?.let { ArrayList(it) }
val list = mutableListOf<Int?>()
queue?.let { list.addAll(it) }
print("堆的数组表示:")
println(list)
println("堆的树状表示:")
val root = list?.let { TreeNode.listToTree(it) }
val root = TreeNode.listToTree(list)
printTree(root)
}

View File

@@ -7,6 +7,7 @@
package utils
/* 二叉树节点类 */
/* 构造方法 */
class TreeNode(
var value: Int // 节点值
) {
@@ -59,8 +60,8 @@ class TreeNode(
}
/* 将二叉树序列化为列表 */
fun treeToList(root: TreeNode?): List<Int?> {
val res = ArrayList<Int?>()
fun treeToList(root: TreeNode?): MutableList<Int?> {
val res = mutableListOf<Int?>()
treeToListDFS(root, 0, res)
return res
}

View File

@@ -19,8 +19,8 @@ class Vertex(val value: Int) {
}
/* 输入顶点列表 vets ,返回值列表 vals */
fun vetsToVals(vets: List<Vertex?>): List<Int> {
val vals = ArrayList<Int>()
fun vetsToVals(vets: MutableList<Vertex?>): MutableList<Int> {
val vals = mutableListOf<Int>()
for (vet in vets) {
vals.add(vet!!.value)
}