Beispiel #1
0
	int HashTable::countObjects() const
	{
		int i,j;
		int cnt;
		ListObject *obj;

		for (cnt = j = i = 0; i < sz; i++) {
			for (obj = tbl[i]; obj; obj = obj->getNext())
				cnt++;
		}
		return cnt;
	}
Beispiel #2
0
	ListObject *HashTable::find(ListObject *item) const
	{
		ListObject *p;
		ListObject *s;
		int ii = 0;

		s = *getChain(item);
		for (p = *getChain(item); p && item->cmp(p); p = p->getNext()) {
			if (p==s)
				if (ii > 0)
					throw "Stuck in loop.";
				else
					ii++;
		}
		return p;
	}
Beispiel #3
0
	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;
	}