Skip to content

Instantly share code, notes, and snippets.

extension BinaryTree {
func traverse() {
print("\nPRE-ORDER TRAVERSE")
self.preorder(self.rootNode)
print("\n\nIN-ORDER TRAVERSE")
self.inorder(self.rootNode)
print("\n\nPOST-ORDER TRAVERSE")
self.postorder(self.rootNode)
let tree = BinaryTree<String>()
tree.insert(element: "F")
tree.insert(element: "G")
tree.insert(element: "H")
tree.insert(element: "D")
tree.insert(element: "E")
tree.insert(element: "I")
tree.insert(element: "J")
extension BinaryTree {
func search(element: T) {
self.search(self.rootNode, element)
}
private func search(_ rootNode: TreeNode<T>?, _ element: T) {
guard let rootNode = rootNode else {
tree.search(element: "E")
tree.search(element: "N")
class TreeNode<T>: Comparable, CustomStringConvertible where T: Comparable, T: CustomStringConvertible {
static func <(lhs: TreeNode<T>, rhs: TreeNode<T>) -> Bool {
return lhs.data < rhs.data
}
static func ==(lhs: TreeNode<T>, rhs: TreeNode<T>) -> Bool {
return lhs.data == rhs.data
}
import Foundation
class Queue<T: CustomStringConvertible>: CustomStringConvertible {
fileprivate var array: [T] = []
func dequeue() -> T? {
let dequeueItem = self.array.removeFirst()
print("DEQUEUE ITEM : \(dequeueItem.description)")
extension BinaryTree {
func levelOrder() {
guard let node = self.rootNode else { return }
self.queue.enqueue(item: node)
while !self.queue.isEmpty {
guard let dequeueNode = self.queue.dequeue() else { break }
if let leftNode = dequeueNode.leftNode {
let tree = BinaryTree<Int>()
tree.insert(element: 50)
tree.insert(element: 40)
tree.insert(element: 60)
tree.insert(element: 30)
tree.insert(element: 70)
tree.insert(element: 25)
tree.insert(element: 35)

Note

Apple will reject apps that are using private url schemes (Ugh, Apple....) if they are pretty much obvius. Some apps are rejected and others are not, so, be aware of this issue before implementing any of those URL's in your app as a feature.

Updates

  • [UPDATE 4] iOS 10 update: apparently settings now can be reached using App-Pref instead of prefs
  • [UPDATE 3] For now you just can use url schemes to open your apps's settings with Swift 3.0 (Xcode 8). I'll keep you informed when OS preferences can be reached
  • [UPDATE 2] The openURL() method of UIApplication is now deprecated. You should use application(_:open:options:) instead
  • [UPDATE 1] Not yet tested in iOS 10. It will fail because of policies changes in URL scheme handling.
@Abhishek9634
Abhishek9634 / git_error_solution.md
Created April 16, 2018 07:21 — forked from johnsolk/git_error_solution.md
git error, fatal: HTTP request failed

Got this error message:


[ljcohen@dev-intel16 Porites_astreoites_larvae_salinity]$ git push origin master
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/ljcohen/Porites_astreoites_larvae_salinity.git/info/refs

fatal: HTTP request failed

Googled problem and found this: