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.

142 Chap. 4 Lists, Stacks, <strong>and</strong> Queues// A simple payroll entry with ID, name, address fieldsclass Payroll {}private Integer ID;private String name;private String address;// Construc<strong>to</strong>rPayroll(int inID, String inname, String inaddr) {ID = inID;name = inname;address = inaddr;}// <strong>Data</strong> member access functionspublic Integer getID() { return ID; }public String getname() { return name; }public String getaddr() { return address; }Figure 4.28 A payroll record implementation.// IDdict organizes Payroll records by IDDictionary IDdict =new UALdictionary();// namedict organizes Payroll records by nameDictionary namedict =new UALdictionary();Payroll foo1 = new Payroll(5, "Joe", "Any<strong>to</strong>wn");Payroll foo2 = new Payroll(10, "John", "My<strong>to</strong>wn");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.29 A dictionary search example. Here, payroll records are s<strong>to</strong>red 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!