// defines.cpp where we gradually add definitions // as we switch to new and different main() clients. // by RPF for mp#3, 5/24/2000 #include "mp3Header.h" // first, define the node constructor for main2 Node::Node(int k, string nf){ key = k; info = nf; } // THIS BEGINS THE SECTION FOR MAIN3 // for main3, add a Node print(): void Node::print(){ cout << "node key= " << key << " info= " << info << endl; } // Linked list items for main3. Each hash array element is a pointer to // a LinkedList item which in turn points to the Node items // in the chain. LinkedList::LinkedList() { length = 0; head = 0; // null header } // Below, we insert at the head, no questions asked. void LinkedList::insertNode(Node* nd){ Node* tempnode = head; // grab the pointer since we'll change it head = nd; // point to inserted node nd->next = tempnode ; // and have it point to previous one // and don't forget to update the length: length++; } // Also for main3, once we insert a few, would be good to print // out the chain to make sure they're all there, so we define // print() for a LinkedList item. void LinkedList::print(){ Node* nd = head; while(nd != 0){ nd->print(); nd = nd->next;} } // THIS BEGINS THE SECTION ON HASHING FOR MAIN4 // The world's simplest hash function int HashTable::hash(int key) { return 0;} // The constructor puts a new LinkedList item in each array position. HashTable::HashTable(){ for(int i=0; i < SIZE; i++) arrayH[i]= new LinkedList(); } // Let's define insert for the hash table. Shouldn't be hard, // since we have insert(Node*) for LinkedList. void HashTable::insertH(Node* nd) { int index = hash(nd->key); cout << "key in node to be inserted is: " << nd->key << "\n"; cout << "and index should be zero: " << hash(nd->key) << "\n"; // SKIP INSERT FOR THE MOMENT arrayH[index]->insertNode(nd); }