int main(){ long int Hash; int size; Player* e1 = new Player("mad", "king",1, 220, 7, 5, 5); Player* e2 = new Player("forrest", "troll", 3, 400, 4, 4, 9); Player* e3 = new Player("lame", "donkey", 1, 40, 2, 2, 2); Item* i2 = new Item("Eye of the beast", "The Eye of the beast slain at the river"); DLinkedList<Player>* enemyList = new DLinkedList<Player>; enemyList->Append(*e1); enemyList->Append(*e2); enemyList->Append(*e3); refreshScreen(); string filename; string mArray[5]; mArray[0] = "hurr durr"; //battle(); menu(); }
void printList(DLinkedList<int> &list) // This function outputs what the current list is { std::cout << "The current list is: "; list.print(); // retrieve list std::cout << std::endl << std::endl; }
void addList(DLinkedList<int> &list, int size) // This function adds a given number of items to the list { printList(list); // print the current list for (int i = 0; i < size; i++) // cycle adding to list { list.addFront(i); // add an item to list printList(list); // print the current list } }
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(); } }
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 }
int main() { DLinkedList<string> Dl; Dl.addFront("World"); Dl.addFront("Hello"); Dl.addBack("It's a"); Dl.addBack("C++ Prog"); Dl.addBack("Doubly linkedlist"); Dl.printList(); cout<<endl<<endl; Dl.reverse(Dl); Dl.printList(); cout<<endl<<endl; Dl.removeFront(); Dl.removeBack(); Dl.printList(); cout<<endl<<endl; return 0; }
void LLTest() { // default constructor, InsertFront, InsertBack, ElementAt DLinkedList<int> lla; lla.InsertFront(5); lla.InsertBack(10); cout << "lla contains " << lla.ElementAt(0) << " at index 0." << endl; // copy constructor, InsertAt, RemoveAt (with exception) DLinkedList<int> llb(lla); llb.InsertAt(7, 1); try { int temp = llb.RemoveAt(12345); } catch (exception e) { cout << "Exception in RemoveAt(): " << e.what() << endl; } // assignment operator, IsEmpty, Size, RemoveDuplicates, Contains DLinkedList<int> llc; if (llc.IsEmpty()) cout << "llc is empty." << endl; else cout << "llc is not empty." << endl; llc = lla; llc.InsertBack(13); llc.InsertBack(13); llc.InsertBack(13); cout << "llc contains " << llc.Size() << " items." << endl; llc.RemoveDuplicates(); if (llc.Contains(10)) cout << "10 found in llc." << endl; else cout << "10 not found in llc." << endl; if (llc.Contains(13)) cout << "13 found in llc." << endl; else cout << "13 not found in llc." << endl; }