Sunday, 15 May 2011

java - Binary Search Tree In-Order Traversal to a new array -


I have traveled in a BST sequence while printing workout as a workout, but the task was to add a The new list contains ...

I tried to do this by creating a list outside the law and adding the array [i] to the list, by increasing the value 'x', but I have a NullPointerException

  int [] bstArray; Int x = 0; Public int [] Return InOrderTraversal (BSTNode node) {if (node ​​== tap) bstArray back; If (node ​​.getLeftChild ()! = Null) {returnInOrderTraversal (node.getLeftChild ()); } BstArray [x] = node.getValue (); X ++; If (node ​​.getRightChild ()! = Null) {returnInOrderTraversal (node.getRightChild ()); } Return bstArray; }  

thanks

  int [] bstArray; & Lt;     > Int [] bstArray = new bstArray [someLength]; & Lt; ------- In this way use bstArray [x] = node.getValue ();  

No comments:

Post a Comment