/* ----------------------------------------------------------------------------- Prints a table. Returns: (int) 1 if table is output as requested 0 if memory for sorted table could not be allocated. ----------------------------------------------------------------------------- */ bool HashTable::printSorted(FILE *fp) const { ListObject **OutTab; ListObject *obj; int i; int cnt = countObjects(); OutTab = getLinearList(); if (OutTab==NULL) return false; sort(OutTab); printHeading(fp); for (i = 0; i < cnt; i++) { obj = OutTab[i]; fprintf(fp, "%3d ", i); if (obj) obj->print(fp); else fputs("????", fp); fputs("\n",fp); } delete[] OutTab; return true; }
bool HashTable::printUnsorted(FILE *fp) const { ListObject *obj; int i, j; printHeading(fp); for (j = i = 0; j < sz; j++) { for (obj = tbl[j]; obj; obj = obj->getNext()) { fprintf(fp, "%3d ", i); if (obj) obj->print(fp); else fputs("?????", fp); fprintf(fp, "\n"); i++; } } return true; }
// Example socket reader // Wait for receiving SimpleObject and ListObject void runAS_Socket(int port=8000, bool print=true) { int sock=(int)(new TCPReceiver(port))->connect(); if (sock==SOCKET_ERROR) return; BinarySocketReader bsr(sock); // Receive SimpleObject SimpleObject *so; if(AS_FAILED(bsr.read((ISerializable**)&so))) std::cout << "Error at receiving SimpleObject" << std::endl; // Receive List ListObject *lo; if(AS_FAILED(bsr.read((ISerializable**)&lo))) std::cout << "Error at receiving ListObject" << std::endl; std::cout << "Sucessfull receive of SimpleObject and ListObject" << std::endl; if (print) { so->print(); lo->print(); } }