Skip to content

Instantly share code, notes, and snippets.

View thexande's full-sized avatar

Alexander Murphy thexande

  • Ibotta
  • Denver, CO, USA, Planet Earth
View GitHub Profile
@thexande
thexande / FrequencyElements.swift
Created September 3, 2018 22:35
Element Frequency: Find the values in an array with a given frequency
/// Find the values in an array with a given frequency
///
/// - Parameters:
/// - array: the array to search through
/// - k: the frequency value
/// - Returns: an array of values with the corresponding frequency
func frequency(for array: [Int], k: Int) -> [Int] {
var bucket: [[Int]] = []
var frequency: [Int:Int] = [:]
@thexande
thexande / RecursiveTreeTraversal.swift
Created September 4, 2018 02:23
A Recursive in order Binary Tree Traversal implementation
/// BinaryTree data structure for a recursive tree
///
/// - node: the root node
/// - empty: empty node
/// - value: The underlying data within the node
indirect enum BinaryTree<T> {
case node(BinaryTree<T>, T, BinaryTree<T>)
case empty
@thexande
thexande / moveZerosToFront.swift
Created September 4, 2018 02:28
Given an array, without using extra space, move all zeros to the end and no-zeros to the beginning.
//Given an array, without using extra space, move all zeros to the end and no-zeros to the beginning. The function should return the number of non-zeros.
/// move all zeros in the list to the front without using extra space or new arrays.
///
/// - Parameter list: list of Int
/// - Returns: number of zeros
public func moveZerosToFront(list: inout [Int]) -> (Int, [Int]) { //O(n)
var numOfZeros = 0
for i in 0..<list.count {
@thexande
thexande / SuperEnumerator.swift
Created September 23, 2018 21:36
A recursive data structure conforming to IteratorProtocol
final public class SuperEnumerator: IteratorProtocol {
public typealias Element = Any
private var item: Element?
private var hasReturnedLowestDimension = false

Privacy Policy

Alexander Murphy built the Algorithms and Data Structures app as an Open Source app. This SERVICE is provided by Alexander Murphy at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Algorithms and Data Structures unless otherwise defined in this Privacy Policy.

Privacy Policy

Alexander Murphy built the Block Viewer app as a Free app. This SERVICE is provided by Alexander Murphy at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Block Viewer unless otherwise defined in this Privacy Policy.

Privacy Policy

built the Bitcoin Maps app as a Free app. This SERVICE is provided by at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Bitcoin Maps unless otherwise defined in this Privacy Policy.

Privacy Policy

Alexander Murphy built the Coin Viewer app as a Free app. This SERVICE is provided by Alexander Murphy at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Coin Viewer unless otherwise defined in this Privacy Policy.

import Foundation
import CoreGraphics
import SDWebImage
final class ImageAspectRatioCache {
var aspectLookup: [URL:CGFloat] = [:]
func produceAspectRatios(for images: [URL], completion: (() -> Void)?) {
@thexande
thexande / Stack.swift
Created January 29, 2019 16:49
Swift Stack Implementation
struct Stack<T> {
private var stack: [T] = []
mutating func push(_ item: T) {
stack.append(item)
}
mutating func pop() -> T {
return stack.removeLast()