C ++ insert sorting two-way insertion (comparison between loops and non-loops)
# Include
Using namespace std; void Grial (int a [], int n) {int I, j; I = j = 0; int B [n]; B [0] = a [I]; int k; for (k = 1; k
A [k]) {B [(J-1 + n) % n] = a [k]; j = (J-1 + n) % n;} else {I ++; int m; for (m = I; B M-1]> a [k]; m --) {B [(m + n) % n] = B [(m-1 + n) % n];} B [(m + n) % n] = a [k] ;}} I ++; k = 0; do {a [k ++] = B [(I) % n]; I ++;} while (I % n! = J);} int main () {int a [] = {10, 4, 2, 5, 88,1, 23}; Grial (a, 7); for (int I = 0; I <7; I ++) {cout <using namespace std; // 2-way insertion sorting. void Grial (int a [], int n) {int I; int j; int B [n]; // new space is used for sorting. B [0] = a [0]; I = 1; j = n-1; int k; for (k = 1; k
(N-j )? 1:-1; // compare the length on the left with the length on the right. If the left is large, flag 1 and else-1. if (a [k]> B [I-1]) {B [I] = a [k]; I ++;} else if (a [k]
B [m + 1]) B [m] = B [m + 1]; else {B [m] = a [k]; break ;}} j --;} else {int m; for (m = I; B M-1]> a [k] & m> 0; m --) {B [m] = M-1];} B [m] = a [k]; I ++ ;}} j = I; k = 0; do {a [k ++] = B [(I + n) % n]; I ++;} while (I % n )! = J);} int main () {int a [] = {, 10, 8,-1}; Grial (a, 10 ); for (int I = 0; I <10; I ++) {cout <