Skip to content

Instantly share code, notes, and snippets.

View kalub92's full-sized avatar

Caleb Stultz kalub92

View GitHub Profile
import Foundation
struct MinHeap {
var items: [Int] = []
//Get Index
private func getLeftChildIndex(_ parentIndex: Int) -> Int {
return 2 * parentIndex + 1
}
private func getRightChildIndex(_ parentIndex: Int) -> Int {
import Foundation
struct Stack {
private var items: [String] = []
}
import Foundation
struct Stack {
private var items: [String] = []
func peek() -> String {
guard let topElement = items.first else { fatalError("This stack is empty.") }
return topElement
}
}
import Foundation
struct Stack {
private var items: [String] = []
func peek() -> String {
guard let topElement = items.first else { fatalError("This stack is empty.") }
return topElement
}
import Foundation
struct Stack {
private var items: [String] = []
func peek() -> String {
guard let topElement = items.first else { fatalError("This stack is empty.") }
return topElement
}
var nameStack = Stack()
nameStack.push("Caleb")
nameStack.push("Charles")
nameStack.push("Tina")
print(nameStack)
extension Stack: CustomStringConvertible {
var description: String {
let topDivider = "---Stack---\n"
let bottomDivider = "\n-----------\n"
let stackElements = array.joined(separator: "\n")
return topDivider + stackElements + bottomDivider
}
}
import Foundation
struct Stack {
private var items: [String] = []
func peek() -> String {
guard let topElement = items.first else { fatalError("This stack is empty.") }
return topElement
}
@kalub92
kalub92 / SearchVC.swift
Created October 17, 2018 23:19
A search ViewController from a meal planning app I'm working on in my spare time.
//
// SearchVC.swift
// Meals
//
// Created by Caleb Stultz on 9/26/18.
// Copyright © 2018 Caleb Stultz. All rights reserved.
//
/*
Code is from a collaborative meal planning app I'm building. This ViewController allows a user to enter an ingredient as a search query into a UISearchBar instance and search for recipes with that ingredient present. Each UITableViewCell has an image of type CustomImageView that allows for synchronous image caching/loading in the background.
@kalub92
kalub92 / Codable-Example.swift
Last active October 25, 2018 18:09
Using SWAPI to test out Codable (Encodable/Decodable) for JSON in Swift 4.2
import Foundation
// Struct conforming to Codable and utilizing the CodingKeys enum to set up parameter to match how API data is organized.
struct Character: Codable {
let name: String
let height: String
let mass: String
let hairColor: String
enum CodingKeys: String, CodingKey {