Swift Syudy! - 2
Data Structure
This time, I focused on the data structure.
Set
I know two characteristics about this.
- There is no order.
- There is no duplicate data.
This can be found out through examples.
var a : Set = [1,2,3,1,1,1]
print(a)
The datatype can be used as a Set and elements can be listed in [ ].
Add elements
In an arrangement, elements are added as follows.
var b : [Int] = [1,2,3]
b.append(5)
print(b)
So then, How to insert datatype at Set?
Yeah, that’s the insert.
var a : Set = [1,2,3,1,1,1]
a.insert(5)
print(a)
By executing this code, you can see that the element has been added.
It’s good to know.
var a : Set = [1,2,3,1,1,1]
a.insert(5) // add element
print(a.count) // count
print(a.contains(3)) // include?
print(a.isEmpty)
a.remove(3)
print(a)
print(a.max()) // max