- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI_sort.cpp
More file actions
Latest commit
32 lines (25 loc) · 569 Bytes
/
Copy pathI_sort.cpp
File metadata and controls
32 lines (25 loc) · 569 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
#include<iostream>
usingnamespacestd;
intmain()
{
int n = 4, i, j, temp;
int data[4] = {5,8,6,9};
for (int i = 0; i < n; i++)
{
j = i;
//ASC: Data[j] < Data[j-1]
//DESC: Data[j] > Data[j-1]
while(j > 0 && data[j] > data[j-1])
{
temp = data[j];
data[j] = data[j-1];
data[j-1] = temp;
}
}
cout << "In ascending order: " <<endl;
for (int i = 0; i < n; i++)
{
cout << data[i] <<endl;
}
return0;
}