fork download
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4. using namespace std;
  5. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  6. void print_array(int * arr, int l, int r, int q, int pivot) {
  7. for (int i = 0; i < q; i++) {
  8. if (i == r) {
  9. SetConsoleTextAttribute(hConsole, (WORD)(NULL | 4));
  10. cout << pivot << " ";
  11. SetConsoleTextAttribute(hConsole, (WORD)(NULL | 15));
  12. }
  13. else if (i == l) {
  14. SetConsoleTextAttribute(hConsole, (WORD)(NULL | 4));
  15. cout << arr[i] << " ";
  16. SetConsoleTextAttribute(hConsole, (WORD)(NULL | 15));
  17. }
  18. else {
  19. cout << arr[i] << " ";
  20. }
  21. }
  22. cout << endl;
  23.  
  24. }
  25. void quickSort(int *numbers, int left, int right, int q)
  26. {
  27. int pivot;
  28. int l_hold = left;
  29. int r_hold = right;
  30. pivot = numbers[left];
  31. while (left < right)
  32. {
  33. while ((numbers[right] >= pivot) && (left < right))
  34. right--;
  35. if (left != right)
  36. {
  37. numbers[left] = numbers[right];
  38. print_array(numbers, left, right, q, pivot);
  39. left++;
  40. }
  41. while ((numbers[left] <= pivot) && (left < right))
  42. left++;
  43. if (left != right)
  44. {
  45. numbers[right] = numbers[left];
  46. print_array(numbers, left, right, q, pivot);
  47.  
  48. right--;
  49. }
  50. }
  51. numbers[left] = pivot;
  52. pivot = left;
  53. left = l_hold;
  54. right = r_hold;
  55. if (left < pivot)
  56. quickSort(numbers, left, pivot - 1, q);
  57. if (right > pivot)
  58. quickSort(numbers, pivot + 1, right, q);
  59. }
  60. int main()
  61. {
  62. int quantity;
  63. cout << "enter the number of items: ";
  64. cin >> quantity;
  65. int* array;
  66. array = (int *)malloc(quantity * sizeof(int));
  67. cout << "Input the array elements:\n";
  68. for (int i = 0; i < quantity; i++)
  69. cin >> array[i];
  70. cout << "Source array: \n";
  71. for (int i = 0; i < quantity; i++)
  72. cout << array[i] << " ";
  73. cout << "\nInterpretation :" << endl;
  74. quickSort(array, 0, quantity - 1, quantity);
  75. cout << "\nSotred array:\n";
  76. for (int i = 0; i<quantity; i++)
  77. cout << array[i] << " ";
  78. cout << endl;
  79. system("pause");
  80. return 0;
  81. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:20: fatal error: stdafx.h: No such file or directory
 #include "stdafx.h"
                    ^
compilation terminated.
stdout
Standard output is empty