Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void goLeft() {
- if(!currentNode.isEmpty()) {
- stack.push(currentNode);
- currentNode = currentNode.left;
- }
- }
- public void goUp() {
- if(!stack.isEmpty()) {
- currentNode = stack.pop();
- }
- }
- public void goRoot() {
- while(!stack.isEmpty()){
- currentNode = stack.pop();
- }
- }
- public void remove() {
- if(!stack.isEmpty() && currentNode.NodeType!=DOUBLE){ //Si la pile n'est pas vide et que le noeud courrant n'est pas double
- //CAS 1 : Le noeud a supprimer est une feuille
- if(currentNode.NodeType==LEAF){
- if (stack.peek().left==currentNode){
- goUp();
- currentNode.left=nul;
- } else {
- goUp();
- currentNode.right=nul;
- }
- } else {
- //CAS 2 : Le noeud a supprimer a un fils (gauche ou droite)
- if (stack.peek().right==currentNode){
- if(currentNode.left!=nul){
- goLeft();
- stack.pop();
- stack.peek().right=currentNode;
- } else {
- goRight();
- stack.pop();
- stack.peek().right=currentNode;
- }
- } else {
- if(currentNode.left!=nul){
- goLeft();
- stack.pop();
- stack.peek().left=currentNode;
- } else {
- goRight();
- stack.pop();
- stack.peek().left=currentNode;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement