Many sample implementations of algorithms found in textbooks or online are formatted in pseudocode, which by design uses indentation for block definition to conserve vertical space. Additionally, because they are often included in papers, journals and books where space is at a premium, they are written with an emphasis on being brief, with short variable and function names. This makes them difficult to read.
New programmers see this style of code while learning to program, and paradoxically end up thinking this is good practice. They then try to emulate this style, which results in code which is unnecessarily terse, difficult to read, and most importantly, difficult to maintain.
This is a collection of my implementations that are (hopefully) easier to read and learn from, as well as my own test of Cunningham's Law. They are in C, Obj-C, and C++ because everything important is written in C or C++.
Heapsort — Intruduction to Algorithms. Cormen, Leiserson, Rivest and Stein, MIT Press. (Obj-C)
Mergesort — Intruduction to Algorithms. Cormen, Leiserson, Rivest and Stein, MIT Press. (Obj-C)
Quicksort — Intruduction to Algorithms. Cormen, Leiserson, Rivest and Stein, MIT Press. (Obj-C)
Balance Brackets (C)
Balanced Split (Obj-C)
Number of Visible Nodes (C)
Reverse Operations (Obj-C)
Reverse Operations C (C)
Leetcode has a funny subculture. If you look at the solutions, you will see very often things like "solution in 4 lines of C" or "solution in two lines of python" and so on. Very reminiscent of the "Obfuscated C Code" contests from back in the day. I get that this is fun to do (and I'm also envious that this is a skill that I simply don't have) but these solutions are completely useless to learn how to code.
I've been going through the problems marked "Hard" and solving them, my solutions are in a mix of Objective-C and C++ depending on what I was doing at the time. These are hopefully easy to understand.
Leetcode № 2 (Medium) — Add two Numbers(C++)
Leetcode № 4 (Hard) — Median of Two Sorted Arrays (C++)
Leetcode № 7 (Medium) — Reverse Integer
Leetcode № 8 (Medium) — String to Integer
Leetcode № 23 (Hard) — Merge K Sorted Lists
Leetcode № 25 (Hard) — Reverse Nodes in k-Group
Leetcode № 30 (Hard) — Substring with concatenation of all words (C++)
Leetcode № 41 (Hard) — First Missing Positive (C++).
Leetcode № 42 (Hard) — Trapping Rain Water (C++).
Leetcode № 51 (Hard) — N-Queens (C++11).
Leetcode № 52 (Hard) — N-Queens II (C++11).
Leetcode № 60 (Hard) — Permutation Sequence (C++11,C++17).
Leetcode № 68 (Hard) — Text Justification (C++11,C++17).
Leetcode № 76 (Hard) — Minimum Window Substring(C++11,C++17).
Leetcode № 80 (Medium) — Remove duplicates from Sorted Array II
Leetcode № 84 (Hard) — Largest Rectangle in Histogram (C++11)
Leetcode № 85 (Hard) — Maximal Rectangle (C++)
Leetcode № 123 (Hard) — Best time to Buy and Sell Stock III (C++)
Leetcode № 135 (Hard) — Candy (C++)
Leetcode № 149 (Hard) — Max Points on a Line (C++)
Leetcode № 218 (Hard) — The Skyline Problem
Leetcode № 233 (Hard) — Number of Digit One (C++/Hard)
Leetcode № 695 (Medium) — Max Area of Island
Leetcode № 1923 (Hard) — Longest Common Subpath
Leetcode № 2104 (Medium) — Sum of Subarray Ranges
Leetcode № 2106 (Hard) — Maximum Fruits Harvested After at Most K Steps