20. In a binary search tree, the immediate predecessor of a given node is the largest node in its left subtree. For example, the immediate predecessor of node 25 in the following tree is 23 while it is 15 for node 16. Nodes 21 and 39 do not have an immediate predecessor because none of them has a left child. 25 Write a non-recursive method immediate Predecessor, which takes a BSTNode parameter node (a reference to a node in a binary search tree) and returns a reference to its immediate predecessor in the tree. If node is null or it does not have an immediate predecessor, the method returns null. public class BSTNode. / 1 39 1 16 / \ 12 21 43 / \ \ 4 15 23 42 50

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
}
20. In a binary search tree, the immediate predecessor of a given node is the largest node in its left subtree.
For example, the immediate predecessor of node 25 in the following tree is 23 while it is 15 for node 16.
Nodes 21 and 39 do not have an immediate predecessor because none of them has a left child.
25
/ 1
Write a non-recursive method immediate Predecessor, which takes a
BSTNode parameter node (a reference to a node in a binary search tree)
and returns a reference to its immediate predecessor in the tree. If node is
null or it does not have an immediate predecessor, the method returns
null.
public class BSTNode
4
{
private int m_info;
private BSTNode m_left;
private BSTNode m_right;
public int getInfo() {return m_info; }
public void setInfo (int value) {m_info
= info; }
public BSTNode getLeft () {return m_left; }
public void setLeft (BSTNode left) (m_left = left; }
public BSTNode getRight () {return m_right;}
public void setRight (BSTNode right) {m_right
= right;}
}
public BSTNode immediate Predecessor (BSTNode node)
{
16
/ \
12 21
39
1
43
/ \
15 23 42 50
Transcribed Image Text:} 20. In a binary search tree, the immediate predecessor of a given node is the largest node in its left subtree. For example, the immediate predecessor of node 25 in the following tree is 23 while it is 15 for node 16. Nodes 21 and 39 do not have an immediate predecessor because none of them has a left child. 25 / 1 Write a non-recursive method immediate Predecessor, which takes a BSTNode parameter node (a reference to a node in a binary search tree) and returns a reference to its immediate predecessor in the tree. If node is null or it does not have an immediate predecessor, the method returns null. public class BSTNode 4 { private int m_info; private BSTNode m_left; private BSTNode m_right; public int getInfo() {return m_info; } public void setInfo (int value) {m_info = info; } public BSTNode getLeft () {return m_left; } public void setLeft (BSTNode left) (m_left = left; } public BSTNode getRight () {return m_right;} public void setRight (BSTNode right) {m_right = right;} } public BSTNode immediate Predecessor (BSTNode node) { 16 / \ 12 21 39 1 43 / \ 15 23 42 50
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY