HACKIS - Hacking Internet Security
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Tuyệt Kỹ Đong Giai Chân Kinh (tuyệt Kỹ cua trai)
Heap  Sort EmptyThu Aug 23, 2012 5:38 am by Admin

» Tuyệt kỹ cua giai
Heap  Sort EmptyThu Aug 23, 2012 5:36 am by Admin

» NETCAT.........
Heap  Sort EmptyMon Aug 13, 2012 6:35 am by Admin

» Bảo mật CSDL bằng phương pháp mã hóa.
Heap  Sort EmptyTue Apr 17, 2012 10:04 pm by Admin

» Hàm mã hóa MD5 bằng JavaScript
Heap  Sort EmptyTue Apr 17, 2012 10:03 pm by Admin

» Giá của món quà
Heap  Sort EmptyFri Apr 13, 2012 6:01 am by Admin

» Sẽ chỉ yêu ai?
Heap  Sort EmptyFri Apr 13, 2012 6:01 am by Admin

» Cách đọc bảng chữ cái!
Heap  Sort EmptyThu Apr 12, 2012 10:37 pm by Admin

» Gắn trojan, keylog, virus vào website, forum
Heap  Sort EmptyTue Apr 10, 2012 1:14 am by Admin

Affiliates
free forum


Heap Sort

Go down

Heap  Sort Empty Heap Sort

Post  chipid1989 Thu May 12, 2011 11:30 pm

#include
#include
#define max 100
void NhapMang(int A[],int n) {
for(int i=0; i cout<<"nhap Phan tu thu A["< cin>>A[i];
}
}
void XuatMang(int A[],int n) {
cout< for(int i=0; i cout<}
void Swap(int &a,int &b) {
int temp = a;
a = b;
b = temp;
}
//hoan vi nut cha thu i phai lon hon nut con
void Heapify(int A[],int n, int i) {
int Left = 2*(i+1)-1;
int Right = 2*(i+1);
int Largest;
if(LeftA[i])
Largest = Left;
else
Largest = i;
if(RightA[Largest])
Largest = Right;
if(i!=Largest) {
Swap(A[i],A[Largest]);
Heapify(A,n,Largest);
}
}
//xay dung Heap sao cho moi nut cha luon lon hon nut con tren cay
void BuildHeap(int A[], int n) {
for(int i = n/2-1; i>=0; i--)
Heapify(A,n,i);
}
void HeapSort(int A[], int n) {
BuildHeap(A,n);
for(int i = n-1; i>0; i--){
Swap(A[0],A[i]);
Heapify(A,i,0);
}
}
void main() {
int A[max], n;
clrscr();
cout<<"Nhap so phan tu:";
cin>>n;
NhapMang(A,n);
cout<<"\nMang vua nhap la:";
XuatMang(A,n);
cout<<"\nSap xep theo Heap Sort:";
HeapSort(A,n);
XuatMang(A,n);
getch();
}

chipid1989

Tổng số bài gửi : 15
Join date : 2011-04-15

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum