Search
Latest topics
Thuật toán QuickSort
Page 1 of 1
Thuật toán QuickSort
#include<iostream.h>
using namespace std;
void QuickSort(int a***91;100***93;, int left, int right);
int main(){
int a***91;100***93;,N,i;
cout<<"N=";cin>>N;
for(i=0;i<N;i++){
cin>>a***91;i***93;;
}
QuickSort(a,0,N-1);
for(i=0;i<N;i++){
cout<<a***91;i***93;<<" ";
}
cout<<endl;
system("pause");
return 0;
}
void QuickSort(int a***91;100***93;, int left, int right){
int i, j, x;
i = left;
j = right;
x = a***91;(left + right)/2***93;;
do {
while (a***91;i***93; < x) i++;
while (a***91;j***93; > x) j--;
if (i <= j) {
int t= a***91;i***93;;
a***91;i***93; = a***91;j***93;;
a***91;j***93; = t;
i++;
j--;
}
}while (i < j);
if (i < right) QuickSort(a, i, right);
if (j > left) QuickSort(a, left, j);
}
using namespace std;
void QuickSort(int a***91;100***93;, int left, int right);
int main(){
int a***91;100***93;,N,i;
cout<<"N=";cin>>N;
for(i=0;i<N;i++){
cin>>a***91;i***93;;
}
QuickSort(a,0,N-1);
for(i=0;i<N;i++){
cout<<a***91;i***93;<<" ";
}
cout<<endl;
system("pause");
return 0;
}
void QuickSort(int a***91;100***93;, int left, int right){
int i, j, x;
i = left;
j = right;
x = a***91;(left + right)/2***93;;
do {
while (a***91;i***93; < x) i++;
while (a***91;j***93; > x) j--;
if (i <= j) {
int t= a***91;i***93;;
a***91;i***93; = a***91;j***93;;
a***91;j***93; = t;
i++;
j--;
}
}while (i < j);
if (i < right) QuickSort(a, i, right);
if (j > left) QuickSort(a, left, j);
}
Similar topics
» Xét Tính Liên Thông Của Đồ Thị Sử Dụng Thuật Toán DFS và BFS
» Thuật toán Dijkstra
» Tìm Cây Phụ Tối Tiểu (Thuật Toán PRIM)
» Ứng dụng thuật toán Prim
» Thuật toán Kruskal tìm cây phủ tối tiểu
» Thuật toán Dijkstra
» Tìm Cây Phụ Tối Tiểu (Thuật Toán PRIM)
» Ứng dụng thuật toán Prim
» Thuật toán Kruskal tìm cây phủ tối tiểu
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Thu Aug 23, 2012 5:38 am by Admin
» Tuyệt kỹ cua giai
Thu Aug 23, 2012 5:36 am by Admin
» NETCAT.........
Mon Aug 13, 2012 6:35 am by Admin
» Bảo mật CSDL bằng phương pháp mã hóa.
Tue Apr 17, 2012 10:04 pm by Admin
» Hàm mã hóa MD5 bằng JavaScript
Tue Apr 17, 2012 10:03 pm by Admin
» Giá của món quà
Fri Apr 13, 2012 6:01 am by Admin
» Sẽ chỉ yêu ai?
Fri Apr 13, 2012 6:01 am by Admin
» Cách đọc bảng chữ cái!
Thu Apr 12, 2012 10:37 pm by Admin
» Gắn trojan, keylog, virus vào website, forum
Tue Apr 10, 2012 1:14 am by Admin