Swift, first introduced by Apple in 2014, has quickly become a cornerstone of iOS, macOS, watchOS, and tvOS development. With over a decade of evolution and refinement, Swift is now the primary language for building apps across Apple's ecosystem. It's used daily by developers worldwide to create everything from simple utility apps to complex, data-driven applications. This project provides a framework for commonly used data structures and algorithms written in Swift, offering practical implementations that go beyond the pseudocode or C/C++ examples often found on Wikipedia.
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, protocols and generics. Beyond Swift, audiences should be familiar with Singleton and Factory design patterns along with sets, arrays and dictionaries.
- Introduction
- Big O Notation
- Basic Sorting
- Advanced Sorting
- Generics
- Linked Lists
- Tries
- Stacks & Queues
- Binary Search Trees
- Tree Balancing
- Graphs
- Shortest Paths
- Heaps
- Traversals
- PageRank
- Blockchain Design
- Hash Tables
- Closures
- Control Structures
- Recursion
- Dynamic Programming
- Unit Testing
- Objective-C Primer
Now in its 5th edition and supporting the latest version of Swift, the Swift Algorithms Book features code and color illustrations that benefits students and professionals. As a collaborative open-source effort, I also welcome feedback and contribution from others.
//bfs traversal with inout closure function
func traverse(_ startingv: Vertex, formula: (_ node: inout 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
guard var vitem = graphQueue.deQueue() else {
break
}
//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)
}
}
//invoke formula
formula(&vitem)
} //end while
print("graph traversal complete..")
}
- bishop-algorithms-swift-package - Examples of commonly used algorithms and data structures in Swift Package format.
- bishop-app-runbuddy-swift - Plan your next run using Generative AI. Implemented in Swift.
- bishop-app-runbuddy-python - A machine learning model that recommends athletic clothing based on weather conditions.
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.
Have a question? Feel free to contact me online.