// Syed Rais AHmad //Assignment # 9 Answ 5. #include "stdafx.h" #include //#include "LinkList.cpp" class llNode { public: int key; int field; llNode * nxtNode; }; //link list class lList { private: llNode * head; public: lList(); ~lList(); bool Search(int); void Insert(int,int); int getall(); }; //create head and put NULL values in it. lList::lList() { head = new llNode; head->nxtNode=NULL; head->key=NULL; head->field=NULL; } //Destroy/free list/memory lList::~lList() { delete head; } //Search of a key in link list. bool lList::Search(int k) { llNode * ptr=head; while(ptr=ptr->nxtNode) { if (ptr->key==k) return true; } return false; } //Insert to the tail of link list void lList::Insert(int key,int rec) { llNode * ptr=head; while(ptr->nxtNode) ptr=ptr->nxtNode; ptr->nxtNode=new llNode; ptr=ptr->nxtNode; ptr->key=key; ptr->field=rec; ptr->nxtNode=NULL; } //print all values in the link list. int lList::getall() { llNode * ptr=head; while (ptr=(ptr->nxtNode)) cout << ptr->key << "\n"; return NULL; } class Table { private: lList rec[12]; public: bool SInsert(int,int); Table(); }; Table::Table() { } bool Table::SInsert(int k,int r) { int j=k%11; if (!rec[j].Search(k)) {rec[j].Insert(k,r);return false;} else return true; } int main() { Table t; cout << t.SInsert(2,23); cout << t.SInsert(13,2); cout << t.SInsert(13,99); cout << t.SInsert(11,9); cout << t.SInsert(11,67); return 0; }