Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void insert(T val) {
- if (this.head == null){
- this.head = new Leave<T>(val);
- this.head.setAsHead();
- } else {
- Leave<T> current = this.head;
- int c = 0;
- while(c == 0)
- {
- T cv = current.getValue();
- if (current.haveChildrens())
- {
- Leave<T> L = current.getLeave_L();
- Leave<T> R = current.getLeave_R();
- if (L != null)
- {
- if (L.getValue().CompareTo(cv) < 0)
- {
- current = L;
- }
- }
- else if (R != null)
- {
- if (R.getValue().CompareTo(cv) < 0)
- {
- current = R;
- }
- }
- }
- else {
- int comp = val.CompareTo(cv);
- if (comp < 0)
- {
- current.setLeave_L(val);
- }
- else
- {
- current.setLeave_R(val);
- }
- c++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement