예제 #1
0
int main(){
  int i=0;
  
  LinkedList l;

  for(i=0;i<30;i++){
    l.Push(i);
  }

  printf("Popping: %d\n", l.Pop());
  printf("Popping: %d\n", l.Pop());
  printf("Popping: %d\n", l.Pop());

  printf("Pushing 203\n");
  l.Push(203);  
  printf("Appending 67\n");
  l.Append(67);  
  printf("Popping: %d\n", l.Pop());
  printf("Copying list to a new list\n");

  LinkedList l2;
  l2=l;
  printf("Testing copy constructor\n");
  LinkedList l3=l2;
  return 0;
}
예제 #2
0
/********************************************************************************
 * int main():
 * 	Purpose: 
 * 		main test program for this class
 * 		- creates a list
 * 		- appends the numbers 0-9 to it
 * 		- prepends the numbers -9 to 0
 * 		- displays what the list looks like
 * 		- removes one of the 0's
 * 		- displays the list backwards
 * 		- clears the list
 * 		- appends 9001 and -1000 to the now empty list
 * 		- inserts a 500 before the number -1000
 * 		- inserts a 360 after the number 9001
 * 		- displays the list
 * 		- calls oldLoop()
 * 		- destructs all nodes in the list
 * 	
 * 	Entry: 
 * 		nothing really
 * 	
 * 	Exit: 
 * 		should display output that makes sense with that ^^^
 * 	
 ********************************************************************************/
int main()
{
	//create a new empty list
	LinkedList<int> myList;

	//append the numbers 0 through 9 to the end of the list
	// (uses LinkedList::Append())
	for(int i=0; i<10; i++)
		myList.Append(i);

	//prepend the numbers -9 to 0 to the start of the list
	// (uses LinkedList::Prepend())
	for(int i=0; i<10; i++)
		myList.Prepend(-i);

	//display the list (front to back)
	cout << myList << endl;

	//remove the first 0 in the list
	delete &myList.Extract(0);

	//display the list (back to front)
	backDisp(cout, myList) << endl;

	//clear the list 
	myList.Purge();

	//add the numbers 9001 and -1000 to the list
	myList.Append(9001);
	myList.Append(-1000);

	//insert the number 500 after -1000
	myList.InsertBefore(-1000, 500);

	//insert the number 360 after 9001
	myList.InsertAfter(9001, 360);

	//show the list
	cout << myList << endl;
	oldLoop();

}
예제 #3
0
bool component::FindShapeInHierarchy(shape *s, LinkedList<shape *> sList)
{
	sList.Append(this);
	if (s == this)
		return true;

	for (int i = 0; i < nInst; i++)
		if (instances[i]->FindShapeInHierarchy(s, sList))
			return true;
	
	sList.RemoveLast();
	return false;
}
예제 #4
0
/********************************************************************************
 * void oldLoop():
 * 	Purpose: 
 * 		some code I first used to test the class
 * 		called oldLoop() because it is older than the current main()
 * 	
 * 	Entry: 
 * 		nothing
 * 	
 * 	Exit: 
 * 		(verbosely states what it is doing)
 * 		- creates a list
 * 		- appends the numbers 9000-9009 to it
 * 		- creates a copy of the list with the assignment operator =
 * 		- attempts to insert the number 9020 after 9002
 * 		(throws error if 9002 isn't in there for some reason)
 * 		- prints the contents of the first list with an iterator for loop
 * 		- prints the contents of the copy with another iterator based loop
 * 		- says if isEmpty() actually knows that the list is empty
 * 		- (implicitly) calls destructor on list, destroying all nodes
 * 	
 ********************************************************************************/
void oldLoop()
{
	//create an empty list
	cout << "creating list" << endl;
	LinkedList<int> myList;

	//append the numbers 9000-9009 to it
	cout << "appending ints" << endl;
	for(int i=9000; i<9010; i++)
		myList.Append(i);

	//make a copy of it using operator=
	cout << "creating copy" << endl;
	LinkedList<int> listCopy;
	listCopy=myList;

	try 
	{
		//insert the number 9020 after 9002
		listCopy.InsertAfter(9002, 9020);
	}
	catch (Exception e)
	{
		cout << "Error: " << e << endl;
	}


	//print the list and its copy
	cout << "printing the contents" << endl;
	for( auto it = myList.Begin(); it.isValid(); ++it)
		cout << *it << endl;

	for( auto it = listCopy.Begin(); it.isValid(); ++it)
		cout << "copy: " << *it << endl;

	//check if the list is empty
	cout << "checking if list is empty" << endl;
	cout << "List is " << (myList.isEmpty() ? "" : "not ") << "empty.\n";
}