Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions README.md

This file was deleted.

139 changes: 139 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<div align="center">
<br>
<br>
<br>
<br>
<img width="400" height="270" src="https://cdn.jsdelivr.net/npm/@programming-languages-logos/cpp@0.0.2/cpp.svg">
<br>
<br>
<br>
<br>
<br>
<br>
<img src="https://cdn.abranhe.com/projects/algorithms/algorithms.svg" width="400px">
<br>
<br>
<p>All ▲lgorithms implemented in C++</p>
<a href="https://algorithms.abranhe.com"><img src="https://cdn.abranhe.com/projects/algorithms/badge.svg"></a>
<a href="https://github.com/abranhe/algorithms/blob/master/license"><img src="https://img.shields.io/github/license/abranhe/algorithms.svg" /></a>
<a href="https://cash.me/$abranhe"><img src="https://cdn.abranhe.com/badges/cash-me.svg"></a>
<a href="https://www.patreon.com/abranhe"><img src="https://cdn.abranhe.com/badges/patreon.svg" /></a>
<a href="https://paypal.me/abranhe/10"><img src="https://cdn.abranhe.com/badges/paypal.svg" /></a>
<br>
<br>
<a href="https://allalgorithms.com"><code>allalgorithms.com</code></a>
</div>


## Contents

- [Artificial Intelligence](#artificial-intelligence)
- [Backtracking](#backtracking)
- [Bit Manipulation](#bit-manipulation)
- [Cellular Automaton](#cellular-automaton)
- [Ciphers](#ciphers)
- [Computational Geometry](#computational-geometry)
- [Cryptography](#cryptography)
- [Data Structures](#data-structures)
- [Divide and conquer](#divide-and-conquer)
- [Dynamic Programming](#dynamic-programming)
- [Gaming Theory](#gaming-theory)
- [Graphs](#graphs)
- [Greedy Algorithms](#greedy-algorithms)
- [Math](#math)
- [Networking](#networking)
- [Numerical Analysis](#numerical-analysis)
- [Operating system](#operating-system)
- [Randomized Algorithms](#randomized-algorithms)
- [Searches](#searches)
- [Selections Algorithms](#selections-algorithms)
- [Sorting](#sorting)
- [Strings](#strings)
- [Online Challenges](#online-challenges)
- [Others](#others)

## Data Structures

- Queue
- [Circular Buffer](data-structures/queue/circular_buffer.cpp)
- [Queue](data-structures/queue/queue.cpp)
- Stack
- [Stack](data-structures/stack/stack.cpp)

## Dynamic Programming

- [Coin Change](dynamic-programming/coin_change.cpp)
- [Edit Distance](dynamic-programming/edit_distance.cpp)
- [Knapsack](dynamic-programming/knapsack.cpp)
- [Longest common subsequence](dynamic-programming/lcs.cpp)
- [Longest Path](dynamic-programming/longest_path.cpp)
- [Ways to Cover](dynamic-programming/ways_to_cover.cpp)

## Graphs

- [Bellman Ford](graphs/bellman_ford.cpp)
- [Breadth-first search](graphs/bfs.cpp)
- [Count Disconnected Components](graphs/count_disconnected_components.cpp)
- [Depth-first search](graphs/dfs.cpp)
- [Dijkstra](graphs/dijkstra.cpp)
- [Floyed Warshall](graphs/floyd_warshall.cpp)
- [Prims Adjacency List](graphs/prims_adjacency_list.cpp)

## Math

- [Collatz](math/collatz.cpp)
- [Euclids Greatest common divisor](math/euclids_gcd.cpp)
- [Factorial](math/factorial.cpp)
- [Greatest common divisor of array](math/gcd_of_array.cpp)
- [Least common multiple of array](math/lcm_of_array.cpp)
- [Lucky Numbers](math/lucky_numbers.cpp)
- [Modular Exponentiations](math/modular_exponentiations.cpp)
- [nth Fibonacci Number using Goldenratio](math/nth_fibonacci_using_goldenratio.cpp)

## Searches

- [Binary Search](searches/binary_search.cpp)
- [Jump Search](searches/jump_search.cpp)
- [Linear Search](searches/linear_search.cpp)
- [Ternary Search](searches/ternary_search.cpp)

## Sorting

- [Bubble Sort](sorting/bubble_sort.cpp)
- [Heap Sort](sorting/heap_sort.cpp)
- [Heap Sort without vectors](sorting/heap_sort_without_vectors.cpp)
- [Insertion Sort](sorting/insertion_sort.cpp)
- [Merge Sort](sorting/merge_sort.cpp)
- [Quick Sort](sorting/quick_sort.cpp)
- [Selection Sort](sorting/selection_sort.cpp)
- [Sort Vector](sorting/sort_vector.cpp)
- [Tree Sort](sorting/tree_sort.cpp)

## Strings

- [Anagram Check](strings/anagram_check.cpp)
- [Lexicographic Ranking](strings/lexicographic_ranking.cpp)
- [Longest Palindrome Subset](strings/longest_palindrome_subset.cpp)
- [Naive Search](strings/naive_search.cpp)
- [Permutations of string](strings/permutations_of_string.cpp)
- [Print duplicate string](strings/print_duplicate_string.cpp)
- [Rabin Karp](strings/rabin_karp.cpp)
- [Remove Adjacent Duplicates](strings/remove_adjacent_duplicates.cpp)
- [Remove Duplicates](strings/remove_duplicates.cpp)
- [Reverse String](strings/reverse_string.cpp)

## License

This work is released under [MIT License](https://github.com/abranhe/algorithms/blob/master/liceense)

[![MIT IMG](https://cdn.abranhe.com/projects/algorithms/mit-license.png)](https://github.com/abranhe/algorithms/blob/master/license)

To the extent possible under law, [Carlos Abraham](https://go.abranhe.com/github) has waived all copyright and related or neighboring rights to this work.


<div align="center">
<a href="https://github.com/abranhe/algorithms">
<img src="https://cdn.abranhe.com/projects/algorithms/logo.svg" width="50px">
</a>
<br>
</div>
61 changes: 61 additions & 0 deletions sorting/shaker_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include<iostream>

using namespace std;

// A function to swap values using call by reference.
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

// A function implementing shaker sort.
void ShakerSort(int a[], int n)
{
int i, j, k;
for(i = 0; i < n;)
{
// First phase for ascending highest value to the highest unsorted index.
for(j = i+1; j < n; j++)
{
if(a[j] < a[j-1])
swap(&a[j], &a[j-1]);
}
// Decrementing highest index.
n--;

// Second phase for descending lowest value to the lowest unsorted index.
for(k = n-1; k > i; k--)
{
if(a[k] < a[k-1])
swap(&a[k], &a[k-1]);
}
// Incrementing lowest index.
i++;
}
}

int main()
{
int n, i;
cout<<"\nEnter the number of data element to be sorted: ";
cin>>n;

int arr[n];
for(i = 0; i < n; i++)
{
cout<<"Enter element "<<i+1<<": ";
cin>>arr[i];
}

ShakerSort(arr, n);

// Printing the sorted data.
cout<<"\nSorted Data ";
for (i = 0; i < n; i++)
cout<<"->"<<arr[i];

return 0;
}
48 changes: 48 additions & 0 deletions sorting/stooge_sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include<iostream>

using namespace std;

// A function implementing stooge sort.
void StoogeSort(int a[],int start, int end)
{
int temp;
// Further breaking the array if the Subpart's length is more than 2.
if(end-start+1 > 2)
{
temp = (end-start+1)/3;
StoogeSort(a, start, end-temp);
StoogeSort(a, start+temp, end);
StoogeSort(a, start, end-temp);
}

// swapping the element at start and end.
if(a[end] < a[start])
{
temp = a[start];
a[start] = a[end];
a[end] = temp;
}
}

int main()
{
int n, i;
cout<<"\nEnter the number of data element to be sorted: ";
cin>>n;

int arr[n];
for(i = 0; i < n; i++)
{
cout<<"Enter element "<<i+1<<": ";
cin>>arr[i];
}

StoogeSort(arr, 0, n-1);

// Printing the sorted data.
cout<<"\nSorted Data ";
for (i = 0; i < n; i++)
cout<<"->"<<arr[i];

return 0;
}
Loading