Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1.  
  2. public void goLeft() {
  3. if(!currentNode.isEmpty()) {
  4. stack.push(currentNode);
  5. currentNode = currentNode.left;
  6. }
  7. }
  8.  
  9. public void goUp() {
  10. if(!stack.isEmpty()) {
  11. currentNode = stack.pop();
  12. }
  13. }
  14.  
  15. public void goRoot() {
  16. while(!stack.isEmpty()){
  17. currentNode = stack.pop();
  18. }
  19. }
  20.  
  21. public void remove() {
  22. if(!stack.isEmpty() && currentNode.NodeType!=DOUBLE){ //Si la pile n'est pas vide et que le noeud courrant n'est pas double
  23.  
  24. //CAS 1 : Le noeud a supprimer est une feuille
  25. if(currentNode.NodeType==LEAF){
  26. if (stack.peek().left==currentNode){
  27. goUp();
  28. currentNode.left=nul;
  29. } else {
  30. goUp();
  31. currentNode.right=nul;
  32. }
  33.  
  34. } else {
  35.  
  36. //CAS 2 : Le noeud a supprimer a un fils (gauche ou droite)
  37. if (stack.peek().right==currentNode){
  38. if(currentNode.left!=nul){
  39. goLeft();
  40. stack.pop();
  41. stack.peek().right=currentNode;
  42. } else {
  43. goRight();
  44. stack.pop();
  45. stack.peek().right=currentNode;
  46. }
  47. } else {
  48. if(currentNode.left!=nul){
  49. goLeft();
  50. stack.pop();
  51. stack.peek().left=currentNode;
  52. } else {
  53. goRight();
  54. stack.pop();
  55. stack.peek().left=currentNode;
  56. }
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement