fork download
  1. /**
  2.   * insertion sort, vector
  3.   */
  4. void i_sort(vector<int> & data){
  5. for(int i = 0; i < data.size()-1; i++){
  6. // out of order element?
  7. if ( data[i] > data[i+1] ){
  8. // pull data[i+1] to its proper position.
  9. // the value needs to be stored.
  10. int insert_value = data[i+1];
  11. int insert_index = i;
  12. // stop at index 0 or at the correct spot.
  13. while( insert_index && data[insert_index] > insert_value ){
  14. // move up value in list to make room for insertion.
  15. data[insert_index+1] = data[insert_index];
  16. insert_index--;
  17. }
  18. data[insert_index+1] = data[insert_index];
  19. data[insert_index] = insert_value;
  20. }
  21. }
  22. }
  23.  
  24.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:13: error: variable or field ‘i_sort’ declared void
prog.cpp:4:13: error: ‘vector’ was not declared in this scope
prog.cpp:4:20: error: expected primary-expression before ‘int’
stdout
Standard output is empty