This project provides a framework for commonly used data structures and algorithms written in a new iOS development language called Swift. While details of many algorithms exists on Wikipedia, these implementations are often written as pseudocode, or are expressed in C or C++. With Swift now officially released, its general syntax should be familiar enough for most programmers to understand.
As a developer, you should already be familiar with the basics of programming. Beyond algorithms, this project also aims to provide an alternative for learning the basics of Swift. This includes implementations of many Swift-specific features such as optionals, extensions and generics. Beyond Swift, audiences should be familiar with Singleton and Factory design patterns along with sets, arrays and dictionaries.
The project features code-level examples for the following items:
- Linked Lists
- Binary Search
- Insertion Sort
- Bubble Sort
- Selection Sort
- Quick Sort
- Merge Sort
- Generics
- Closures
- Hash Tables
- Bloom Filters
- Binary Search Trees
- Tree Balancing (Rotations)
- Tries
- Stacks & Queues
- Graphs
- Dijkstra's Shortest Path
- Heaps & Heapsort Operations
- Depth-First Search
- Breadth-First Search
Available in print or pdf format, The Swift Algorithms Book features code and color illustrations that will benefit students and professionals. As a collaborative open-source effort, I also welcome feedback and contribution from others.
/* graph traversal - breadth first search */
func traverse(startingv: Vertex) {
//establish a new queue
let graphQueue: Queue<Vertex> = Queue<Vertex>()
//queue a starting vertex
graphQueue.enQueue(startingv)
while !graphQueue.isEmpty() {
//traverse the next queued vertex
let vitem = graphQueue.deQueue() as Vertex!
//add unvisited vertices to the queue
for e in vitem.neighbors {
if e.neighbor.visited == false {
print("adding vertex: \(e.neighbor.key!) to queue..")
graphQueue.enQueue(e.neighbor)
}
}
vitem.visited = true
print("traversed vertex: \(vitem.key!)..")
} //end while
print("graph traversal complete..")
} //end function
Swift Structures has been optimized for Xcode 7.0 GM Seed (e.g., Swift 2.0) or later. The directories are organized as follows:
- Source - Code for all Swift data structures and algorithms
- Example - An empty iOS single-view application template
- SwiftTests - Unit tests with XCTest Framework
Individuals are welcome to use the code with commercial and open-source projects. As a courtesy, please provide attribution to waynewbishop.com. For more information, review the complete license agreement.
- master - The production branch. Clone or fork this repository for the latest copy
- develop - The active development branch. <a href="https://help.github.com/articles/creating-a-pull-request" target=_blank">Pull requests should be directed to this branch
- EKAlgorithms - A set of computer exercises implemented in Objective-C
- Algorithms - A playground for common questions implemented in Ruby
Have a question? Feel free to contact me on Twitter or online.