Esempio n. 1
0
int main()
{
   ListArray<CD>* cds = CD::readCDs("cds.txt");
   int num_items = cds->size();
   cout << num_items << endl;

   TableSortedList<CD>* slt = new TableSortedList<CD>(&CD::compare_items, &CD::compare_keys);

   //DO THIS
   //thoroughly test your table

   ListArrayIterator<CD>* iter = cds->iterator();
   
   
	if(slt->tableIsEmpty())
	{
		int count = 0;
		while(iter->hasNext())
		{
		CD* cd = iter->next();
		slt->tableInsert(cd);
		count++;
		}
	}

	ListDoublyLinkedIterator<CD>* iter2 = slt->iterator();
	
	/*while(iter2->hasNext())
	{
		CD* myCD = iter2->next();
		myCD->getKey()->displayString();
		cout << endl;
		
	}*/

	String* title = new String("Manifesto");
	
	
	bool rem = slt->tableRemove(title);
	if (rem)
		cout << "Removed item" << endl << endl;
	
	while(iter2->hasNext())
	{
		CD* myCD = iter2->next();
		myCD->getKey()->displayString();
		cout << endl;
	}
	
	cout << endl;
	cout << slt->tableSize() << endl;
	
	delete title;
   deleteCDs(cds);
   delete cds;
   delete slt;
   return 0;
}
Esempio n. 2
0
int main()
{
   ListArray<CD>* cds = CD::readCDs("cds.txt");
   int num_items = cds->size();
   cout << num_items << endl;

   TableSortedList<CD>* slt = new TableSortedList<CD>(&CD::compare_items, &CD::compare_keys);

   //DO THIS
   //thoroughly test your table
   
      ListArrayIterator<CD>* iter = cds->iterator();
	  
	 String* titles[310]; 
	 CD* cds2[310];
	 int count = 0; 
	 
	 CD* duplicateTest; // test duplicate CD to be added later
	 
   while(iter->hasNext())
   {
      CD* cd = iter->next();
	  duplicateTest = cd;
	  
	  cds2[count]=cd;
	  titles[count]=cds2[count]->getKey();
	  count++;
	  
      slt->tableInsert(cd);
   }
   delete iter;
   
   slt->tableInsert(duplicateTest); // Program should not insert this CD because it is a duplicate
   
   cout << "Table size after inserting all CDs is " << slt->tableSize() << endl;	// If insert works correctly, size should be 310 (If duplicate was added, it would be 311)

   for(count = 0; count < 310; count++)
   {
	CD* cdRetrieve = slt->tableRetrieve(titles[count]);	// testing the retrieve function, it should be able to find all 310 CDs
	if (cdRetrieve == NULL)
	cout << "Couldn't find CD" << endl;
	else
	cout << "Found CD #" << count+1 << endl;
   }
	

   
   count = 1;
   
   ListDoublyLinkedIterator<CD>* iter2 = slt->iterator();	// Testing the SLDL iterator, every CD should be displayed
   
   while(iter2->hasNext())
   {
   CD* cd3 = iter2->next();

   cout << "\nThis is CD #" << count << ":" << endl << endl;
   count++;
   
   cd3->displayCD();
   }
   
   for(int i = 0; i < 310; i++)
   {
   slt->tableRemove(titles[i]);
   }
   
   	cout << "Table size after removing all CDs is " << slt->tableSize();	// Table size should be 0 after removing everything


   deleteCDs(cds);
   delete cds;
   delete slt;
   return 0;
}