fork download
  1. #include<iostream>
  2. #include<ctime>
  3. #include<string>
  4. using namespace std;
  5.  
  6.  
  7. int quick_sort_help(string &text,int left, int right, int pivot){
  8.  
  9.  
  10. char val = text[pivot];
  11. char temp;
  12.  
  13. //swap
  14. // temp =text[pivot];
  15. //text[pivot]= text[right];
  16. //text[right]=temp;
  17.  
  18. //swap(&text[left],&text[right]);
  19.  
  20. int l = left;
  21. int r = right;
  22.  
  23. int i=left;
  24. while (i<=r)
  25. {
  26. while (text[i]<val)
  27. i++;
  28. while (text[right]>val)
  29. r--;
  30. if (i<=r)
  31. {
  32. temp=text[i];
  33. text[i]=text[r];
  34. text[r]=temp;
  35. i++;
  36. r--;
  37. }
  38. }
  39.  
  40.  
  41. return l;
  42. }
  43.  
  44.  
  45. void quicksort(string &text,int left, int right){
  46.  
  47. if (left < right){
  48.  
  49. int pivot=(left+right)/2;
  50. int pivottwo = quick_sort_help(text, left, right, pivot);
  51. quicksort(text, left, pivottwo - 1);
  52. quicksort(text, pivottwo + 1, right);
  53. }
  54. }
  55. void quick_sort(string &text,int size){
  56. quicksort(text,0,size);}
  57.  
  58.  
  59. int main()
  60. {
  61.  
  62. string text="this is a test string text,.,!";
  63. int size = text.length();
  64. float t1, t2;
  65. t1 = clock();
  66. quick_sort(text,size);
  67.  
  68. t2=clock();
  69. cout<<text<<endl;
  70.  
  71. return 0;
  72. }
Time limit exceeded #stdin #stdout 5s 2852KB
stdin
Standard input is empty
stdout

Standard output is empty