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

12 Tips to Maintain a Virus Free Computer

1. Email is one of the common ways by which your computer can catch a virus . So it is always recommended to stay away from SPAM. Open only those emails that has it’s origin from a trusted source such as those which comes from your contact list. If you are using your own private email host (other than gmail, yahoo, hotmail etc.) " then it is highly recommended that you use a good anti-spam software. And finally NEVER click on any links in the emails that comes from untrusted sources. 2. USB thumb/pen drives is another common way by which viruses spread rapidly." So it is always a good habit to perform a virus scan before copying any data onto your computer. NEVER double-click the pen drive to open it. Instead right-click on it and select the option “open”. This is a safe way to open a pen drive. 3. Be careful about using MS Outlook. Outlook is more susceptible to worms than other e-mail programs, unless you have efficient Anti-Virus programs running. Use Pegasus ...

Streamlining Java Web Application Deployment with React WAR Generator

In the ever-evolving world of web development, managing builds and deployments can often be cumbersome and error-prone. Today, we're excited to introduce a tool designed to simplify and streamline this process: the React WAR Generator . What is the React WAR Generator? The React WAR Generator is a Python-based tool that automates the creation of WAR (Web Application Archive) files for Java web applications. It caters specifically to frontend projects built with React or similar frameworks, making it easier to package and deploy your web applications to a Tomcat server. Key Features Profile-Based Builds : With support for multiple profiles ( dev , test , prod , default ), you can build your application according to different environments and configurations. Version File Generation : Optionally generate a version file that integrates versioning information directly into your TypeScript files, ensuring your build versions are always up-to-date. Tomcat Deployment : Simplify your deploy...

How to Protect an Email Account from being Hacked

If this is the case, then what is the reason for many people to lose their accounts? The answer is very simple. They don’t know how to protect themselves from being hacked! In fact most of the people who lose their email accounts are not the victims of hacking but the victims of Trapping. They lose their passwords not because they are hacked by some expert hackers but they are fooled to such an extent that they themselves give away their password. Are you confused? If so continue reading and you’ll come to know… Now I’ll mention some of the most commonly used online scams which fool people and make them lose their passwords. I’ll also mention how to protect your email account from these scams. 1 . WEBSITE SPOOFING =Website spoofing is the act of creating a website, with the intention of misleading the readers. The website will be created by a different person or organisation (Other than the original) especially for the purposes of cheating. Normally, the website...

how to Send a Confirmation Email Upon Form Submission-Woofoo

When someone successfully submits an entry, you can automatically send them a confirmation email to let them know. You can customize the email to include any follow-up info you'd like, and you can choose to include a copy of their entry in the email as well. To set up confirmation emails in Form Settings: Log in and go to  Forms . Hover over  Edit  next to the form you want to edit. Choose  Edit form . Click the  Form Settings  tab. Under Confirmation Options, select  Send Confirmation Email to User . From the  Send To  dropdown, select an Email field from your form. We'll send the confirmation email to the email address the person filling out your form entered into this field. If the dropdown says "No Email Fields Found", add an  Email  field to your form. In the  Reply To  textbox, enter the reply-to email—if someone replies to their confirmation email, this is the email address that their reply will be s...

How to Use Google for Hacking

Google serves almost 80 percent of all the search queries on the Internet, proving itself as the most popular search engine. However, Google makes it possible to reach not only the publicly available information resources, but also gives access to some of the most confidential information that should never have been revealed. In this post, you will find the information on how to use Google for exploiting security vulnerabilities that exists within many websites. The following are some of the ways to use Google for hacking : 1. Using Google to Hack Security Cameras: There exists many security cameras that are used for monitoring places like parking lots, college campus, road traffic etc. With Google, it is possible to hack these cameras so that you can view the images captured by them in real time. For this, all you have to do is just use the following search query in Google. Type in the Google search box exactly as given below and hit enter: inurl:”viewerframe?m...

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...

How to Hack an Ethernet ADSL Router

Every router comes with a  username  and  password  using which it is possible to gain access to the router settings and configure the device. The vulnerability actually lies in the  Default username  and  password  that comes with the factory settings. Usually the routers come preconfigured from the Internet Service provider and hence the users do not bother to change the password later. This makes it possible for the attackers to gain unauthorized access to the router and modify its settings using a common set of default usernames and passwords. Here is how you can do it. Before you proceed, you need the following tool in the process: Angry IP Scanner Hacking the ADSL Router: Here is a detailed information on how to exploit the vulnerability of an ADSL router: Go to  whatismyipaddress.com . Once the page is loaded, you will find your IP address. Note it down. Open Angry IP Sca...

just more way to disable autorun.inf

Auto run.Inf this is a instruction file associated with the Auto run function. It is a simple text configuration file that instructs the OS (operating system) which executable to start which icon to use which additional menu commands to make available etc Auto run.inf must be located in the root directory of a volume.That is CD,DVD,of Floppy Disk or Pen drive. It is mainly used by the manufacturer on what actions to taken when their CD-ROM when it is inserted. In OS, when autorun.inf is enabled (Normally by default it is enabled ) then by inserting the Cd or DVD the content of the medium is automatically executed. This is to avoid the user intervention and help the low level knowledge of computer literacy people. But Virus programmer taken this as advantage and make virus instruction in autorun.inf text file. TYPICAL AUTORUN.INF A typical autorun.inf file looks like below. [autorun] open=setup.exe icon=setup.exe,0 label=GameProgram SIMPLE METHOD NOT TO GET INFECTED BY AUTORUN.INF:...

Samsung mobile cheat codes

* Software version: *#9999# * IMEI number: *#06# * Serial number: *#0001# * Battery status- Memory capacity : *#9998*246# * Debug screen: *#9998*324# – *#8999*324# * LCD kontrast: *#9998*523# * Vibration test: *#9998*842# – *#8999*842# * Alarm beeper – Ringtone test : *#9998*289# – *#8999*289# * Smiley: *#9125# * Software version: *#0837# * Display contrast: *#0523# – *#8999*523# * Battery info: *#0228# or *#8999*228# * Display storage capacity: *#8999*636# * Display SIM card information: *#8999*778# * Show date and alarm clock: *#8999*782# * The display during warning: *#8999*786# * Samsung hardware version: *#8999*837# * Show network information: *#8999*638# * Display received channel number and received intensity: *#8999*9266# * *#1111# S/W Version * *#1234# Firmware Version * *#2222# H/W Version * *#8999*8376263# All Versions Together * *#8999*8378# Test Menu * *#4777*8665# GPSR Tool * *#8999*523# LCD Brightness * *#8999*377# Error LOG Menu *...