#include <errno.h>
#include <string.h>
-struct file_with_size {
- char *filename;
- size_t size;
- struct file_with_size *next;
-};
-
size_t file_or_dir_size(char *name) {
DIR *dir;
struct dirent *dir_e;
return result;
}
+/**********************************************************************/
+
+struct file_with_size {
+ char *filename;
+ size_t size;
+ struct file_with_size *next;
+};
+
struct file_with_size *create(char *name, struct file_with_size *current) {
struct file_with_size *result;
result = malloc(sizeof(struct file_with_size));
return result;
}
+void destroy(struct file_with_size *node) {
+ struct file_with_size *next;
+ while(node) {
+ next = node->next;
+ free(node->filename);
+ free(node);
+ node = next;
+ }
+}
+
+/**********************************************************************/
+
+void print_sorted(struct file_with_size *root) {
+ struct file_with_size *node;
+ struct file_with_size **nodes;
+ int nb, n;
+
+ nb = 0;
+ for(node = root; node; node = node->next) {
+ nb++;
+ }
+
+ nodes = malloc(nb * sizeof(struct file_with_size *));
+
+ n = 0;
+ for(node = root; node; node = node->next) {
+ nodes[n++] = node;
+ }
+
+ for(n = 0; n < nb; n++) {
+ printf("%u %s\n", nodes[n]->size, nodes[n]->filename);
+ }
+
+ free(nodes);
+}
+
+/**********************************************************************/
+
int main(int argc, char **argv) {
int k;
struct file_with_size *root;
root = create(argv[k], root);
}
- while(root) {
- printf("%u %s\n",
- root->size,
- root->filename);
- root = root->next;
- }
+ print_sorted(root);
+
+ destroy(root);
exit(0);
}