1. Engineering
  2. Computer Science
  3. change reccurtion to itteration 1 public boolean searchint value ...

Question: change reccurtion to itteration 1 public boolean searchint value ...

Question details

change reccurtion to itteration:

1.)


public boolean search(int value)
{
return search(root, value);
}

private boolean search(Node r, int value)
{
if (r.getData() == value)
return true;
if (r.getLeft() != null)
if (search(r.getLeft(), value))
return true;
if (r.getRight() != null)
if (search(r.getRight(), value))
return true;
return false;   
}

2.)  

public int min(){
return min(root).getData();
}

private Node min(Node r){
if(r.getLeft()!=null){
r=min(r.getLeft());
}
return r;

3.)

  public int max(){
return max(root).getData();
}

private Node max(Node r){
if(r.getRight()!=null){
r=max(r.getRight());
}
return r;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution