예제 #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
	for(int c = 0; c < num_items; c++)
	{
		slt->tableInsert(cds->get(c+1));
	}
	
	displayTitles(slt);





   deleteCDs(cds);
   delete cds;
   delete slt;
   return 0;
}
예제 #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();
   
   
	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;
}
예제 #3
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>* addCDs = cds->iterator();
   while (addCDs->hasNext())
   {
	   slt->tableInsert(addCDs->next());
   }
   cout << "\nSize after adding CDs: " << slt->tableSize() << endl;
   
   String* sk = new String("Omnivium");
   cout << "Retrieving " << "Omnivium" << "..." << endl;
   slt->tableRetrieve(sk)->displayCD();
   
   cout << "\nSize after retrieval: " << slt->tableSize() << endl;
   
   cout << "\n\nRemoving " << "Omnivium" << "..." << endl;
   bool isDelete = slt->tableRemove(sk);
   cout << "Successful? ";
   if (isDelete) cout << "Yes";
   else cout << "No";
   
   
   sk = new String("Programmed To Consume");
   cout << "\n\nRemoving " << "Programmed to Consume" << "..." << endl;
   isDelete = slt->tableRemove(sk);
   cout << "Successful? ";
   if (isDelete) cout << "Yes";
   else cout << "No";
   
   cout << "\n\n\nSize after removal: " << slt->tableSize() << endl;
   
   sk = new String("My Little Pony Anthology");
   cout << "\n\nRemoving item not in table, " << "My Little Pony Anthology" << "..." << endl;
   isDelete = slt->tableRemove(sk);
   cout << "Successful? ";
   if (isDelete) cout << "Yes";
   else cout << "No";
   
   cout << "\n\n\nSize after removal: " << slt->tableSize() << endl;
   
   sk = new String("Back in Black");
   cout << "\n\nRetrieving item not in table, " << "Back in Black" << "..." << endl;
   
   
   cout << "\n\nInserting duplicates..." << endl;
   ListArray<CD>* cds2 = CD::readCDs("cds.txt");
   ListArrayIterator<CD>* addCDs2 = cds2->iterator();
   while (addCDs2->hasNext())
   {
	   slt->tableInsert(addCDs2->next());
   }
   
   //finished size should be 310 since removed CDs are re-added
   cout << "Size after inserting duplicates: " << slt->tableSize();
   
   cout << "\n\n\nIs the table empty? ";
   if (!slt->tableIsEmpty()) cout << "No";
   else cout << "Yes";
   
   cout << "\n\n\nRemoving all CDs..." << endl;
   slt->~TableSortedList(); //deconstruct ALL THE THINGS
   
   cout << "\n\nIs the table empty? ";
   if(!slt->tableIsEmpty()) cout << "No";
   else cout << "Yes";
   
   deleteCDs(cds);
   delete cds;
   delete slt;
   return 0;
}
예제 #4
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;
}