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

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 

python program to take nested list input ...(nested list addition ,substraction etc)

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 #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Mar 13 14:25:56 2018 @author: beast Note this program is for holding int value to list only """ def inmatrix (): matrixA = list () # intialize matrix as empty list try : row,col = [ int (j) for j in ( input ( "Enter the row and col " ) . split())] print (row,col) inp = "" except ValueError : print ( "Please Enter row and col seperated by space eg: 2 2" ) inmatrix() for i in range (row): for j in range (col): inp += (( input ( "Enter the number--->" )) + "," ) try : lst = [ int (a) for a in inp . split( "," ) if a != "" ] #delete int for making it to hold any data

Internet Download Manager (IDM}

Internet Download Manager (IDM) is a tool to increase download speeds by up to 5 times, resume and schedule downloads. Comprehensive error recovery and resume capability will restart broken or interrupted downloads due to lost connections, network problems, computer shutdowns, or unexpected power outages. Simple graphic user interface makes IDM user friendly and easy to use.Internet Download Manager has a smart download logic accelerator that features intelligent dynamic file segmentation and safe multipart downloading technology to accelerate your downloads. Unlike other download managers and accelerators Internet Download Manager segments downloaded files dynamically during download process and reuses available connections without additional connect and login stages to achieve best acceleration performance. Internet Download Manager supports proxy servers, ftp and http protocols, firewalls, redirects, cookies, authorization, MP3 audio and MPEG video content processing. IDM integra

How to Put Google Adsense Below Post Title in Blogger?

Adsense is used by majority of expert bloggers for their website monetization because it is a cookie based contextual advertising system that shows targeted ads relevant to the content and reader. As bloggers are paid on per click basis, they try various ad placements on the blog to  increase the revenue  and get maximum clicks on the ad units. Well, on some blogs, you might have seen Adsense ad units placed below the post title. Do you know why? It is because the area just below the post title gets the most exposure and is the best place to put AdSense ad units to increase  Click Through Rate (CTR). Even though ads below post title work like a charm but this doesn’t mean that it will work for you as well. If you want to find out the best AdSense ads placement for your blog, try experimenting by placing ads at various locations such as header, sidebar, footer, etc. You can try other  blog monetization methods  as well to effectively monetize your blog. In this tutorial, I

3g what it is

Definition of 3G: 3G is the third generation of wireless technologies. It comes with enhancements over previous wireless technologies, like high-speed transmission, advanced multimedia access and global roaming. 3G is mostly used with mobile phones and handsets as a means to connect the phone to the Internet or other IP networks in order to make voice and video calls, to download and upload data and to surf the net. How is 3G Better?: 3G has the following enhancements over 2.5G and previous networks: Several times higher data speed; Enhanced audio and video streaming; Video-conferencing support; Web and WAP browsing at higher speeds; IPTV (TV through the Internet) support. 3G Technical Specifications: The transfer rate for 3G networks is between 128 and 144 kbps (kilobits per second) for devices that are moving fast and 384 kbps for slow ones(like for pedestrians). For fixed wireless LANs, the speed goes beyond 2 Mbps. 3G is a set of technologies and stand

Structure of C Programs

Objectives: Having completed this section you should know about: 1.C's character set 2.C's keywords 3.the general structure of a C program 4.that all C statement must end in a ; 5.that C is a free format language 6.all C programs us header files that contain standard library functions. C's Character Set: C does not use, nor requires the use of, every character found on a modern computer keyboard. The only characters required by the C Programming Language are as follows: A - Z a -z 0 - 9 space . , : ; ' $ " # % & ! _ {} [] () < > | + - / * = The use of most of this set of characters will be dicussed throughout the course. The form of a C Program: All C programs will consist of at least one function, but it is usual (when your experience grows) to write a C program that comprises several functions. The only function that has to be present is the function called main. For more advanced programs the main functi

python program get union of two list (program to get A union B ) list method .

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 #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Mar 16 17:08:52 2018 @author: beast """ def version1 (): a = [ 'a' , 'b' , 'c' , 'd' , 'e' ] # list 1 b = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' ] # list 2 c = [k for k in (a) if (k in (a) and k not in (b))] # include unique item from list 1 : items are (list1-list2)(set thoery) d = [l for l in (b) if l in (a ) and l in (b) or (l not in (a) and l in (b))] #include all the comman from list 1 and unique from list 2 lst = c + d # append above two comprehensed list to get union of list1 U list2 lst . sort() # not neccessay but makes list easy to understand (sorting in ascending order )

C Program for Password Login IN CUI

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 #include <stdio.h> char str; char passwd[ 100 ]; void main () { int i = 0 ,j; printf( "Enter the text now \n " ); while ((str = getch()) != '\r' ) { if (str == '\b' ){ // if a backspace key is used then go back printf( " \b \b " ); i -- ; } else { passwd[i ++ ] = str; printf( "*" ); // hide the password } } printf( " \n Finished " ); printf( " \n Your password is ->" ); for ( j = 0 ;j < i;j ++ ) printf( "%c" ,passwd[j]); getch(); }

Tips to Enable or Disable Toast Notifications on Windows 8

Windows 8 is among the most incredible and interesting kind of Windows version from Microsoft. It has visually eye catching design, which is found in modern user interface that is meant for redesigning a number of operating systems, worked out for users. If you have used or seen someone using Windows 8 you could have noticed the toast notifications in this modern version of windows, which simply appears the moment you install or uninstall any application. There are many users who are well versed with the bubble notifications, which were found in the earlier versions of Windows seen via the taskbar. The new application platform in Windows 8 comes with an integrated notification system for installing or uninstalling a number of modern applications. The Windows 8 style application can employ a number of notifications types including the traditional toast notifications, live titles and lock screen. These can be managed by either disabling or enabling the notification of your applicatio