Skip to content

Instantly share code, notes, and snippets.

View Mintri1199's full-sized avatar
💻
Everything will be alright

Jackson Ho Mintri1199

💻
Everything will be alright
View GitHub Profile
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
}
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
}
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) {
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))
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()
}
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
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
}
}
@Mintri1199
Mintri1199 / DecimalTreeNode.swift
Created May 16, 2019 21:46
basic decimal tree node
class DecimalTreeNode {
var data: Any?
var next: [DecimalTreeNode?] = []
init(data: Any?) {
self.data = data
self.next = Array(repeating: nil, count: 10)
}
}
// 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)
}
}
fileprivate func callKeywordApi() {
NetworkManager().newGetKeywords { (result) in
switch result {
case .success(let keywords):
self.listOfKeywords = keywords
case .failure(let error):
print(error.localizedDescription)
}
}
}