| -license:gpl heapsort lang:c | -license:gpl heapsort lang:c++ | -license:gpl heapsort lang:python |
| -license:gpl heapsort lang:java |
1: # Implementacion de Heapsort 2: # Todas las operaciones trabajan sobre listas 1-indexadas, salvo heapsort que sabe hacer la conversion 3: # El algoritmo se simplifica bastante por esa razon.
7: def heapsort(s,d): 8: a = secuAArreglo(s)
95: s2 = s[:] 96: heapsort(s2, d) 97:
117: def testHeapsort(): 118: import random
1: /*-------------------Start heapsort.c program-------------------*/ 2:
4: /* HEAPSORT */ 5: /* C Program Source */ 6: /* Heapsort program for variable sized arrays */
31: /* (1) UNIX Systems: */ 32: /* cc -DUNIX -O heapsort.c -o heapsort */ 33: /* cc -DUNIX heapsort.c -o heapsort */ 34: /****************************************************/
755: /*------ End of heapsort.c, say goodnight Vicki! (Sep 1992) ------*/
152: /* 153: * Heapsort -- Knuth, Vol. 3, page 145. Runs in O (N lg N), both average 154: * and worst. While heapsort is faster than the worst case of quicksort, 155: * the BSD quicksort does median selection so that the chance of finding 156: * a data set that will trigger the worst case is nonexistent. Heapsort's 157: * only advantage over quicksort is that it requires little additional memory.
159: int 160: heapsort(vbase, nmemb, size, compar) 161: void *vbase;
10: always greater then its children. 11: Current implementation of heapsort works by building heap out of an 12: array. To both maintain and implement shape property of heap, left
74: void heapsort(int *arr, int len) 75: {
95: print_array(arr, len); 96: heapsort(arr, len); 97: print_array(arr, len);
Google Home - Google Code - Discuss - Terms of Service - Help - Submit Your Code
©2010 Google - Privacy