12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 10.5 B-Trees 373/** Add a new key/value pair <strong>to</strong> the node. There might be asubtree associated with the record being added. Thisinformation comes in the form of a 2-3 tree node withone key <strong>and</strong> a (possibly null) subtree through thecenter pointer field. */public TTNode add(TTNode it) {if (rkey == null) { // Only one key, add hereif (lkey.compareTo(it.lkey()) < 0) {rkey = it.lkey(); rval = it.lval();right = center; center = it.cchild();}else {rkey = lkey; rval = lval; right = center;lkey = it.lkey(); lval = it.lval();center = it.cchild();}return this;}else if (lkey.compareTo(it.lkey()) >= 0) { // Add leftcenter = new TTNode(rkey, rval, null, null,center, right, null);rkey = null; rval = null; right = null;it.setLeftChild(left); left = it;return this;}else if (rkey.compareTo(it.lkey()) < 0) { // Add centerit.setCenterChild(new TTNode(rkey, rval, null,null, it.cchild(), right, null));it.setLeftChild(this);rkey = null; rval = null; right = null;return it;}else { // Add rightTTNode N1 = new TTNode(rkey, rval, null,null, this, it, null);it.setLeftChild(right);right = null; rkey = null; rval = null;return N1;}}Figure 10.15 The 2-3 tree node add method.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!