NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package Tree;

public class Node {

public int data;
public Node leftChild;
public Node rightChild;

public void displayNode() {

System.out.println("{");

System.out.println(data);

System.out.println("}");
}

}
-------------------------------------------------------------------------------------------------------
package Tree;

public class Tree {

Node root;

public Node minimum() {

Node current=root;

Node last=null;

while(current!=null) {

last=current;

current=current.leftChild;
}

return last;
}

public Node minRec(Node root) {

if(root.leftChild==null) {

return root;
}

return minRec(root.leftChild);
}

public boolean delete(int key) {

Node current=root;

Node parent=root;

boolean isleftChild=true;

while(current.data!=key) {

parent=current;

if(key<current.data) {

isleftChild=true;

current=current.leftChild;
}

else {

isleftChild=false;

current=current.rightChild;

}

if(current==null) {

return false;
}
}

if(current.leftChild==null && current.rightChild==null) {

if(current==root) {

root=null;
} else if (isleftChild){

parent.leftChild=null;
} else {

parent.rightChild=null;
}
}

else if(current.rightChild==null) {

if(current==root) {

root=current.leftChild;
} else if(isleftChild) {

parent.leftChild=current.leftChild;
} else {

parent.rightChild=current.leftChild;
}
}

else if(current.leftChild==null) {

if(current==root) {

root=current.rightChild;
} else if(isleftChild) {

parent.leftChild=current.rightChild;
} else {

parent.rightChild=current.rightChild;
}
}

else {

Node succesor=getSuccesor(current);

if(current==root) {

root=succesor;
} else if(isleftChild){

parent.leftChild=succesor;
} else {

parent.rightChild=succesor;
}

succesor.leftChild=current.leftChild;
}

return true;
}

private Node getSuccesor(Node delNode) {

Node succesorParent=delNode;

Node succesor=delNode;

Node current=delNode.rightChild;

while(current!=null) {

succesorParent=succesor;

succesor=current;

current=current.leftChild;
}

if(succesor!=delNode.rightChild) {

succesorParent.leftChild=succesor.rightChild;

succesor.rightChild=delNode.rightChild;
}

return succesor;
}

public void displayNode() {

System.out.println(root);
}

}

--------------------------------------------------------------------------------------------------------
package Tree;

public class TreeApp {

public static void main(String[] args) {

Tree theTree=new Tree();

theTree.insert(50);
theTree.insert(37);
theTree.insert(21);
theTree.insert(45);
theTree.insert(65);
theTree.insert(64);
theTree.insert(70);
theTree.insert(80);
theTree.insert(90);
theTree.insert(95);

theTree.minimum().displayNode();;
}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.