Skip to content

Instantly share code, notes, and snippets.

View sarkarchandan's full-sized avatar

Chandan Sarkar sarkarchandan

  • Karlsruhe Institute of Technology
  • Karlsruhe, Germany
  • 17:07 (UTC +01:00)
View GitHub Profile
/*
* 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
@sarkarchandan
sarkarchandan / 1 Extension for Sort
Last active July 13, 2017 18:35
Find patching pairs of objects in an array that add up to a certain value
//: 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]{
@sarkarchandan
sarkarchandan / 1 Shortened Code
Last active July 16, 2017 18:27
Find patching pairs of objects in an array that add up to a certain value -- Shortened
// 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 {
@sarkarchandan
sarkarchandan / Dijkstra.swift
Created August 21, 2017 07:01
Dijkstra Implementation
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>?