This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PrefixTreeNode { | |
var data: String? | |
var weight: Int = 0 | |
var userWeight: Int? | |
var children: [PrefixTreeNode?] = Array(repeating: nil, count: 26) | |
func isEmpty() -> Bool { | |
return self.numberOfChildren() == 0 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecimalSearchTree{ | |
... | |
func search(number: String) -> Any?{ | |
// Return an item in this decimal search tree matching the given number, | |
// or nil if the given item is not found. | |
if let node = findNodeRecursive(number: number, node: self.root) { | |
return node.data | |
} else { | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecimalSearchTree{ | |
... | |
func insert(number: String, data: Any) { | |
// Insert the data in order of the number to the Decimal Search Tree | |
// recursively. | |
insertNodeRecursive(number: number, data: data, node: self.root) | |
} | |
func insertNodeRecursive(number: String, data: Any, node: DecimalTreeNode) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecimalSearchTree { | |
... | |
func contains(numbers: String) -> Bool{ | |
// Return true if this Decimal search tree contains a path at contains | |
// all the numbers iteratively. | |
var currentNode: DecimalTreeNode? = self.root | |
for character in numbers { | |
let index = Int(String(character)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecimalSearchTree{ | |
let root: DecimalTreeNode = DecimalTreeNode(data: "+") | |
var size: Int = 11 // number of nodes in the tree and the unuse node | |
var usedSize: Int = 0 // Number of nodes that are used | |
func isEmpty() -> Bool{ | |
// Return true if this decimal search tree is empty (has no nodes) | |
return self.root.isLeaf() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecimalTreeNode { | |
... | |
func height() -> Int{ | |
/*Return the height of the node (the number of edges on the longest | |
downward path from this node to a descendant leaf node).*/ | |
// Early break | |
if self.isLeaf(){ | |
return 0 | |
} | |
// Create a array of int to keep track of the height of each branch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecimalTreeNode { | |
... | |
func isLeaf() -> Bool { | |
// Check if the current node is a leaf or not | |
// Count the number of nil values in self.next | |
for item in self.next { | |
if item != nil { // There is a child of the node | |
return false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecimalTreeNode { | |
var data: Any? | |
var next: [DecimalTreeNode?] = [] | |
init(data: Any?) { | |
self.data = data | |
self.next = Array(repeating: nil, count: 10) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// New network call | |
fileprivate func callKeywordApi() { | |
NetworkManager().newGetKeywords { (result) in | |
switch result { | |
case .success(let keywords): | |
self.listOfKeywords = keywords | |
case .failure(let error): | |
print(error.localizedDescription) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate func callKeywordApi() { | |
NetworkManager().newGetKeywords { (result) in | |
switch result { | |
case .success(let keywords): | |
self.listOfKeywords = keywords | |
case .failure(let error): | |
print(error.localizedDescription) | |
} | |
} | |
} |
NewerOlder