Skip to content

Instantly share code, notes, and snippets.

View Rabishranjan08's full-sized avatar
🎯
Focusing

Rabish Ranjan Rabishranjan08

🎯
Focusing
View GitHub Profile
@Rabishranjan08
Rabishranjan08 / Sort.cpp
Created September 15, 2021 07:55
Algorithm to sort an array
#include<bits/stdc++.h>
using namespace std;
/*1.We are given with an input array which is supposed to be sorted in ascending order
2.We start with the first element and i=0 index and check if the element present at i+1 is greater then we swap the elements at index i and i+1.
3.If above is not the case, then no swapping will take place.
4.Now “ i ” gets incremented and the above 2 steps happen again until the array is exhausted.
5.We will ignore the last index as it is already sorted.
6.Now the largest element will be at the last index of the array.
7.Now we will again set i=0 and continue with the same steps that will eventually place second largest at second last place in the array. Now the last 2 indexes of the array are sorted.
*/