Concept of an Element (Node)

From

(Difference between revisions)
Jump to: navigation, search
Line 6: Line 6:
== Examples of Abstract Node Implementation ==
== Examples of Abstract Node Implementation ==
 +
A node containing a single reference field.
A node containing a single reference field.
 +
   '''class''' ''Node'' {
   '''class''' ''Node'' {
     data ''// The data being stored in the node''
     data ''// The data being stored in the node''
Line 14: Line 16:
Here three such nodes form a singly-linked list of length 3.
Here three such nodes form a singly-linked list of length 3.
 +
<br>[[Image:Singly_linked_list_delete_after.png]]
-
[[Image:Node chain.svg]]
+
<br>
-
 
+
-
 
+
A node containing two reference fields.
A node containing two reference fields.
 +
   '''class''' ''Node'' {
   '''class''' ''Node'' {
     data ''// The data being stored in the node''
     data ''// The data being stored in the node''
Line 28: Line 30:
Here two such nodes form a doubly-linked list of length 2.
Here two such nodes form a doubly-linked list of length 2.
-
[[Image:node chain.svg]]
+
[[Image:]]
-
 
+
-
[[Category:Linked lists]]
+
-
[[Category:Trees (structure)]]
+
-
[[Category:Graph data structures]]
+
-
 
+
 +
<br>
-
 
+
<br>(...Java Example Link...)
-
(...Java Example Link...)
+
(...C++ Example Link...)&nbsp;
(...C++ Example Link...)&nbsp;
Line 46: Line 43:
[[/index.php/CS-2|Back to Data Structures]]
[[/index.php/CS-2|Back to Data Structures]]
 +
 +
[[Category:Linked_lists]] [[Category:Trees_(structure)]] [[Category:Graph_data_structures]]

Revision as of 17:01, 25 March 2009

A node is an abstract basic unit used to build linked data structures such as trees, linked lists, and computer-based representations of 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.

Nodes are conceptually similar to vertices, which are elements of a graph.

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.


Image:Singly_linked_list_delete_after.png


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 two such nodes form a doubly-linked list of length 2.

[[Image:]]



(...Java Example Link...)

(...C++ Example Link...) 



Back to Data Structures

Personal tools
MediaWiki Appliance - Powered by TurnKey Linux