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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

542 Chap. 16 Patterns of <strong>Algorithm</strong>s/** Insert a record in<strong>to</strong> the skiplist */public void insert(Key k, E newValue) {int newLevel = r<strong>and</strong>omLevel(); // New node’s levelif (newLevel > level)// If new node is deeperAdjustHead(newLevel); // adjust the header// Track end of levelSkipNode[] update =(SkipNode[])new SkipNode[level+1];SkipNode x = head; // Start at header nodefor (int i=level; i>=0; i--) { // Find insert positionwhile((x.forward[i] != null) &&(k.compareTo(x.forward[i].key()) > 0))x = x.forward[i];update[i] = x;// Track end at level i}x = new SkipNode(k, newValue, newLevel);}for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!