Re: Naming curiosity
- From: maverik <maverik.mail@xxxxxxxxx>
- Date: Thu, 27 Nov 2008 06:59:25 -0800 (PST)
On Nov 27, 5:40 pm, "Lorenzo Villari" <vll...@xxxxxxxx> wrote:
If I define a linked list this way
typedef struct sList
{
void *head;
void *next;
void *prev;
} List;
so that
1) I don't use a recursive structure using pointers to the structure itself
but pointers to void or whatever
There are many definitions of a linked list. It's common that as
minimum linked list has links (pointers) to its nodes (one or more).
So usually it looks like:
struct sList {
struct sList *next;
struct sList *prev;
...
};
In your case it's difficult to say to what next and prev are point.
May be you should write a short comment that says that it is pointer
to previous/next/... element.
If fields next and prev in your structure points to the next/previous
element of the list then it is still a linked list.
2) I use head as the data item and as the head of the list as opposed to
have a separate data item
Can't say anything. At least you should comment this as others can
misunderstand the real purpose of the head field.
3) I don't have a separate variable to indicate the number of the items in
the list but I use a calculation with the
next and prev pointers
It is common case. Many implementations of the linked list don't have
a separate variable to indicate the number of the items.
is that still called a "linked list" or it's called by another name?
Difficult to say. If you use it as a linked list then it is still
linked list. Otherwise is not.
.
- References:
- Naming curiosity
- From: Lorenzo Villari
- Naming curiosity
- Prev by Date: Re: Naming curiosity
- Next by Date: 賺全世界的美金
- Previous by thread: Re: Naming curiosity
- Next by thread: Re: Naming curiosity
- Index(es):
Relevant Pages
|