-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.cpp
More file actions
59 lines (55 loc) · 1006 Bytes
/
sort.cpp
File metadata and controls
59 lines (55 loc) · 1006 Bytes
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
/****************
sort algorithm
creat by Dash
data : 2016-03-23
***************/
#include"iostream"
using namespace std;
string str;
void quicksort(int left ,int right){
if (left>right)
return;
int i,j;
int temp = str[left];
i = left;
j = right;
while(i != j){
while(str [j]>= temp && i < j )
j--;
while(str [i] <=temp && i< j )
i++;
if (i < j ){
int tem = str [j];
str [ j ] = str [i];
str [ i ] = tem;
}
}
str [ left ] = str [i ];
str [ i ] = temp;
quicksort(left,i-1);
quicksort(i+1,right);
}
string buble_sort(string str2){
for (int i = 0; i < str2.length(); ++i)
{
for (int j = i; j< str2.length(); ++j)
{
if (str2[i]<str2[j])
{
int t = str2 [i];
str2 [i] = str2 [j];
str2 [j] = t;
}
}
}
return str2;
}
int main(int argc, char const *argv[])
{
cout<<"please input the que with n:"<<endl;
cin >> str ;
quicksort(0,str.length()-1);
string str2 = buble_sort(str);
cout<<str2<<endl;
return 0;
}