-
-
Notifications
You must be signed in to change notification settings - Fork 360
Added BogoSort in Swift 4.1 #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Butt4cak3
merged 17 commits into
algorithm-archivists:master
from
Wesley-Arrington:master
Jun 29, 2018
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f5ccae7
Added BogoSort in Swift 4.1
3e82fd1
Updated .md
090d5b7
Updated book.json
fa07e5e
Updating .md
b68abf2
Updated CONTRIBUTORS.md
Wesley-Arrington e4c61b1
Fixing Formatting
Wesley-Arrington 8450b8c
Merge branch 'master' into master
Wesley-Arrington ba208f7
Fixing formatting
Wesley-Arrington 2f1723b
Fixing Formating
Wesley-Arrington cae4e82
Fixed Brackets
Wesley-Arrington e4e82c3
Fixing Brackets
Wesley-Arrington a88b732
Merge branch 'master' into master
Wesley-Arrington f18feab
Updated File Name
Wesley-Arrington 8c3b742
Got rid of spaces in whitespace
Wesley-Arrington 0a0fc50
Renamed bogosort.swift file
Wesley-Arrington 414a7e8
Removing duplicate {% endmethod %}
Wesley-Arrington 9578b02
Merge branch 'master' of https://github.com/CDsigma/algorithm-archive
Wesley-Arrington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ Maxime Dherbécourt | |
Jess 3Jane | ||
Pen Pal | ||
Chinmaya Mahesh | ||
Kjetil Johannessen | ||
Unlambder | ||
Kjetil Johannessen | ||
CDsigma |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
|
||
|
||
func isSorted(inputArray: [Int]) -> Bool { | ||
|
||
for i in 0..<inputArray.count-1 { | ||
if inputArray[i] > inputArray[i+1] { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
|
||
|
||
func shuffle(inputArray: inout [Int]) -> [Int] { | ||
|
||
var shuffledArray = [Int]() | ||
|
||
for _ in 0..<inputArray.count { | ||
let rand = Int(arc4random_uniform(UInt32(inputArray.count))) | ||
shuffledArray.append(inputArray[rand]) | ||
inputArray.remove(at: rand) | ||
} | ||
|
||
return shuffledArray | ||
} | ||
|
||
|
||
|
||
func bogoSort(sortArray: inout [Int]) -> [Int] { | ||
|
||
while(!isSorted(inputArray: sortArray)) { | ||
sortArray = shuffle(inputArray: &sortArray) | ||
} | ||
|
||
return sortArray | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only supposed to be one
{% endmethod %}
statement at the end. You have to remove the one in line 38.