tree

// par défaut
TreeSet ensemble = new TreeSet();
// comparateur
Comparator comparateur = new Comparateur();
TreeSet ensemble = new TreeSet(comparateur);

// classe Comparateur implémentant l'interface Comparator
public class Comparateur implements Comparator {
  public int compare(Object obj1, Object obj2){
    return ((Comparable)obj2).compareTo(obj1);
  }
  public boolean equals(Object obj){
    return this.equals(obj);
  }
}

4
6
Jonwayne 140 points

                                    class Node:
    def __init__(self,key):
        self.left = None
        self.right = None
        self.val = key
 
root = Node(1)
root.left      = Node(2);
root.right     = Node(3);
root.left.left  = Node(4);

4 (6 Votes)
0
4
8

                                    TreeSet: Can contain only unique values and it is sorted in ascending order
TreeMap: Can contain only unique keys and keys are sorted in ascending order.

4 (8 Votes)
0
3.75
8
M Palmer 90 points

                                    void insert(int data) {
   struct node *tempNode = (struct node*) malloc(sizeof(struct node));
   struct node *current;
   struct node *parent;

   tempNode->data = data;
   tempNode->leftChild = NULL;
   tempNode->rightChild = NULL;

   //if tree is empty, create root node
   if(root == NULL) {
      root = tempNode;
   } else {
      current = root;
      parent  = NULL;

      while(1) {                
         parent = current;

         //go to left of the tree
         if(data < parent->data) {
            current = current->leftChild;                
            
            //insert to the left
            if(current == NULL) {
               parent->leftChild = tempNode;
               return;
            }
         }
			
         //go to right of the tree
         else {
            current = current->rightChild;
            
            //insert to the right
            if(current == NULL) {
               parent->rightChild = tempNode;
               return;
            }
         }
      }            
   }
}

3.75 (8 Votes)
0
4.14
7
O.Raz 90 points

                                    Trees are pretty POG

4.14 (7 Votes)
0
3
2
TKK 135 points

                                    // extrait de la classe TreeSet
public class TreeSet extends AbstractSet
        implements SortedSet, Cloneable, java.io.Serializable {
  //...
  public TreeSet() {
    this(new TreeMap());
  }
  //...
}

3 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
trees definition bs tree binary tree.com BINARY TREE DEF TreeSet sprt treeset' whats a binary tree treeset() what's a binary tree? binary treebfs binery tree binary tree binary code tree whatss a binary tree what is a binary treee binarry tree tree binary binary treee binary tree in ds binary tree is which structure binart tree what does a binary tree does trees binary what s binary tree what a binary tree what is binary tree what's a binary tree what does a binary tree do binary treed What are Binary trees? binnary tree binay tree binsary tree Binary tree. treeset binary treec treeSet structure binary tree What is a binary tree? binary tree algorithm binary tree meaning binary tree structure .What is Binary Trees? trees set binary tree definition what is a binary tree binary tree tree what is the binary tree binary tree code treeset ? tree binary tree tree binary tree wiki what is a binary tree used for which is binary tree binary binary tree binary trees bst tree what is binary tree binary tree what is treeset used for TreeSet. what does treeset do what is a treeSet treeset package in java is treeset sorted treesetjava documentation treeset example java java tree set api TreeSet metods treeset java oracle treeset methods in java treeset ajva tree set java extend sorted set treeset constructors jav treeset next lowest default treeset java treeset with values java all treeset methods in java tree set? Java when to specify types for treeset treeset java amount of members treeset example in java treeset get element treeset first can integer be added to tree set treeset new set treeset methods java tree set treeset methods tree set java tree set methods treeset en java java TreeSets java tree set treeset in java java Treesets and java treeset treeset java treeset
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source