Doubly-linked list/Element definition: Difference between revisions
Content added Content deleted
(Added Algol W) |
|||
Line 131: | Line 131: | ||
=={{header|C}}== |
=={{header|C}}== |
||
It basically doesn't matter if we use the name link, node, Node or some other name. These are matters of taste and aesthetics. However, it is important that the C language is case-sensitive and that the namespace for structures is separate. |
|||
<lang c>struct |
<lang c>struct Node |
||
{ |
{ |
||
struct |
struct Node *next; |
||
struct |
struct Node *prev; |
||
void *data; |
void *data; |
||
size_t type; |
|||
};</lang> |
};</lang> |
||
An alternative technique is to define a pointer type by typedef as shown below. The advantage here is that you do not have to write struct everywhere - assuming that you will most often need a pointer to a struct Node, not the structure itself. |
|||
<lang c> |
|||
struct Node; |
|||
typedef struct Node* Node; |
|||
struct Node |
|||
{ |
|||
Node next; |
|||
Node prev; |
|||
void* data; |
|||
}; |
|||
</lang> |
|||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |