-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated file structure added more algos
- Loading branch information
1 parent
f6de42d
commit 1482724
Showing
26 changed files
with
61 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Insertion sort | ||
Can be remembered as deck of cards taken one by one | ||
*/ | ||
#include <stdio.h> | ||
|
||
void print_array(int a[], int n){ | ||
for(int i = 0; i<n; i++){ | ||
printf("%d ", a[i]); | ||
} | ||
} | ||
|
||
int main(){ | ||
|
||
int arr[10] = {9,6,5,0,3,4,1,2, 14,10}; //input array | ||
int key, j, i; | ||
for(i = 0; i < 10; i++){ | ||
key = arr[i]; | ||
j = i-1; | ||
while(j>=0 && key < arr[j]){ | ||
arr[j+1] = arr[j]; | ||
j--; | ||
} | ||
arr[j+1]=key; | ||
//j has been decremented so in the end will be at one less than the position desired, so adding one | ||
} | ||
|
||
printf("the sorted array is:\n"); | ||
print_array(arr,10); | ||
} | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.