Re: Naming curiosity



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.

.



Relevant Pages

  • Re: Naming curiosity
    ... void *head; ... I don't use a recursive structure using pointers to the structure itself but pointers to void or whatever ... what do you mean by "head"? ... struct sList *prev; ...
    (comp.lang.c)
  • Re: Naming curiosity
    ... void *head; ... I don't use a recursive structure using pointers to the structure itself but pointers to void or whatever ... what do you mean by "head"? ... next and prev pointers ...
    (comp.lang.c)
  • Naming curiosity
    ... void *head; ... I don't use a recursive structure using pointers to the structure itself ... I use head as the data item and as the head of the list as opposed to ... next and prev pointers ...
    (comp.lang.c)
  • Re: Naming curiosity
    ... void *head; ... I don't use a recursive structure using pointers to the structure itself ... Sometimes the head is a data item and sometimes the head is a list ... (Most of the time I'm using linked lists, I don't have any sort of ...
    (comp.lang.c)
  • Re: Fastcode CompareStr B&V 1.1
    ... into the void where you read "SOME": ... > the two pointers together and check whether the result is 0 instead ... Gallery: http://web.telia.com/~u16122508/gallery/index.htm ... Prev by Date: ...
    (borland.public.delphi.language.basm)