#include <stdlib.h>
#include <stdio.h>
#define uint unsigned int
typedef int (*compare_func)(int, int);
void heap_sort(int This[], compare_func func_pointer, uint len)
{
/* heap sort */
uint half;
uint parents;
if (len <= 1)
return;
half = len >> 1;
for (parents = half; parents >= 1; --parents)
{
int tmp;
int level = 0;
uint child;
child = parents;
/* bottom-up downheap */
/* leaf-search for largest child path */
while (child <= half)
{
++level;
child += child;
if ((child < len) &&
((*func_pointer)(This[child], This[child - 1]) > 0))
++child;
}
/* bottom-up-search for rotation point */
tmp = This[parents - 1];
for (;;)
{
if (parents child)
break;
if ((*func_pointer)(tmp, This[child - 1]) <= 0)
break;
child >>= 1;
--level;
}
/* rotate nodes from parents to rotation point */
for (;level > 0; --level)
{
This[(child >> level) - 1] =
This[(child >> (level - 1)) - 1];
}
This[child - 1] = tmp;
} while (--len >= 1);
}
#define ARRAY_SIZE 250000
int my_array[ARRAY_SIZE];
void init()
{
int indx;
for (indx=0; indx < ARRAY_SIZE; ++indx)
{
my_array[indx] = rand();
}
}
int cmpfun(int a, int b)
{
if (a > b)
return 1;
else if (a < b)
return -1;
else
return 0;
}
int main()
{
int indx;
init();
heap_sort(my_array, cmpfun, ARRAY_SIZE);
for (indx=1; indx < ARRAY_SIZE; ++indx)
{
if (my_array[indx - 1] > my_array[indx])
{
printf("bad sort\n");
return(1);
}
}
return(0);
}
types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort
using doublelinked list insertion sort in c language
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
A C program is a computer program written using the C programming language.
C language is not a program, and it isn't an object-oriented language either.
to implement operations on binary heap in c
123
types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort
what are the parts of C language program
using doublelinked list insertion sort in c language
David Spuler has written: 'Comprehensive C' -- subject(s): C (Computer program language) 'C++ and C efficiency' -- subject(s): C++ (Computer program language), C (Computer program language)
find the program in c-pgms.blogspot.com
c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.
Conor Sexton has written: 'Newnes C++ pocket book' -- subject(s): C (Computer program language), C++ (Computer program language) 'C pocket book' -- subject(s): C (Computer program language) 'Y2K7'
A C program is a computer program written using the C programming language.
Steve Schustack has written: 'C for fun and profit' -- subject(s): C (Computer program language) 'Variations in C' -- subject(s): C (Computer program language) 'C for fun and profit' -- subject(s): C (Computer program language) 'Variations In C Edition'
The c language is as secure or as insecure as the programmer makes it. Security is not in the language; it is in the design of the program.