Programming Language: Java

Class/Type: Node

Method/Function: getRightChild

Examples at hotexamples.com: 21

Node.getRightChild() is a method in Java used to retrieve the right child node of a given node.

Example 1:

Suppose we have a binary tree with root node "A", left child node "B" and right child node "C". If we want to retrieve the right child node of node "A", we can use the getRightChild() method as follows:

Node root = new Node("A");

Node leftChild = new Node("B");

Node rightChild = new Node("C");

root.setLeftChild(leftChild);

root.setRightChild(rightChild);

Node rChild = root.getRightChild(); // returns node "C"

Example 2:

If we have a linked list of nodes, where each node has a reference only to the next node, we can use the getRightChild() method to retrieve the next node.

Node currentNode = headNode; // headNode is the first node in the list

while(currentNode != null){

Node nextNode = currentNode.getRightChild();

// do something with nextNode

currentNode = currentNode.getRightChild();

}

This method is most likely part of a custom node or tree-based library and not part of the standard Java library.

Example 1:

Suppose we have a binary tree with root node "A", left child node "B" and right child node "C". If we want to retrieve the right child node of node "A", we can use the getRightChild() method as follows:

Node root = new Node("A");

Node leftChild = new Node("B");

Node rightChild = new Node("C");

root.setLeftChild(leftChild);

root.setRightChild(rightChild);

Node rChild = root.getRightChild(); // returns node "C"

Example 2:

If we have a linked list of nodes, where each node has a reference only to the next node, we can use the getRightChild() method to retrieve the next node.

Node currentNode = headNode; // headNode is the first node in the list

while(currentNode != null){

Node nextNode = currentNode.getRightChild();

// do something with nextNode

currentNode = currentNode.getRightChild();

}

This method is most likely part of a custom node or tree-based library and not part of the standard Java library.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related