Code Monkey home page Code Monkey logo

swiftstructures's Introduction

Swift Structures

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.

Audience

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.

Features

The project features code-level examples for the following items:

  • Linked Lists
  • Binary Search
  • Insertion Sort
  • Bubble Sort
  • Quick Sort
  • Merge Sort
  • Generics
  • Hash Tables
  • Binary Search Trees
  • Tree Balancing (Rotations)
  • Tries
  • Stacks & Queues
  • Graphs
  • Dijkstra's Shortest Path
  • Heaps & Heapsort Operations
  • Depth-First Search
  • Breath-First Search

I plan to write further additional examples of algorithms and all developers are welcome to follow the project through Github or online at www.waynewbishop.com/swift. As a collaborative open-source effort, I also welcome feedback and contribution from others.

Example

  /* graph traversal - breadth first search */
  
  func traverseGraphBFS(startingv: Vertex) {
    
        //establish a new queue
        var graphQueue: Queue<Vertex> = Queue<Vertex>()
    
    
        //queue a starting vertex
        graphQueue.enQueue(startingv)
    
        while(!graphQueue.isEmpty()) {
            
            //traverse the next queued vertex
            var vitem = graphQueue.deQueue() as Vertex!
            
            //add unvisited vertices to the queue
            for e in vitem.neighbors {
                if e.neighbor.visited == false {
                    println("adding vertex: \(e.neighbor.key!) to queue..")
                    graphQueue.enQueue(e.neighbor)
                }
            }
            
            vitem.visited = true
            println("traversed vertex: \(vitem.key!)..")
            
        } //end while
    
        println("graph traversal complete..")
        
    
    } //end function

Getting Started

Swift Structures has been optimized for Xcode 6.3 (e.g., Swift 1.2) 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

Usage

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.

Branches

Other Projects

  • EKAlgorithms - A set of computer exercises implemented in Objective-C
  • Algorithms - A playground for common questions implemented in Ruby

Questions

Have a question? Feel free to contact me on Twitter or online.

swiftstructures's People

Contributors

waynewbishop avatar jokigenki avatar voidet avatar arslanbilal avatar blakemerryman avatar hotogwc avatar

Watchers

 avatar Andy Bennett avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.