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
func bubbleSort(forInput input: inout [Int]) { | |
let uptoEndIndex = input.count - 1 | |
for rearIndex in 0...uptoEndIndex { | |
var isAllSorted = true | |
for frontIndex in 0..<uptoEndIndex - rearIndex { | |
let currentRunning = frontIndex | |
let currentRunningAheadByOne = currentRunning + 1 | |
if input[currentRunning] > input[currentRunningAheadByOne] { | |
input.swapAt(currentRunning, currentRunningAheadByOne) |
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
func insertionSort(forInput input: inout [Int]) { | |
let uptoIndex = input.count - 1 | |
for rearIndex in 1...uptoIndex { | |
let rearValue = input[rearIndex] | |
var currentRunningIndex = rearIndex | |
while currentRunningIndex > 0 && input[currentRunningIndex - 1] > rearValue { | |
input[currentRunningIndex] = input[currentRunningIndex - 1] |
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
func selectionSort(forInput input: inout [Int]) { | |
let uptoIndex = input.count - 1 | |
var currentRunningMaximumNumber = input[0] | |
for rearIndex in 0..<uptoIndex { | |
// Assuming all are sorted | |
var isAllSorted = true | |
// Assuming rearIndex is minimum Index |
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
class Solution { | |
func setZeroes(_ matrix: inout [[Int]]) { | |
if matrix.isEmpty { | |
return | |
} | |
struct Coordinate: Equatable, Hashable { | |
var row: Int | |
var column: Int |
OlderNewer