Concept of an Element (Node)
From
(→Examples of Abstract Node Implementation) |
|||
Line 1: | Line 1: | ||
- | A '''node''' is an abstract basic unit used to build linked | + | A '''node''' is an abstract basic unit used to build linked data structures such as linked lists, trees, and graphs. Each node contains some data and possibly links to other nodes. Links between nodes are often implemented by pointers or references. |
+ | <br/><br/> | ||
A node can be thought of as a logical placeholder for some data. It is a memory block which contains some data unit and perhaps references to other nodes, which in turn contain data and perhaps references to yet more nodes. By forming chains of interlinked nodes, very large and complex data structures can be formed. | A node can be thought of as a logical placeholder for some data. It is a memory block which contains some data unit and perhaps references to other nodes, which in turn contain data and perhaps references to yet more nodes. By forming chains of interlinked nodes, very large and complex data structures can be formed. | ||
- | + | <br/><br/> | |
- | + | ||
== Examples of Abstract Node Implementation == | == Examples of Abstract Node Implementation == | ||
Line 11: | Line 11: | ||
'''class''' ''Node'' { | '''class''' ''Node'' { | ||
data ''// The data being stored in the node'' | data ''// The data being stored in the node'' | ||
- | next ''// A | + | next ''// A reference to the next node, null if last node'' |
} | } | ||
Line 24: | Line 24: | ||
'''class''' ''Node'' { | '''class''' ''Node'' { | ||
data ''// The data being stored in the node'' | data ''// The data being stored in the node'' | ||
- | previous ''// A | + | previous ''// A reference to the previous node, null if first node'' |
- | next ''// A | + | next ''// A reference to the next node, null if last node'' |
} | } | ||
Revision as of 15:04, 29 March 2009
A node is an abstract basic unit used to build linked data structures such as linked lists, trees, and graphs. Each node contains some data and possibly links to other nodes. Links between nodes are often implemented by pointers or references.
A node can be thought of as a logical placeholder for some data. It is a memory block which contains some data unit and perhaps references to other nodes, which in turn contain data and perhaps references to yet more nodes. By forming chains of interlinked nodes, very large and complex data structures can be formed.
Examples of Abstract Node Implementation
A node containing a single reference field.
class Node { data // The data being stored in the node next // A reference to the next node, null if last node }
Here three such nodes form a singly-linked list of length 3.
A node containing two reference fields.
class Node { data // The data being stored in the node previous // A reference to the previous node, null if first node next // A reference to the next node, null if last node }
Here three such nodes form a doubly-linked list of length 3.
(...Java Example Link...)
(...C++ Example Link...)