language: C++ 4.7.2 (gcc-4.7.2)
date: 557 days 12 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
 
int main() {
  int array[] = {5,4,3,2,1};
 
  int key ;
  int t;//for future purpose
  int compcount = 0;//to keep track of comparisons
  for (int j = 1; j<sizeof(array)/sizeof(array[0]);j++)
  {
    key = array[j];//assign to second element initially
    t = j-1;//assign to first element initially
    while (j > 0 && array[t]>key)
    {
      array[t+1] = array[t];//moving array if bigger than next element
      t = t-1;
      compcount++;
    }
    array[t+1] = key;
  }
  for(int i = 0; i<5; i++)
    std::cout << array[i] << std::endl;
}
prog.cpp: In function ‘int main()’:
prog.cpp:9: warning: comparison between signed and unsigned integer expressions