לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #2  
ישן 14-12-2010, 00:25
צלמית המשתמש של hellfrost
  hellfrost hellfrost אינו מחובר  
 
חבר מתאריך: 07.12.09
הודעות: 7,072
בתגובה להודעה מספר 1 שנכתבה על ידי figureskater שמתחילה ב "מיון ערמה ב c"

קוד PHP:
 #define length(a) 21
static int c[21];
static 
int heapsize 21;
static 
int countCopy 0;
static 
int countComp 0;

int parent();
int child();
void heapify();
void buildheap();
void heapsort();
int maxextract();
void printArray();
int main();

int parent(int i,int d){
    return (
i-1)/d+((i-1)%==:1);
}

int child(int iint j,int d){
    return (
d*(i-1)+j-1);
}

void heapify(int i,int d){
    if (
i>20)
    return;
    
printf("%d\n",i);
    
int largest i;
    
countCopy++;
    
int j,l,temp;
    for(
j=1;j<=d;j++){
        
child(i,j,d);
        
countCopy++;
        
countComp +=2;
        if(
l<20&& c[l]>c[largest]){
            
largest l;
            
countCopy++;
        }
        
printf("%d\n",largest);
    }
    
countComp++;
    if(
largest !=i){
        
temp c[i];
        
c[i]= c[largest];
        
c[largest] = temp;
        
countComp+=3;
    }
    
printf("3\n");
    
heapify(largest,d);


}

void buildheap(int d){
    
int i;
    for(
= (19)/+ ((19%d) == 1);>= 1;i--){
        
countCopy++;
        
countComp++;
        
heapify(i,d);
    }
}

void heapsort(int d){
    
buildheap(d);
    
int i;
    
int sorted[21];
    for(
i=1;i<=heapsizei++){
        
countCopy++;
        
countComp++;
        
sorted[21-i]= maxextract(d);
        
countCopy++;
    }
    
printArray(sorted);

}

int maxextract(int d){
    if(
heapsize<1)
    
puts("error");
    
int max c[1];
    
c[1] = c[heapsize];
    
heapsize--;
    
countCopy += 3;
    
heapify(1,d);
    return 
max;
}

void printArray(int b[]){
    
int i;
    for(
i=1;i<=20;i++)
    
printf("%d " ,b[i]);
    
puts("\n");
}


int  main(void){
    
int i,j,d;

    for(
2<= 5d++)
    for(
i=0;i<10;i++){
        for(
j=1;j<21;j++){
            
c[j] = rand()%11;
        }
        
printArray(c);
        
printf("d= %d number of i is %d number of j is %d number of copy is %d \n",dij-1,countCopy);
        
heapsort(d);

    }





אין לי כוח לעבור על זה...
אבל אלוהי כל הבאלגן....

נערך לאחרונה ע"י hellfrost בתאריך 14-12-2010 בשעה 00:29.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 13:00

הדף נוצר ב 0.10 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר