Skip to main content

Binary Search Tree in Java implementation (reference based, dynamic memory)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.util.Scanner;
 class BST {
    static BST.Node root = null;
    public void insert(int num) {
        if (root == null) {
            root = new BST.Node(num);
        } else {// root node is not empty
            BST.Node temp = root;
            while (temp != null) {

                if (num <= temp.getVal()) {
                    if (temp.getLeft() != null)
                        temp = temp.getLeft();
                    else {
                        temp.setLeft(new Node(num));
                        break;
                    }
                } else {
                    if (temp.getRight() != null)
                        temp = temp.getRight();
                    else {


                        temp.setRight(new Node(num));
                        break;
                    }

                }

            }


        }
    }

    public void search(int num, Node root) {
        if (root == null) {
            System.out.println("Number is not present ");
            return;
        }
        if (root.getVal() == num) {
            System.out.println("Number is present ");
        } else {
            if (num < root.getVal()) search(num, root.getLeft());
            else search(num, root.getRight());
        }


    }

    public void display(Node root) {
        if (root == null)
            return;
        display(root.getLeft());
        System.out.println(" " + root.getVal() + " ");
        display(root.getRight());

    }

    public static void main(String[] args) {
        BST bst= new BST();
        byte choice = 0;
        while (choice != 4) {
            int num;

            Scanner in = new Scanner(System.in);
            System.out.print("\nPress \n1 to insert \n2. To search \n3. Display \n4 to exit->");
            choice = in.nextByte();
            switch (choice) {
                case 1:
                    System.out.print("Enter the number ->");
                    num = in.nextInt();
                    bst.insert(num);
                    break;
                case 2:
                    System.out.print("Enter the Number ");
                    num = in.nextInt();
                    bst.search(num, root);
                    break;
                case 3:
                    bst.display(root);


            }

        }

    }

    private static class Node {
        private int val;
        private Node left = null;
        private Node right = null;

        public Node(int i) {
            this.val = i;
        }

        public int getVal() {
            return val;
        }

        public void setVal(int val) {
            this.val = val;
        }

        public Node getLeft() {
            return left;
        }

        public void setLeft(Node left) {
            this.left = left;
        }

        public Node getRight() {
            return right;
        }

        public void setRight(Node right) {
            this.right = right;
        }

    }
}

Comments

  1. Your Affiliate Profit Machine is waiting -

    Plus, making profit with it is as easy as 1..2..3!

    Here are the steps to make it work...

    STEP 1. Input into the system what affiliate products the system will advertise
    STEP 2. Add push button traffic (it takes JUST 2 minutes)
    STEP 3. Watch the system grow your list and up-sell your affiliate products for you!

    Are you ready to make money ONLINE???

    Click here to activate the system

    ReplyDelete
  2. Did you realize there is a 12 word phrase you can tell your crush... that will trigger intense emotions of love and impulsive attraction to you buried within his chest?

    That's because hidden in these 12 words is a "secret signal" that triggers a man's impulse to love, look after and guard you with his entire heart...

    12 Words Who Fuel A Man's Love Response

    This impulse is so hardwired into a man's mind that it will drive him to try harder than ever before to make your relationship as strong as it can be.

    In fact, triggering this powerful impulse is so essential to getting the best ever relationship with your man that the instance you send your man one of these "Secret Signals"...

    ...You will immediately find him expose his soul and mind for you in a way he's never expressed before and he will distinguish you as the one and only woman in the galaxy who has ever truly appealed to him.

    ReplyDelete
  3. According to Stanford Medical, It's really the one and ONLY reason this country's women get to live 10 years longer and weigh 19 KG lighter than we do.

    (And actually, it has totally NOTHING to do with genetics or some secret-exercise and really, EVERYTHING about "HOW" they are eating.)

    BTW, I said "HOW", and not "WHAT"...

    Tap this link to see if this brief questionnaire can help you discover your true weight loss possibilities

    ReplyDelete
  4. Your Affiliate Money Making Machine is waiting -

    Plus, making profit with it is as simple as 1-2-3!

    This is how it all works...

    STEP 1. Choose affiliate products you want to promote
    STEP 2. Add some PUSH button traffic (it takes JUST 2 minutes)
    STEP 3. Watch the affiliate system explode your list and upsell your affiliate products all for you!

    Are you ready to make money automatically??

    Get the full details here

    ReplyDelete

Post a Comment

share your thoughts ....

Popular posts from this blog

QWERTY-keyboard when this idean came

QWERTY QWERTY   / ˈ k w Éœr t i /  is the most common modern-day  keyboard layout . The name comes from the first six  keys  appearing on the top left letter row of the keyboard and read from left to right: Q-W-E-R-T-Y. The QWERTY design is based on a layout created for the  Sholes and Glidden typewriter  and sold to  Remington  in 1873. It became popular with the success of the Remington No. 2 of 1878, and remains in use on electronic keyboards due to the  network effect  of a standard layout and a belief that  alternatives  fail to provide very significant advantages. [ 1 ]  The use and adoption of the QWERTY keyboard is often viewed as one of the most important case studies in  open standards  because of the widespread, collective adoption and use of the product. [ 2 ] History and purposes [ edit ] Keys are arranged on diagonal columns, to give space for the levers. Main article:  Sholes and Glidden typewriter Still used to this day, the QWERTY layout was devised

Dragon Age: Inquisition Digital Deluxe Edition + All DLCs (torrent) Repack Size: 20.1~23.9 GB

Brief : Dragon Age: Inquisition  is an  action role-playing video game  developed by  Bioware Edmonton  and published by  Electronic Arts . The third major game in the  Dragon Age  franchise,  Dragon Age: Inquisition  is the sequel to  Dragon Age: Origins  and  Dragon Age II . The game was released worldwide in November 2014 for  Microsoft Windows ,  PlayStation 3 ,  PlayStation 4 ,  Xbox 360 , and  Xbox One . Repack Size: 20.1~23.9 GB 

6 Ways to Hack or deface Websites Online

Hello friends , today i will explain all the methods that are being used to hack a website or websites database. This is the first part of the hacking websites tutorial where i will explain in brief all methods for hacking or defacing websites. Today I will give you the overview and in later tutorials we will discuss them one by one with practical examples. So guys get ready for first part of Hacking websites class.... Don't worry i will also tell you how to protect your websites from these attacks and other methods like hardening of SQL and hardening of web servers and key knowledge about CHMOD rights that what thing should be give what rights... Note : This post is only for Educational Purpose only. What are basic things you should know before website hacking? First of all everything is optional as i will start from very scratch. But you need atleast basic knowledge of following things.. 1. Basics of HTML, SQL, PHP. 2. Basic knowledge of Javascript. 3. Basic knowled

How to open facebook through Uninor when it is blocked

Tweet Just Follow this steps . 1. Goto www.uninor.in 2. choose your circle 3.Goto  http://www.uninor.in/customer-care/Pages/customer-complaint-log.aspx 4. Now in new complaint just type your moblie number 5.now you will receive passwrod just type in and hit submit 7. NOW select as following as type as it in every box Complaint Type   -- Select --   DND Related   GPRS   Network Related   Tariff & VAS Related   Activation/ Deactivation   Barring/ Unbarring   Balance Related    Complaint Area   -- Select --   Activation / Deactivation   PC/Modem Connectivity   Usage / Charges related   GPRS issues   Non-Uninor sites   Complaint sub Area   -- Select --   Unable to browse   Unable to download   Please ensure all questions below are answered in the text box below. 1. Handset make and model no. 2. Web Site Name/ URL 3. Error message

What Are Search Engine Spiders?

A spider, also known as a robot or a crawler, is actually just a program that follows, or "crawls", links throughout the Internet, grabbing content from sites and adding it to search engine indexes. Spiders only can follow links from one page to another and from one site to another. That is the primary reason why links to your site (inbound links) are so important. Links to your website from other websites will give the search engine spiders more "food" to chew on. The more times they find links to your site, the more times they will stop by and visit. Google especially relies on its spiders to create their vast index of listings. Spiders find Web pages by following links from other Web pages, but you can also submit your Web pages directly to a search engine or directory and request a visit by their spider. In fact, it's a good idea to manually submit your site to a human-edited directory such as Yahoo, and usually spiders from other search e

Input and Output Functions in c

Objectives: Having read this section you should have a clearer idea of one of C's: 1.input functions, called scanf 2.output functions, called printf On The Run: Even with arithmetic you can't do very much other than write programs that are the equivalent of a pocket calculator. The real break through comes when you can read values into variables as the program runs. Notice the important words here: "as the program runs". You can already store values in variables using assignment. That is: a=100; stores 100 in the variable a each time you run the program, no matter what you do. Without some sort of input command every program would produce exactly the same result every time it was run. This would certainly make debugging easy! But in practice, of course, we need programs to do different jobs each time they are run. There are a number of different C input commands, the most useful of which is the scanf command. To read a single integer value into the variable cal

Overview of C

Why use C?: C has been used successfully for every type of programming problem imaginable from operating systems to spreadsheets to expert systems - and efficient compilers are available for machines ranging in power from the Apple Macintosh to the Cray supercomputers. The largest measure of C's success seems to be based on purely practical considerations: the portability of the compiler; the standard library concept; a powerful and varied repertoire of operators; an elegant syntax; ready access to the hardware when needed; and the ease with which applications can be optimized by hand-coding isolated procedures C is often called a "Middle Level" programming language. This is not a reflection on its lack of programming power but more a reflection on its capability to access the system's low level functions. Most high-level languages (e.g. Fortran) provides everything the programmer might want to do already built into the language. A low l

python program to Print Starting Series OF Indian Mobile Number for a State or operator or both

import requests import urllib.request import time from bs4 import BeautifulSoup as bs import re url = ' https://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India' state_to_extract = "UE" #if set to None all state is considered telecom_to_extracted = None #if set to none all operator from particular city is extracted response = requests . get(url) print (response) soup = bs(response . text, "html.parser" ) one_a_tag = soup . findAll( 'tr' )[ 35 :] lst = [] for k in one_a_tag: s = k . findAll( 'td' ) limit = len (s) i = 0 while True : if i == limit: break no = s[i] . text i += 1 if i == limit: break operator = s[i] . text i += 1 if i == limit: break state = s[i] . text i += 1 if i == limit: break res = f "{no} {operator} {state}" if state_to_extract is None : if telecom_to_extracted is None : lst . append(no) elif telecom_to_e

Download pocket tank delux with 295 weapons free total 295 weapons version 1.6

Download Pocket Tanks Deluxe Full Version Free With 295 Weapons Pack | Size: 30MB UPDATED 2019 /19/april Description: Pocket Tanks is a 1-2 player computer game for Windows and Mac OS X, created by Blitwise Productions, developer of Super DX-Ball and Neon Wars. Adapted from Michael Welch's earlier Amiga game Scorched Tanks, this newer version features modified physics, dozens of weapons ranging from simple explosive shells to homing missiles, and the ability to move the tank. It supports several expansion packs. At the moment, players can have up to 295 different weapons total. Pocket Tanks is often abbreviated as PTanks. Have Fun! NOTE: FILE NAME IS SCRAMBLED FOR AVOIDING HARD DETECTION & FILE TAKEN DOWN . How to Play: Best with 2 players on the same computer at school or at work. UPDATED LINK https://mirr.re/d/u1Y https://nl26.seedr.cc/ff_get/447027537/ptd16.295.exe?st=lUp-PbRp4YOwToHIOGwStQ&e=1555747979 http://www.uploadmagnet.com/7gfzhbyfe