Commit 90cb710b authored by Ilya Prokhorov's avatar Ilya Prokhorov

Insertion sort added

parent 6ec0ba5f
var wordsList = ["zabbi","e","b","d","c","xyrax","aaa"]
print(wordsList)
for i in 0..<wordsList.count {
let word = wordsList[i]
print("---\nword: \(word)\n")
for y in (0..<i).reversed() {
let reversedItem = wordsList[y]
print("y: \(y)")
print("reversedItem: \(reversedItem)")
if word < reversedItem {
let removeIndex = y + 1
let insertIndex = y
print("remove at: \(removeIndex)")
print("insert at: \(insertIndex)")
print(wordsList)
wordsList.remove(at: removeIndex)
wordsList.insert(word, at: insertIndex)
print(wordsList)
}
else {
break
}
print(".")
}
}
print(wordsList)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment