Skip to content

Instantly share code, notes, and snippets.

View Roshankumar350's full-sized avatar
🎯
Focusing

Roshan Kumar Sah Roshankumar350

🎯
Focusing
View GitHub Profile
@Roshankumar350
Roshankumar350 / BubbleSort.swift
Created April 1, 2021 19:28
Sorting: Understanding Bubble Sort
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)
@Roshankumar350
Roshankumar350 / InsertionSort.swift
Created April 3, 2021 19:43
Insertion Sort with Swift
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]
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
class Solution {
func setZeroes(_ matrix: inout [[Int]]) {
if matrix.isEmpty {
return
}
struct Coordinate: Equatable, Hashable {
var row: Int
var column: Int