C Lists
Hi, i'm revising my old self referential structures, basically a two way list. I'm at a point where i'm rewriting 'add' into 'append' and i'm thinking I can avoid returning a structure. However if I do and then try to access the last element it returns the one before, yet if I print the whole list then the last element is there... (why?)
main.c Code:
#include <stdio.h> Code:
#include <stdio.h> |
Yip, a copy typo!
This function now reads as: Code:
struct rclist *find_last_node(struct rclist *root) |
Code:
void rclist_append(char *s, struct rclist *root) |
It's surely not? It creates new, then points last to it!
|
Sorry that was incorrect but it does look funky.
Code:
void rclist_append(char *s, struct rclist *root) |
Yes, the error checking will be similar to 'add_node()' (in original e.g.).
Cheers |
Maybe it is just me or you can not see what i am saying. If I rename the nodes maybe it will help
Code:
void rclist_append(char *s, struct rclist *root) |
That's basically the same code as it is?
The append will also have an alias named 'push', and other functions such as pop, insert_at, remove_at, foreach(funcp), qsort. Maybe this doesn't fit the true name of a list, but since i'm self taught it's descriptive, what would you call it? P.S. This is very loosely based on the glist.h spec... |
Quote:
Quote:
Reread what you first said: Quote:
Code:
... |
Quote:
Also: Quote:
Code:
root->up = r; |
Quote:
Psuedo for what you want Code:
append at end(node*) Code:
void rclist_append_to_end(char *s, struct rclist *root) |
The only difference I can see between your code and mine is that you go down and I build up, which beyond semantics is irrelevant? I first used lists with gl transform lists (which are basically stacks) so I find it natural to build up and not build down. Or is there another difference that i'm missing?
|
All times are GMT -5. The time now is 08:15 PM. |