Programming Language: Java

Class/Type: Node

Method/Function: getRight

Examples at hotexamples.com: 30

java Node.getRight() is a method which returns the right child of the current node. This method is commonly used in tree data structures to access the right subtree of a node.

**Example 1:** getting the right child of a binary search tree node

This example shows a binary search tree implementation in Java where we can get the right child of any node using the getRight() method.

**Example 2:** getting the right child of a linked list node

import java.util.*; class Node { int value; Node left; Node right; public Node(int val) { value = val; left = null; right = null; } } public class BinarySearchTree { Node root; //methods for inserting, deleting and searching in BST public Node getRightChild(Node current) { if (current != null) { return current.right; } return null; } }

This example shows a binary search tree implementation in Java where we can get the right child of any node using the getRight() method.

import java.util.*; class Node { int value; Node next; public Node(int val) { value = val; next = null; } } public class LinkedList { Node head; //methods for inserting, deleting and searching in linked list public Node getRightNode(Node current) { if (current != null) { return current.next; } return null; } }This example shows a linked list implementation in Java where we can get the right node of any node using the getRight() method. Package/Library: This method is not associated with any specific package/library. It is a method that can be defined in any custom class that uses tree or linked list data structures.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related

x