From cb1e9c1a8a1de8c6be7b41027db3ada16070d691 Mon Sep 17 00:00:00 2001 From: Zackratos <869649338@qq.com> Date: Wed, 19 Jun 2019 01:27:35 +0800 Subject: [PATCH] update code format --- kotlin/08_stack/StackBasedOnLinkedList.kt | 46 +++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/kotlin/08_stack/StackBasedOnLinkedList.kt b/kotlin/08_stack/StackBasedOnLinkedList.kt index e0f37c4..76ea545 100644 --- a/kotlin/08_stack/StackBasedOnLinkedList.kt +++ b/kotlin/08_stack/StackBasedOnLinkedList.kt @@ -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?) - + } \ No newline at end of file