File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ Encoding and decoding are synonyms to *serializing* and *deserializing* trees.
13
13
As a reference, the following code represents the typical ` Node ` type of a binary tree:
14
14
15
15
``` swift
16
- class BinaryNode <Element : Comparable & Encodable > {
16
+ class BinaryNode <Element : Comparable > {
17
17
var data: Element
18
18
var leftChild: BinaryNode?
19
19
var rightChild: BinaryNode?
@@ -79,7 +79,7 @@ class BinaryNodeCoder {
79
79
private var nilNode: String { return " X" }
80
80
81
81
// 4
82
- func encode <T : Encodable >(_ node : BinaryNode<T>) -> String {
82
+ func encode <T >(_ node : BinaryNode<T>) -> String {
83
83
var str = " "
84
84
node.preOrderTraversal { data in
85
85
if let data = data {
@@ -128,13 +128,13 @@ class BinaryNodeCoder {
128
128
// ...
129
129
130
130
// 1
131
- func decode <T : Decodable >(_ string : String ) -> BinaryNode<T>? {
131
+ func decode <T >(_ string : String ) -> BinaryNode<T>? {
132
132
let components = encoded.lazy .split (separator : separator).reversed ().map (String .init )
133
133
return decode (from : components)
134
134
}
135
135
136
136
// 2
137
- private func decode (from array : inout [String ]) -> AVLNode <String >? {
137
+ private func decode (from array : inout [String ]) -> BinaryNode <String >? {
138
138
guard ! array.isEmpty else { return nil }
139
139
let value = array.removeLast ()
140
140
guard value != " \( nilNode ) " else { return nil }
You can’t perform that action at this time.
0 commit comments