Gary D. Brown
CIS 11: Data Structures and Algorithms
Fall 2006

Section 0502

Tuesdays & Thursdays 10:30 am to 12:00 pm

Room 2928

Dynamic Keyed Bag Hints

#include <iostream>
using namespace std;

class Test {
  public:
    typedef double value_type;
    typedef int key_type;
    Test(size_t n) {
      record = new record_type[n]; }
    void setKey(size_t r, key_type k) {
      record[r].key = k; }
    key_type getKey(size_t r) const {
      return record[r].key; }
    void setData(size_t r, value_type d) {
      record[r].data = d; }
    value_type getData(size_t r) const {
      return record[r].data; }
  private:
    class record_type {
      public:
        key_type key;
        value_type data; }
    * record;
};

int main() {
  Test t(10);
  t.setKey(0, 2000);
  t.setData(0, 2);
  cout << "Key: " << t.getKey(0) << " Data: " << t.getData(0) << endl;
  //cout << t.record[0].key; Can't do that!
}

2006/09/27