Skip to content

Commit 25e6a19

Browse files
kelvinlauKLremlostime
authored andcommitted
Removed mentions of Encodable and Decodable protocol. Fixed a typo.
1 parent 4187a9a commit 25e6a19

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Encode and Decode Tree/readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Encoding and decoding are synonyms to *serializing* and *deserializing* trees.
1313
As a reference, the following code represents the typical `Node` type of a binary tree:
1414

1515
```swift
16-
class BinaryNode<Element: Comparable & Encodable> {
16+
class BinaryNode<Element: Comparable> {
1717
var data: Element
1818
var leftChild: BinaryNode?
1919
var rightChild: BinaryNode?
@@ -79,7 +79,7 @@ class BinaryNodeCoder {
7979
private var nilNode: String { return "X" }
8080

8181
// 4
82-
func encode<T: Encodable>(_ node: BinaryNode<T>) -> String {
82+
func encode<T>(_ node: BinaryNode<T>) -> String {
8383
var str = ""
8484
node.preOrderTraversal { data in
8585
if let data = data {
@@ -128,13 +128,13 @@ class BinaryNodeCoder {
128128
// ...
129129

130130
// 1
131-
func decode<T: Decodable>(_ string: String) -> BinaryNode<T>? {
131+
func decode<T>(_ string: String) -> BinaryNode<T>? {
132132
let components = encoded.lazy.split(separator: separator).reversed().map(String.init)
133133
return decode(from: components)
134134
}
135135

136136
// 2
137-
private func decode(from array: inout [String]) -> AVLNode<String>? {
137+
private func decode(from array: inout [String]) -> BinaryNode<String>? {
138138
guard !array.isEmpty else { return nil }
139139
let value = array.removeLast()
140140
guard value != "\(nilNode)" else { return nil }

0 commit comments

Comments
 (0)