forked from kelvins/algorithms-and-data-structures
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deque.swift
51 lines (38 loc) · 786 Bytes
/
deque.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// deque.swift
//
//
// Created by Matheus Torres on 14/11/20.
//
class Deque {
var deque: [Int] = []
func addAtBeginning(_ value: Int) {
deque.insert(value, at: 0)
}
func addAtEnd(_ value: Int) {
deque.append(value)
}
func removeAtBeggining() {
deque.removeFirst()
}
func removeAtEnd() {
deque.removeLast()
}
func read() {
print(deque)
}
func readReverse() {
print(Array(deque.reversed()))
}
}
let newDeque = Deque()
for n in 0...20 {
newDeque.addAtEnd(n)
}
newDeque.addAtBeginning(666)
newDeque.addAtBeginning(1000)
newDeque.removeAtBeggining()
newDeque.addAtBeginning(616)
newDeque.removeAtEnd()
newDeque.read()
newDeque.readReverse()