Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 77ee27c

Browse files
committed
Initial Commit And Added Nodes Topic
0 parents  commit 77ee27c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Nodes/Node.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
public class Node {
2+
3+
public String data;
4+
private Node next;
5+
6+
public Node(String data) {
7+
this.data = data;
8+
this.next = null;
9+
}
10+
11+
public void setNextNode(Node node) {
12+
this.next = node;
13+
}
14+
15+
public Node getNextNode() {
16+
return this.next;
17+
}
18+
19+
public static void main(String[] args) {
20+
Node strawberry = new Node("Strawberry First");
21+
Node banana = new Node("Banana Second");
22+
Node coconut = new Node("Coconut Third");
23+
24+
strawberry.setNextNode(banana);
25+
banana.setNextNode(coconut);
26+
27+
Node currentNode = strawberry;
28+
while (currentNode != null) {
29+
System.out.println(currentNode.data);
30+
currentNode = currentNode.getNextNode();
31+
}
32+
}
33+
34+
}

Nodes/readme.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Nodes
2+
Nodes are the fundamental building blocks of many computer science data structures.
3+
4+
They form the basis for linked lists, stacks, queues, trees, and more.
5+
6+
An individual node contains data and links to other nodes.
7+
8+
Each data structure adds additional constraints or behavior to these features to create the desired structure.
9+
10+
## Nodes Data
11+
The data contained within a node can be a variety of types (depending on the language being used).
12+
13+
The link or links within the node are sometimes referred to as _pointers_. This is because they “_point_” to another node.
14+
15+
Typically, data structures implement nodes with one or more links. If these links are _null_, it denotes that you have reached the _end of the particular node_ or link path you were previously following.
16+
17+
## Linking
18+
19+
It is very important to consider how you implement, modify or removing nodes from a data structure.
20+
21+
If you _inadvertently_ remove the single link to a node, that node’s data and any linked nodes could be “**lost**” to your application. When this happens to a node, it is called an **orphaned node**.
22+

0 commit comments

Comments
 (0)