Midterm Review2.4

Midterm Review2.4 - Additional Methods of the Adaptable...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Additional Methods of the Adaptable Priority Queue ADT remove(e): Remove from P and return entry e. replaceKey(e,k): Replace with k and return the old key; an error condition occurs if k is invalid (that is, k cannot be compared with other keys). replaceValue(e,x): Replace with x and return the old value. CSE 2011 Prof. J. Elder - 66 - Last Updated: 1/7/10 10:14 AM Locating Entries In order to implement the operations remove(k), replaceKey(e), and replaceValue(k), we need fast ways of locating an entry e in a priority queue. We can always just search the entire data structure to find an entry e, but there are better ways for locating entries. CSE 2011 Prof. J. Elder - 67 - Last Updated: 1/7/10 10:14 AM Location-Aware Entries A locator-aware entry identifies and tracks the location of its (key, value) object within a data structure CSE 2011 Prof. J. Elder - 68 - Last Updated: 1/7/10 10:14 AM Maps A map models a searchable collection of key-value entries The main operations of a map are for searching, inserting, and deleting items Multiple entries with the same key are not allowed Applications: address book student-record database CSE 2011 Prof. J. Elder - 69 - Last Updated: 1/7/10 10:14 AM The Map ADT Map ADT methods: get(k): if the map M has an entry with key k, return its associated value; else, return null put(k, v): insert entry (k, v) into the map M; if key k is not already in M, then return null; else, return old value associated with k remove(k): if the map M has an entry with key k, remove it from M and return its associated value; else, return null size(), isEmpty() keys(): return an iterator of the keys in M values(): return an iterator of the values in M entries(): returns an iterator of the entries in M CSE 2011 Prof. J. Elder - 70 - Last Updated: 1/7/10 10:14 AM ...
View Full Document

This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

Ask a homework question - tutors are online