Advertisement
Guest User

Untitled

a guest
May 26th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public Node<E> addChild(Node<E> node, E elem)
  2. {
  3. SLLNode<E> tmp = new SLLNode<E>(elem);
  4. SLLNode<E> curr = (SLLNode<E>) node;
  5.  
  6. SLLNode<E> t = curr.firstChild;
  7. SLLNode<E> pret = null;
  8.  
  9. while(t != null)
  10. {
  11. if(t.info.compareTo(elem) > 0)
  12. {
  13. break;
  14. }
  15.  
  16. pret = t;
  17. t = t.sibling;
  18. }
  19.  
  20. if(pret == null)
  21. {
  22. tmp.sibling = curr.firstChild;
  23. curr.firstChild = tmp;
  24. }
  25. else
  26. {
  27. pret.sibling = tmp;
  28. tmp.sibling = t;
  29. }
  30.  
  31. tmp.parent = curr;
  32. return tmp;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement