Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions 6l_ChukarkovKonstantin.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

struct Stack<Element> {

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<String>()

stack.push("кот")
stack.push("бегемот")
stack.push("жираф")
stack.push("крыса")

stack.pop()

print(stack.count)


print(stack[1]!)
print(stack[4] as Any)
4 changes: 4 additions & 0 deletions 6l_ChukarkovKonstantin.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>