11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

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

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

134 Chap. 4 Lists, Stacks, <strong>and</strong> Queues/** A simple payroll entry with ID, name, address fields */class Payroll {}priv<strong>at</strong>e Integer ID;priv<strong>at</strong>e String name;priv<strong>at</strong>e String address;/** Constructor */Payroll(int inID, String inname, String inaddr) {ID = inID;name = inname;address = inaddr;}/** <strong>D<strong>at</strong>a</strong> member access functions */public Integer getID() { return ID; }public String getname() { return name; }public String getaddr() { return address; }Figure 4.30 A payroll record implement<strong>at</strong>ion.// IDdict organizes Payroll records by IDDictionary IDdict =new UALdictionary();// namedict organizes Payroll records by nameDictionary namedict =new UALdictionary();Payroll foo1 = new Payroll(5, "Joe", "Anytown");Payroll foo2 = new Payroll(10, "John", "Mytown");IDdict.insert(foo1.getID(), foo1);IDdict.insert(foo2.getID(), foo2);namedict.insert(foo1.getname(), foo1);namedict.insert(foo2.getname(), foo2);Payroll findfoo1 = IDdict.find(5);Payroll findfoo2 = namedict.find("John");Figure 4.31 A dictionary search example. Here, payroll records are stored intwo dictionaries, one organized by ID <strong>and</strong> the other organized by name. Bothdictionaries are implemented with an unsorted array-based list.

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

Saved successfully!

Ooh no, something went wrong!