Computer Science, asked by vj92910p6tnta, 1 year ago

Make a binary search tree of values 8,4,15,10 & 3.​

Answers

Answered by Sidyandex
0

Answer:

public class BST <AnyType extends Comparable<AnyType>>

{

  private Node<AnyType> root;

  private class Node<AnyType>

  {

     private AnyType data;

     private Node<AnyType> left, right;

     public Node(AnyType data)

     {

        left = right = null;

        this.data = data;

     }

  }

  ...

}public AnyType next()

{

  Node cur = stk.peek();

  if(cur.left != null)

  {

     stk.push(cur.left);

  }

  else

  {

     Node tmp = stk.pop();

     while(tmp.right == null)

     {

        if (stk.isEmpty()) return cur.data;

        tmp = stk.pop();

     }

     stk.push(tmp.right);

  }

  return cur.data;

}

Similar questions
Math, 6 months ago