I have an assignment in a programming class where we are traversing directory paths. I have two structs, one for Nodes and another for the List itself as such:
In this assignment we have to insert sort elements into a doubly linked list by their PATH alphabetically (which I can do). Next we have to sort the list by the LEVEL numerically in ascending order, lowest level to highest level. However, in between the LEVEL and the PATH is an ORDER integer. This number is not sorted, it just exists and is incremented based on specific rules that don't really matter for this explanation. My issue is that I cannot seem to be able to sort the LEVEL while still keeping the PATH that corresponds to that level with it.Code:struct Node { int level; int order; char *path; struct Node *next; struct Node *prev; }; struct List { struct Node *head; struct Node *tail; };
My linked list prints out like this LEVEL:ORDER:PATH
For example it would look something like this when sorted by the path:
1:0:/home/Downloads/folder1
2:0:/home/Downloads/folder1/README.txt
2:0:/home/Downloads/folder1/c3
3:0:/home/Downloads/folder1/c3/Simulator
4:0:/home/Downloads/folder1/c3/Simulator/d.c
3:0:/home/Downloads/folder1/c3/win32.c
2:0:/home/Downloads/folder1/c4
3:0:/home/Downloads/folder1/c4/Driver
3:0:/home/Downloads/folder1/c4/thrd-p.c
3:0:/home/Downloads/folder1/c4/thrd-w.c
Then sorting it by the LEVEL would look like this, where the ORDER is mixed but the LEVEL is ascending and the LEVEL stayed with its corresponding PATH:
1:1:/home/Downloads/folder1
2:1:/home/Downloads/folder1/README.txt
2:2:/home/Downloads/folder1/c3
2:3:/home/Downloads/folder1/c4
3:1:/home/Downloads/folder1/c3/Simulator
3:2:/home/Downloads/folder1/c3/win32.c
3:3:/home/Downloads/folder1/c4/Driver
3:4:/home/Downloads/folder1/c4/thrd-p.c
3:5:/home/Downloads/folder1/c4/thrd-w.c
4:1:/home/Downloads/folder1/c3/Simulator/d.c
Note: I would post my code but we are not allowed to do so to get help, I have posted as much as I am allowed to without being considered cheating. Any help is appreciated.