projects
/
dus.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9dcd9cc
)
Finished the routine to print in size order.
author
Francois Fleuret
<francois@fleuret.org>
Wed, 24 Feb 2010 07:10:41 +0000
(08:10 +0100)
committer
Francois Fleuret
<francois@fleuret.org>
Wed, 24 Feb 2010 07:10:41 +0000
(08:10 +0100)
dus.c
patch
|
blob
|
history
diff --git
a/dus.c
b/dus.c
index
9f05071
..
536d607
100644
(file)
--- a/
dus.c
+++ b/
dus.c
@@
-100,6
+100,22
@@
void destroy(struct file_with_size *node) {
/**********************************************************************/
/**********************************************************************/
+int compare_files(const void *x1, const void *x2) {
+ const struct file_with_size **f1, **f2;
+
+ f1 = (const struct file_with_size **) x1;
+ f2 = (const struct file_with_size **) x2;
+
+ if((*f1)->size < (*f2)->size) {
+ return -1;
+ } else if((*f1)->size > (*f2)->size) {
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+
void print_sorted(struct file_with_size *root) {
struct file_with_size *node;
struct file_with_size **nodes;
void print_sorted(struct file_with_size *root) {
struct file_with_size *node;
struct file_with_size **nodes;
@@
-117,6
+133,8
@@
void print_sorted(struct file_with_size *root) {
nodes[n++] = node;
}
nodes[n++] = node;
}
+ qsort(nodes, nb, sizeof(struct file_with_size *), compare_files);
+
for(n = 0; n < nb; n++) {
printf("%u %s\n", nodes[n]->size, nodes[n]->filename);
}
for(n = 0; n < nb; n++) {
printf("%u %s\n", nodes[n]->size, nodes[n]->filename);
}