Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97866870
sortf.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jan 6, 23:17
Size
1 KB
Mime Type
text/x-c
Expires
Wed, Jan 8, 23:17 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23372807
Attached To
R1448 Lenstool-HPC
sortf.c
View Options
#include <stdlib.h>
//#define null 0
struct
arbre
{
double
N
;
struct
arbre
*
FG
;
struct
arbre
*
FD
;
};
static
struct
arbre
*
addf
(
double
M
,
struct
arbre
*
A
,
int
(
*
comp
)(
double
,
double
));
static
void
readf
(
struct
arbre
*
R
,
double
*
B
,
int
*
i
);
/*
* sort double array
*/
void
sortf
(
int
n
,
double
*
A
,
int
(
*
comp
)(
double
,
double
))
{
struct
arbre
*
racine
;
int
i
;
racine
=
NULL
;
for
(
i
=
0
;
i
<
n
;
i
++
)
racine
=
addf
(
A
[
i
],
racine
,
comp
);
i
=
0
;
readf
(
racine
,
A
,
&
i
);
}
/***************************************************************/
static
struct
arbre
*
addf
(
double
M
,
struct
arbre
*
A
,
int
(
*
comp
)(
double
,
double
))
{
if
(
A
==
NULL
)
{
A
=
(
struct
arbre
*
)
malloc
(
sizeof
(
struct
arbre
));
A
->
N
=
M
;
A
->
FG
=
A
->
FD
=
NULL
;
}
else
{
if
((
*
comp
)(
M
,
A
->
N
))
(
A
->
FG
)
=
addf
(
M
,
A
->
FG
,
comp
);
else
(
A
->
FD
)
=
addf
(
M
,
A
->
FD
,
comp
);
};
return
(
A
);
}
/***************************************************************/
static
void
readf
(
struct
arbre
*
R
,
double
*
B
,
int
*
i
)
{
if
(
R
!=
NULL
)
{
readf
(
R
->
FG
,
B
,
i
);
B
[(
*
i
)
++
]
=
R
->
N
;
readf
(
R
->
FD
,
B
,
i
);
}
}
/***************************************************************/
int
comp_asc
(
double
A
,
double
B
)
{
return
(
A
<=
B
);
}
/***************************************************************/
int
comp_desc
(
double
A
,
double
B
)
{
return
(
A
<=
B
);
}
Event Timeline
Log In to Comment