diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6d13881f9..f60110b82 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -9,5 +9,6 @@ Maxime Dherbécourt Jess 3Jane Pen Pal Chinmaya Mahesh -Kjetil Johannessen Unlambder +Kjetil Johannessen +CDsigma \ No newline at end of file diff --git a/book.json b/book.json index bcbe11d3b..9d7122d7b 100644 --- a/book.json +++ b/book.json @@ -83,6 +83,10 @@ "lang": "go", "name": "Go" }, + { + "lang": "swift", + "name": "Swift" + }, { "lang": "racket", "name": "Racket" diff --git a/chapters/sorting_searching/bogo/bogo_sort.md b/chapters/sorting_searching/bogo/bogo_sort.md index a8efb5bf3..ca5c77516 100644 --- a/chapters/sorting_searching/bogo/bogo_sort.md +++ b/chapters/sorting_searching/bogo/bogo_sort.md @@ -35,6 +35,8 @@ In code, it looks something like this: [import, lang:"c_cpp"](code/c++/bogosort.cpp) {% sample lang="rs" %} [import, lang:"rust"](code/rust/bogosort.rs) +{% sample lang="swift" %} +[import, lang:"swift"](code/swift/bogosort.swift) {% endmethod %} That's it. diff --git a/chapters/sorting_searching/bogo/code/swift/bogosort.swift b/chapters/sorting_searching/bogo/code/swift/bogosort.swift new file mode 100644 index 000000000..4db91083c --- /dev/null +++ b/chapters/sorting_searching/bogo/code/swift/bogosort.swift @@ -0,0 +1,39 @@ +import Foundation + + +func isSorted(inputArray: [Int]) -> Bool { + + for i in 0.. inputArray[i+1] { + return false + } + } + + return true +} + + + +func shuffle(inputArray: inout [Int]) -> [Int] { + + var shuffledArray = [Int]() + + for _ in 0.. [Int] { + + while(!isSorted(inputArray: sortArray)) { + sortArray = shuffle(inputArray: &sortArray) + } + + return sortArray +}