Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package binarytree;
- /**
- * @author Otto Sabart - Seberm
- * 11/10/2010
- */
- public class Node {
- // Artibutes: //
- private int m_key;
- private Node m_left = null;
- private Node m_right = null;
- // Constructors: //
- public Node() {
- m_key = 0;
- }
- public Node(int key) {
- m_key = key;
- }
- // Methods: //
- public int getKey() {
- return m_key;
- }
- public void insertKey(int key) {
- if (key > m_key) {
- if (m_right == null)
- m_right = new Node(key);
- else m_right.insertKey(key);
- } else if (m_left == null)
- m_left = new Node(key);
- else m_left.insertKey(key);
- }
- public void removeKey() {
- /*
- * @todo dodelat odstaneni klice...tak aby nezustavala zapolnena pamet..a pointer se mezi nodama posouval spravne
- */
- }
- public int getMax() {
- if (m_right == null)
- return m_key;
- else return m_right.getMax();
- }
- public int getMin() {
- if (m_left == null)
- return m_key;
- else return m_left.getMin();
- }
- public boolean searchKey(int key) {
- if (key == m_key)
- return true;
- if (key > m_key) {
- if (m_right != null)
- return m_right.searchKey(key);
- else return false;
- } else {
- if (m_left != null)
- return m_left.searchKey(key);
- else return false;
- }
- }
- public void printFindResult(int key) {
- if (searchKey(key))
- System.out.printf("Program found number %d\n", key);
- else System.out.printf("Program didn't find the number %d\n", key);
- }
- }
Add Comment
Please, Sign In to add comment