Skip to content

Commit

Permalink
update code format
Browse files Browse the repository at this point in the history
  • Loading branch information
Zackratos committed Jun 18, 2019
1 parent c9097e3 commit cb1e9c1
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions kotlin/08_stack/StackBasedOnLinkedList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@
*/

class StackBasedOnLinkedList {

private var top: Node? = null

private var top: Node? = null

fun push(value: Int) {
val newNode = Node(value, null)
// 不管 top 是不是 null,都可以这么写
newNode.next = top
top = newNode
}
fun push(value: Int) {
val newNode = Node(value, null)
// 不管 top 是不是 null,都可以这么写
newNode.next = top
top = newNode
}

fun pop(): Int {
if (top == null) return -1
val node = top
top = top!!.next
return node!!.data
}
fun pop(): Int {
if (top == null) return -1
val node = top
top = top!!.next
return node!!.data
}

fun printAll() {
var p = top
while(p != null) {
print("${p.data} ")
p = p.next
}
println()
}
fun printAll() {
var p = top
while (p != null) {
print("${p.data} ")
p = p.next
}
println()
}

class Node(var data: Int, var next: Node?)

}

0 comments on commit cb1e9c1

Please sign in to comment.