c# - Is it necessary to implement a BST with both keys and values? -
is necessary implement bst both keys , values? can implement bst has method calls such following, in make comparison @ each node of whether traversal should go left node or right node based upon v value:
public class bst<v> { public void insert(v value) { //implementation } public v remove(v value) { //implementation } //other methods }
or, can implement bst such has method calls following, in k keys comparing determination of whether traverse left node or right node:
public class bst<k key, v value> { public void insert(k key, v value) { //implementation } //which of following appropriate method signature? public v remove(k key) { //implementation } //or? public v remove(v value) { //implementation } //other methods }
not using key value fine. however, tree become immutable if this. modifying value no longer safe since imbalance tree. have enforce providing property getter node value.
Comments
Post a Comment