منتدى مدرسة الهاشمية الثانوية للبنين
heap sort in c++ 613623

عزيزي الزائر / عزيزتي الزائرة يرجي التكرم بتسجبل الدخول اذا كنت عضو معنا
او التسجيل ان لم تكن عضو وترغب في الانضمام الي اسرة المنتدي
سنتشرف بتسجيلك
شكرا heap sort in c++ 829894
ادارة المنتدي heap sort in c++ 103798
منتدى مدرسة الهاشمية الثانوية للبنين
heap sort in c++ 613623

عزيزي الزائر / عزيزتي الزائرة يرجي التكرم بتسجبل الدخول اذا كنت عضو معنا
او التسجيل ان لم تكن عضو وترغب في الانضمام الي اسرة المنتدي
سنتشرف بتسجيلك
شكرا heap sort in c++ 829894
ادارة المنتدي heap sort in c++ 103798
منتدى مدرسة الهاشمية الثانوية للبنين
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

منتدى مدرسة الهاشمية الثانوية للبنين

منتدى المدارس الاردنية و العربية و العالمية
 
الرئيسيةأحدث الصورالتسجيلدخول

 

 heap sort in c++

اذهب الى الأسفل 
2 مشترك
كاتب الموضوعرسالة
Abdulbasit
عبدالباسط غرايبة
عبدالباسط غرايبة
Abdulbasit


ذكر عدد الرسائل : 1668
الموقع : alhash-school.yolasite.com
العمر : 40
العمل/الترفيه : فني مختبرات
نقاط التميز مسابقات : 130
نقاط التميز : 16183
السٌّمعَة : 48
الاوسمة : heap sort in c++ 78c57f10
الاوسمة2 : وسام ادارة
احترام قوانين المنتدى :
heap sort in c++ Left_bar_bleue100 / 100100 / 100heap sort in c++ Right_bar_bleue

الدولة : heap sort in c++ Male_j11
تاريخ التسجيل : 28/11/2008

heap sort in c++ Empty
مُساهمةموضوع: heap sort in c++   heap sort in c++ I_icon_minitimeالإثنين يونيو 08, 2009 3:42 am

include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

class HeapSort
{
private:
int list[10];
protected:
void fixup(int, int, int);
void buildheap();
public:
void heapsort();
void store(int, int);
void printHeap();

};

void
HeapSort::fixup(int value, int start, int last)
{
int look;
bool done;
done = false;
look = 2*start+1;

while(look <= last && !done)
{
if(look < last)
{
if(list[look] < list[look+1])
look = look+1;
}
if(value > list[look])
done = true;
else
{
list[start] = list[look];
start = look;
look = 2*start+1;
}
}
}

void
HeapSort::buildheap()
{
int count;
int item;

for(count = (10/2)-1; count >= 0; count--)
{
item = list[count];
fixup(item, count, 9);
}
}

void
HeapSort::heapsort()
{
int count;
int item;

buildheap();
for(count = 9; count >= 1; count--)
{
//cout << list[count] << endl;
//cout <<"count " << count << endl;
item = list[count];
list[count] = list[0];
fixup(item, 0, count-1);
//cout << list[count] << endl;
}
}

void
HeapSort::store(int number, int place)
{
list[place] = number;
}

void
HeapSort::printHeap()
{
for(int i = 0; i < 10; i++)
cout << list[i] << endl;
}
int
main()
{
HeapSort heap1;
HeapSort heap2;

int x = 0;
int numberInput;

cout << "Enter ten numbers: " << endl;

while(x < 10)
{
cin >> numberInput;
http://heap1.heapsort();
//cout << x;
heap1.store(numberInput, x);
x++;
}

x = 0;

/*while(x < 10)
{
cin >> numberInput;
heap2.store(numberInput, x);
x++;
}
*/
heap1.heapsort();
heap1.printHeap();
http://heap2.printHeap();
// heap2.heapsort();
http://heap2.printHeap();

system("pause");
}#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

class HeapSort
{
private:
int list[10];
protected:
void fixup(int, int, int);
void buildheap();
public:
void heapsort();
void store(int, int);
void printHeap();

};

void
HeapSort::fixup(int value, int start, int last)
{
int look;
bool done;
done = false;
look = 2*start+1;

while(look <= last && !done)
{
if(look < last)
{
if(list[look] < list[look+1])
look = look+1;
}
if(value > list[look])
done = true;
else
{
list[start] = list[look];
start = look;
look = 2*start+1;
}
}
}

void
HeapSort::buildheap()
{
int count;
int item;

for(count = (10/2)-1; count >= 0; count--)
{
item = list[count];
fixup(item, count, 9);
}
}

void
HeapSort::heapsort()
{
int count;
int item;

buildheap();
for(count = 9; count >= 1; count--)
{
//cout << list[count] << endl;
//cout <<"count " << count << endl;
item = list[count];
list[count] = list[0];
fixup(item, 0, count-1);
//cout << list[count] << endl;
}
}

void
HeapSort::store(int number, int place)
{
list[place] = number;
}

void
HeapSort::printHeap()
{
for(int i = 0; i < 10; i++)
cout << list[i] << endl;
}
int
main()
{
HeapSort heap1;
HeapSort heap2;

int x = 0;
int numberInput;

cout << "Enter ten numbers: " << endl;

while(x < 10)
{
cin >> numberInput;
http://heap1.heapsort();
//cout << x;
heap1.store(numberInput, x);
x++;
}

x = 0;

/*while(x < 10)
{
cin >> numberInput;
heap2.store(numberInput, x);
x++;
}
*/
heap1.heapsort();
heap1.printHeap();
http://heap2.printHeap();
// heap2.heapsort();
http://heap2.printHeap();

system("pause");
}
الرجوع الى أعلى الصفحة اذهب الى الأسفل
https://alhash-school.yoo7.com
Abdulbasit
عبدالباسط غرايبة
عبدالباسط غرايبة
Abdulbasit


ذكر عدد الرسائل : 1668
الموقع : alhash-school.yolasite.com
العمر : 40
العمل/الترفيه : فني مختبرات
نقاط التميز مسابقات : 130
نقاط التميز : 16183
السٌّمعَة : 48
الاوسمة : heap sort in c++ 78c57f10
الاوسمة2 : وسام ادارة
احترام قوانين المنتدى :
heap sort in c++ Left_bar_bleue100 / 100100 / 100heap sort in c++ Right_bar_bleue

الدولة : heap sort in c++ Male_j11
تاريخ التسجيل : 28/11/2008

heap sort in c++ Empty
مُساهمةموضوع: رد: heap sort in c++   heap sort in c++ I_icon_minitimeالإثنين يونيو 08, 2009 3:46 am

#include <stdlib.h>
#include <stdio.h>
#define NUM_ITEMS 100
void heapSort(int numbers[], int array_size);
void siftDown(int numbers[], int root, int bottom);
int numbers[NUM_ITEMS];

int main()
{
int i;
//seed random number generator
srand(getpid());
//fill array with random integers
for (i = 0; i < NUM_ITEMS; i++)
numbers[i] = rand();
//perform heap sort on array
heapSort(numbers, NUM_ITEMS);
printf("Done with sort.\n");
for (i = 0; i < NUM_ITEMS; i++)
printf("%i\n", numbers[i]);
}

void heapSort(int numbers[], int array_size)
{
int i, temp;
for (i = (array_size / 2)-1; i >= 0; i--)
siftDown(numbers, i, array_size);
for (i = array_size-1; i >= 1; i--)
{
temp = numbers[0];
numbers[0] = numbers[i];
numbers[i] = temp;
siftDown(numbers, 0, i-1);
}
}

void siftDown(int numbers[], int root, int bottom)
{
int done, maxChild, temp;
done = 0;
while ((root*2 <= bottom) && (!done))
{
if (root*2 == bottom)
maxChild = root * 2;
else if (numbers[root * 2] > numbers[root * 2 + 1])
maxChild = root * 2;
else
maxChild = root * 2 + 1;
if (numbers[root] < numbers[maxChild])
{
temp = numbers[root];
numbers[root] = numbers[maxChild];
numbers[maxChild] = temp;
root = maxChild;
}
else
done = 1;
}
}
الرجوع الى أعلى الصفحة اذهب الى الأسفل
https://alhash-school.yoo7.com
zgol
عضو خبير
عضو خبير
zgol


ذكر عدد الرسائل : 557
الموقع : alhash-shool.yoo7.com
العمر : 28
العمل/الترفيه : طالب
المزاج : من الاخر
نقاط التميز : 7162
السٌّمعَة : 0
الاوسمة : heap sort in c++ 22
احترام قوانين المنتدى :
heap sort in c++ Left_bar_bleue100 / 100100 / 100heap sort in c++ Right_bar_bleue

الدولة : heap sort in c++ Male_j11
تاريخ التسجيل : 29/03/2009

heap sort in c++ Empty
مُساهمةموضوع: رد: heap sort in c++   heap sort in c++ I_icon_minitimeالإثنين يوليو 06, 2009 9:34 pm

heap sort in c++ 2816481c8ffdf41a3
الرجوع الى أعلى الصفحة اذهب الى الأسفل
 
heap sort in c++
الرجوع الى أعلى الصفحة 
صفحة 1 من اصل 1
 مواضيع مماثلة
-
» bubble sort

صلاحيات هذا المنتدى:لاتستطيع الرد على المواضيع في هذا المنتدى
منتدى مدرسة الهاشمية الثانوية للبنين :: الحاسوب و تكنولوجيا المعلومات-
انتقل الى: