One more time. This time I loaded the file in UltraEdit and saved it in
ANSI/ASCII code DOS format.
--
//---------------------------START OF C
CODE---------------------------------------
#include <string.h>
#include <memory.h>
#pragma hdrstop
//------------------------------------------------------------------------------------
typedef struct {
int len;
int node[];
}heap;
//----------------------------------------------------------------------------------------
int fLeft(int i){return (i << 1) + 1;}
//----------------------------------------------------------------------------------------
void Swap(int *i, int *j) {
int k = *j;
*j = *i;
*i = k;
}
//----------------------------------------------------------------------------------------
void Fix_heap(heap *hp, int i) {
int m = fLeft(i);
if (m < hp->len){
int h = m + 1;
if (h < hp->len && hp->node[h] > hp->node[m]) m = h;
if (hp->node[m] > hp->node[i]) {
Swap(hp->node+i, hp->node+m);
Fix_heap(hp, m);
}
}
}
//---------------------------------------------------------------------------------------
int main(int argc, char *argv[]) {
int i;
int ary[]={9, 2, 10, 12, 7, 5, 8, 1, 3, 5};
heap *hp = (heap *) malloc(sizeof(int)*10); //9 elem. + len
memcpy(hp, ary, sizeof(ary));
Fix_heap(hp, 0);
for (i=0; i<hp->len; i++) printf(" %i", hp->node[i]);
getch();
return 0;
}
//---------------------------------------------------------------------------
"Judson McClendon" <judmc@[EMAIL PROTECTED]
> skrev i melding
news:4IjUi.7265$ho4.891@[EMAIL PROTECTED]
> "Anonymous" <r1a@[EMAIL PROTECTED]
> wrote:
>> The C code looks garbled in my news reader...
>
> The C source code is probably from a ?nix system with only a LF
character
> at the end of the line instead of CRLF. PowerBASIC Console Compiler
> installs program CRLF in the Samples folder, and it will fix the file.
Or
> search powerbasic.com for the file LF2CRLF.ZIP which contains such a
> program.
> --
> Judson McClendon judmc@[EMAIL PROTECTED]
(remove zero)
> Sun Valley Systems http://sunvaley.com
> "For God so loved the world that He gave His only begotten Son, that
> whoever believes in Him should not perish but have everlasting life."
>


|