language: C++ 4.7.2 (gcc-4.7.2)
date: 400 days 0 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<ctime>
#include<string>
using namespace std;
 
 
int quick_sort_help(string &text,int left, int right, int pivot){
 
 
  char val = text[pivot];
  char temp;
 
  //swap
 // temp =text[pivot];
  //text[pivot]= text[right];
  //text[right]=temp;
 
  //swap(&text[left],&text[right]);
 
  int l = left;
  int r = right;
 
  int i=left;
  while (i<=r)
  {
      while (text[i]<val)
          i++;
      while (text[right]>val)
          r--;
      if (i<=r)
      {
          temp=text[i];
          text[i]=text[r];
          text[r]=temp;
          i++;
          r--;
      }
  }
 
 
  return l;
     }
 
 
void quicksort(string &text,int left, int right){
 
      if (left < right){
 
          int pivot=(left+right)/2;
          int pivottwo = quick_sort_help(text, left, right, pivot);
          quicksort(text, left, pivottwo - 1);
          quicksort(text, pivottwo + 1, right);
          }
 }  
void quick_sort(string &text,int size){
              quicksort(text,0,size);}
 
 
int main()
{
 
    string text="this is a test string text,.,!";
    int size = text.length();
    float t1, t2;
    t1 = clock();
    quick_sort(text,size);
 
    t2=clock();
    cout<<text<<endl;
 
    return 0;
}