From 19fdeb39296c6ddb69c9ee6b97e5901832832611 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 4 Jun 2020 15:53:58 +0300 Subject: [PATCH] add 6 lesson --- .../Contents.swift | 45 +++++++++++++++++++ .../contents.xcplayground | 4 ++ 2 files changed, 49 insertions(+) create mode 100644 6l_ChukarkovKonstantin.playground/Contents.swift create mode 100644 6l_ChukarkovKonstantin.playground/contents.xcplayground diff --git a/6l_ChukarkovKonstantin.playground/Contents.swift b/6l_ChukarkovKonstantin.playground/Contents.swift new file mode 100644 index 0000000..d8b0348 --- /dev/null +++ b/6l_ChukarkovKonstantin.playground/Contents.swift @@ -0,0 +1,45 @@ + +struct Stack { + + var items = [Element]() + mutating func push(_ item: Element) { + items.append(item) + } + + mutating func pop() -> Element { + return items.removeLast() + } + + mutating func append(_ item: Element) { + self.push(item) + } + + + var count: Int { + return items.count + } + + subscript(i: Int) -> Element? { + if i < items.count { + return items[i] + } + return nil + } + +} + + +var stack = Stack() + +stack.push("кот") +stack.push("бегемот") +stack.push("жираф") +stack.push("крыса") + +stack.pop() + +print(stack.count) + + +print(stack[1]!) +print(stack[4] as Any) diff --git a/6l_ChukarkovKonstantin.playground/contents.xcplayground b/6l_ChukarkovKonstantin.playground/contents.xcplayground new file mode 100644 index 0000000..5da2641 --- /dev/null +++ b/6l_ChukarkovKonstantin.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file