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
| 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. | |
| /// |
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
| 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. | |
| /// |
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
| // | |
| // CyclicLinkedList.swift | |
| // | |
| // Created by keshavkumar A C on 09/03/23. | |
| // | |
| import Foundation | |
| class Node<T: Equatable>: Equatable { | |
| var data: T |
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
| // | |
| // DoublyLinkedList.swift | |
| // | |
| // Created by keshavkumar A C on 09/03/23. | |
| // | |
| import Foundation | |
| /// Ref: https://medium.com/@sarinyaswift/doubly-linked-lists-swift-4-ae3cf8a5b975 |
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
| // | |
| // SinglyLinkedList.swift | |
| // | |
| import Foundation | |
| class Node<T: Equatable>: Equatable { | |
| var data: T | |
| var next: Node<T>? = nil | |
| weak var prev: Node<T>? = nil |