Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of insertion sort and name added to contributers.md #49

Merged
merged 1 commit into from
Oct 5, 2020
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
3 changes: 2 additions & 1 deletion Contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ <h1 class="animated rubberBand delay-4s">Contributors</h1>
<a class="box-item" href="https://github.com/rajneeshk94"><span>Rajneesh Khare</span></a>
<a class="box-item" href="https://github.com/milos5593"><span>Milos Vujinic</span></a>
<a class="box-item" href="https://github.com/senshiii"><span>Sayan Das</span></a>
<a class="box-item" href="https://github.com/Shagufta08"><span>Shagufta Iqbal</span></a>
<a class="box-item" href="https://github.com/Shagufta08"><span>Shagufta Iqbal</span></a>
<a class="box-item" href="https://github.com/ishgary"><span>Ishant Garg</span></a>
<!--
Add here
format : <a class="box-item" href="https://github.com/<your-username>"><span>Your Name</span></a>
Expand Down
34 changes: 34 additions & 0 deletions I-Sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include<iostream>
using namespace std;
void display(int *array, int size) {
for(int i = 0; i<size; i++)
cout << array[i] << " ";
cout << endl;
}
void insertionSort(int *array, int size) {
int key, j;
for(int i = 1; i<size; i++) {
key = array[i];//take value
j = i;
while(j > 0 && array[j-1]>key) {
array[j] = array[j-1];
j--;
}
array[j] = key; //insert in right place
}
}
int main() {
int n;
cout << "Enter the number of elements: ";
cin >> n;
int arr[n]; //create an array with given number of elements
cout << "Enter elements:" << endl;
for(int i = 0; i<n; i++) {
cin >> arr[i];
}
cout << "Array before Sorting: ";
display(arr, n);
insertionSort(arr, n);
cout << "Array after Sorting: ";
display(arr, n);
}