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.

112 Chap. 4 Lists, Stacks, <strong>and</strong> Queuespublic void moveToStart(){ curr = head; }public void moveToEnd(){ curr = tail; }// Set curr at list start// Set curr at list end// Move curr one step left; no change if already at frontpublic void prev() {if (curr == head) return; // No previous elementLink temp = head;// March down list until we find the previous elementwhile (temp.next() != curr) temp = temp.next();curr = temp;}// Move curr one step right; no change if already at endpublic void next(){ if (curr != tail) curr = curr.next(); }public int length() { return cnt; } // Return length// Return the position of the current elementpublic int currPos() {Link temp = head;int i;for (i=0; curr != temp; i++)temp = temp.next();return i;}// Move down list <strong>to</strong> "pos" positionpublic void moveToPos(int pos) {assert (pos>=0) && (pos

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

Saved successfully!

Ooh no, something went wrong!