-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort-Insertion.cpp
More file actions
45 lines (37 loc) · 767 Bytes
/
Sort-Insertion.cpp
File metadata and controls
45 lines (37 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
void sortArray(int arr[], int size)
{
int i,j,value;
for(i = 1 ; i<size ; i++)
{
value = arr[i];
j = i-1;
while(j>=0 && arr[j] > value)
{
arr[j+1] = arr[j];
j--;
}
arr[j+1] = value;
}
}
void printArray(int *ptrArray, int size)
{
for(int i=0 ; i<size ; i++)
{
cout << *ptrArray << " ";
*ptrArray++;
}
cout << endl;
}
int main()
{
int arr[] = {32,14,10,11,28};
int size = sizeof(arr)/sizeof(arr[0]);
cout << "Printing Array in Un-Sorted form : ";
printArray(arr,size);
sortArray(arr,size);
cout << "Printing Array in Sorted form : ";
printArray(arr,size);
return 0;
}