fork(1) download
  1. template <class T>
  2. void swap(T& a, T& b){
  3. T temp(a);
  4. a = b;
  5. b = temp;
  6. }
  7.  
  8. //Бинарный поиск
  9. int binsearch(int array[], int key, int size){
  10. int left = 0;
  11. int right = size;
  12. int mid;
  13.  
  14. if(size == 0) return -1;
  15.  
  16. while (left <= right){
  17. mid = left + (right - left) / 2;
  18. if(key < array[mid])
  19. right = mid - 1;
  20. else if(key > array[mid])
  21. left = mid + 1;
  22. else return mid;
  23. }
  24. return -1;
  25. }
  26.  
  27. //Сортировка бинарными вставками
  28. void binsort(int array[], int size){
  29. int j, k, m;
  30. for(int i = 0; i < size; i++){
  31. j = i - 1;
  32. k = binsearch(array, array[i], size);
  33. for(int m = j; m >= k; m--)
  34. swap(array[m], array[m+1]);
  35. }
  36. }
  37.  
  38. //Генерация случайной последовательности
  39. void genRandSeq(int *array){
  40. std::srand(std::time(0));
  41. for(int i = 0; i < SIZE; i++)
  42. array[i] = std::rand();
  43. }
  44.  
  45. //Функция main
  46. int main(){
  47. int seq[SIZE];
  48. genRandSeq(seq);
  49.  
  50. binsort(seq, SIZE);
  51.  
  52. for(int i = 0; i < SIZE; i++)
  53. std::cout << seq[i] << " ";
  54. std::cout << std::endl;
  55.  
  56. int pause;
  57. std::cin >> pause;
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void genRandSeq(int*)':
prog.cpp:40:5: error: 'srand' is not a member of 'std'
     std::srand(std::time(0));
     ^
prog.cpp:40:16: error: 'time' is not a member of 'std'
     std::srand(std::time(0));
                ^
prog.cpp:41:24: error: 'SIZE' was not declared in this scope
     for(int i = 0; i < SIZE; i++)
                        ^
prog.cpp:42:20: error: 'rand' is not a member of 'std'
         array[i] = std::rand();
                    ^
prog.cpp: In function 'int main()':
prog.cpp:47:13: error: 'SIZE' was not declared in this scope
     int seq[SIZE];
             ^
prog.cpp:48:16: error: 'seq' was not declared in this scope
     genRandSeq(seq);
                ^
prog.cpp:53:9: error: 'cout' is not a member of 'std'
         std::cout << seq[i] << " ";
         ^
prog.cpp:54:5: error: 'cout' is not a member of 'std'
     std::cout << std::endl;
     ^
prog.cpp:54:18: error: 'endl' is not a member of 'std'
     std::cout << std::endl;
                  ^
prog.cpp:57:5: error: 'cin' is not a member of 'std'
     std::cin >> pause;
     ^
stdout
Standard output is empty