#include #include "ListT.h" using namespace std; ListT::ListT(){ size = 0; current = 0; capacity = 10; data = new int[capacity]; cout << "In the Constructor " << endl; } ListT::ListT(const ListT & other) { size_t i; size = other.size; current = other.current; capacity = other.capacity; data = new int[capacity]; for(i=0; i< size; i++) { data[i] = other.data[i]; } } ListT::~ListT() { delete [] data; data = nullptr; capacity = 0; cout << "In the destructor" << endl; } ListT & ListT::operator =(const ListT & other){ // worry about a = a; if (this != &other) { size_t i; size = other.size; current = other.current; capacity = other.capacity; delete [] data; data = new int[capacity]; for(i=0; i< size; i++) { data[i] = other.data[i]; } } return *this; } bool ListT::IsEmpty(void) const{ return size==0; } bool ListT::IsFull(void) const{ return false; } size_t ListT::Length(void) const{ return size; } size_t ListT::Find(int key) const { size_t pos=0; bool found = false; while(pos < size and not found) { if (data[pos] == key) { found = true; } else { pos ++; } } return pos; } bool ListT::IsPresent(int key) const{ size_t pos; pos = Find(key); return pos != size; } void ListT::Delete(int key){ bool found; size_t pos = Find(key); found = pos < size; while (found and pos < size-1) { data[pos] = data[pos+1]; pos++; } if (found) { size--; current = 0; } } void ListT::Insert(int key){ int * tmp = nullptr; size_t i; if (size >= capacity) { capacity *= 2; tmp = new int[capacity]; for(i=0; i < size; i++) { tmp[i] = data[i]; } delete [] data; data = tmp; } data[size] = key; size++; } void ListT::Reset(void){ current = 0; } bool ListT::HasNext(void) const{ return current < size; } void ListT::Next(void){ if (current < size) { current ++; } } int ListT::GetItem(void) const{ int rv = 0; if (current < size) { rv = data[current]; } return rv; }