Exemple #1
0
void DLinkedList<E>::reverse(DLinkedList& L)
{
    DLinkedList T;
    while(!L.empty())
    {
        string s=L.front();
        T.addFront(s);
        L.removeFront();
    }
    while(!T.empty())
    {
        string s= T.front();
        L.addBack(s);
        T.removeFront();
    }
}
Exemple #2
0
int main()
// The main function will run through the test cases as outlined in the 
// attached assignment documentation
{
	DLinkedList<int> list;					// initialize the list
	int size = 5;							// initialize a size
	int testCase = 1;						// initialize test cases

	std::cout << "Creating initial list... "
		<< std::endl << std::endl;			// create the list
	addList(list, size);

	for (int i = -1; i <= size; i++)		// run through first 6 test cases
	{
		printTest(testCase);				// inform us of which test case
		testCase++;							// increment test case
		list.swap(i);						// attempt to swap items
		printList(list);					// print the current list
	}

	std::cout << "Emptying list... "
		<< std::endl << std::endl;			// delete the contents of the list
	while (!list.empty())					// check for an empty list
	{
		list.removeFront();				// remove front item from list
		printList(list);				// print out current list
	}

	int i = 1;								// initialize counter
	while (i <= 2)							// run final two test cases
	{
		printTest(testCase);				// inform us of which test case
		testCase++;							// increment test case
		list.swap(0);						// try to swap the lead element
		list.addFront(i);					// add an item to the list
		printList(list);					// print the current list
		i++;								// increment counter
	}

	return EXIT_SUCCESS;					// exit successfully
}