Code
1void SortByInsertion(int *tobeSorted,int n)
2{
3 for(int j=1;j<n;j++)
4 { int key=tobeSorted[j];
5 int i=j-1;
6 while((i>=0)&&(tobeSorted[i]>key))
7 {
8 tobeSorted[i+1]=tobeSorted[i];
9 i--;
10 }
11 tobeSorted[i+1]=key;
12 }
13}
1void SortByInsertion(int *tobeSorted,int n)
2{
3 for(int j=1;j<n;j++)
4 { int key=tobeSorted[j];
5 int i=j-1;
6 while((i>=0)&&(tobeSorted[i]>key))
7 {
8 tobeSorted[i+1]=tobeSorted[i];
9 i--;
10 }
11 tobeSorted[i+1]=key;
12 }
13}
Code
1 #include<iostream>
2 using namespace std;
3 int main()
4 { void SortByInsertion(int *tobeSorted,int n);
5 int a[6]={5,2,4,6,1,3};
6 for(int i=0;i<6;i++)
7 {
8 cout<<a[i]<<";";
9 }
10 cout<<endl;
11 SortByInsertion(a,6);
12 for(int i=0;i<6;i++)
13 {
14 cout<<a[i]<<";";
15
16 }
17 cout<<endl;
18 char f;
19 cin>>f;
20
21 }
1 #include<iostream>
2 using namespace std;
3 int main()
4 { void SortByInsertion(int *tobeSorted,int n);
5 int a[6]={5,2,4,6,1,3};
6 for(int i=0;i<6;i++)
7 {
8 cout<<a[i]<<";";
9 }
10 cout<<endl;
11 SortByInsertion(a,6);
12 for(int i=0;i<6;i++)
13 {
14 cout<<a[i]<<";";
15
16 }
17 cout<<endl;
18 char f;
19 cin>>f;
20
21 }