Skip to content

Instantly share code, notes, and snippets.

View Keshavkumar96's full-sized avatar

keshavkumar A C Keshavkumar96

View GitHub Profile
@Keshavkumar96
Keshavkumar96 / InsertionSort.swift
Last active August 1, 2023 10:29
Insertion Sort in swift
import Foundation
/// Insertion sort is a sorting algorithm that places an unsorted element at its suitable place in each iteration.
///
/// 1. How it works
/// Insertion sort works similarly as we sort cards in our hand in a card game.
/// We assume that the first card is already sorted then, we select an unsorted card.
/// If the unsorted card is greater than the card in hand, it is placed on the right otherwise, to the left.
/// In the same way, other unsorted cards are taken and put in their right place.
///
@Keshavkumar96
Keshavkumar96 / CountingSort.swift
Last active August 1, 2023 10:42
Counting sort algorithm implementation in swift
import Foundation
/// Counting Sort - Not a comparison Sort.
/// Unlike other sorting algorithims which sorts by comparing each element.
///
/// 1. How it works
/// This algorthm sorts the elements of an array by counting the number of occurrences of each unique element in the array.
/// This algo can be used to sort an array of recurring non-negative integers
/// This algo can be used when maximum value 'K' is not very large than total count 'N', like, n^2.
///
@Keshavkumar96
Keshavkumar96 / CircularLinkedList.swift
Created March 24, 2023 17:13
Circular linked list implementation in swift
//
// CyclicLinkedList.swift
//
// Created by keshavkumar A C on 09/03/23.
//
import Foundation
class Node<T: Equatable>: Equatable {
var data: T
@Keshavkumar96
Keshavkumar96 / DoublyLinkedList.swift
Last active March 24, 2023 17:04
Doubly Linked List implementation in swift
//
// DoublyLinkedList.swift
//
// Created by keshavkumar A C on 09/03/23.
//
import Foundation
/// Ref: https://medium.com/@sarinyaswift/doubly-linked-lists-swift-4-ae3cf8a5b975
@Keshavkumar96
Keshavkumar96 / SinglyLinkedList.swift
Last active March 21, 2023 01:54
Singly Linked list in swift language
//
// SinglyLinkedList.swift
//
import Foundation
class Node<T: Equatable>: Equatable {
var data: T
var next: Node<T>? = nil
weak var prev: Node<T>? = nil