Giter Site home page Giter Site logo

ios-bubble-sort-swift-challenge's Introduction

Challenge

Your challenge today is to write a function bubbleSort(_:) that takes in an array of integers and sorts them using the bubble sort method. Bubble sort is the most basic sorting algorithm and can be described like this:

  • It compares the first element of an array with the second element. If the first element is greater than the second element then it swaps them.
  • Then it compares the second and third elements and swaps them if the second is larger. Then it compares the third and fourth elements and does the same. This continues and the the larger elements begin to "bubble" towards the end.
  • The loop then restarts and repeats this process until it makes a clean pass without performing any swaps.

Here's a cool visualization of Sorting Algorithms

Do not use the built-in sort() or sorted() methods.

Examples

bubbleSort([1, 3, 6, 2, 4, 5]) // returns [1, 2, 3, 4, 5, 6]

Stretch: What's the time complexity of your algorithm? Are there ways you can improve it? Could you write it to take a generic array instead of just ints?

Here are the overall instructions for code challenges. Before you begin, fork and clone this repo and work through your solution in the included starter playground file. When you're done, Please make sure to save and push all your work, and submit a Pull Request. Don't forget tag your TL so they can review your submission!

ios-bubble-sort-swift-challenge's People

Contributors

jkaunert avatar ladybeitel avatar paulsolt avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.