diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..8d7d026 --- /dev/null +++ b/main.cpp @@ -0,0 +1,56 @@ +/* + * + * kkamin8 + */ + +#include "linkedlist.h" +#include "variablearray.h" +#include <iostream> + +int main(int argc, char *argv[]) +{ + Collection *ll = new LinkedList(); + std::cout << "adding elements into linked list" << std::endl; + ll->add(7); + ll->add(12); + ll->add(21); + ll->add(33); + std::cout << "elements in ll: " << ((LinkedList *) ll)->print() << std::endl; + + std::cout << "element at zero is: " << (*ll)[0] << std::endl; + std::cout << "element at two is : " << (*ll)[2] << std::endl; + std::cout << "the size of ll is: " << ll->get_size() << std::endl; + std::cout << "does ll contain 33? " << (ll->contains(33) ? "Yes\n" : "No\n"); + std::cout << "does ll contain 999? " << (ll->contains(999) ? "Yes\n" : "No\n"); + + Collection *ll_copy = ll->copy(); + delete ll; + std::cout << "copy of ll contains: " << ((LinkedList *) ll_copy)->print() << std::endl; + + std::cout << std::endl << "adding elements into variable array" << std::endl; + Collection *arr = new VariableArray(); + arr->add(13); + arr->add(131); + arr->add(-23); + arr->add(99); + arr->add(45); + std::cout << "array contains: " << ((VariableArray *)arr)->print() << std::endl; + std::cout << "removing 22 and 131" << std::endl; + arr->remove(22); + arr->remove(131); + std::cout << "array contains: " << ((VariableArray *)arr)->print() << std::endl; + std::cout << "the size of array is: " << arr->get_size() << std::endl; + std::cout << "element at two is: " << (*arr)[2] << std::endl; + std::cout << "element at four is: " << (*arr)[4] << std::endl; + std::cout << "NOTE: -1 means out of bounds access" << std::endl; + + Collection *arr_copy = arr->copy(); + delete arr; + std::cout << "copy of va contains: " << ((VariableArray *) arr_copy)->print() << std::endl; + + delete ll_copy; + delete arr_copy; + + return 0; +} + |