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
/* | |
* Copyright (C) 2014 skyfish.jy@gmail.com | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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
//: Playground - noun: a place where people can play | |
import Foundation | |
/** | |
Defining an extension for sorting the input array | |
where array elements conform to Comparable protocol | |
*/ | |
extension Array where Element: Comparable{ | |
mutating func quickSort() -> [Element]{ |
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
// Defining an extension for implementing Binary Search in the input array where | |
// array elements conform to Comparable protocol | |
extension Array where Element: Comparable{ | |
func binarySearch(_ value: Element) -> Int{ | |
return binSearch(0, self.count - 1, value) | |
} | |
func binSearch(_ start: Int, _ end: Int, _ value: Element) -> Int { | |
if start > end { |
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
import Foundation | |
import CoreLocation | |
public class Dijkstra { | |
public static func getShortestPath<T>(_ graph: Graph<T>, _ source: Node<T>, _ destination: Node<T>) -> [Node<T>] { | |
var frontier = [Path<T>]() | |
var possiblePaths = [Path<T>]() | |
var betterPath: Path<T>? |