diff options
Diffstat (limited to 'Homework8/MyStructures/ContactList.hpp')
| -rw-r--r-- | Homework8/MyStructures/ContactList.hpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/Homework8/MyStructures/ContactList.hpp b/Homework8/MyStructures/ContactList.hpp index bc2240f..b324064 100644 --- a/Homework8/MyStructures/ContactList.hpp +++ b/Homework8/MyStructures/ContactList.hpp @@ -28,7 +28,7 @@ namespace MyStructures void Prepend(const C& data); //add contact as the first item void RemoveLast(); //remove last void RemoveFirst(); //remove first - void Extract(const C& data); //delete this data + void Extract(const C& data); //delete this data, slash collecting its data void InsertAfter(const C& data, const C& after); //Insert contact data after 'after' void InsertBefore(const C& data, const C& before); //Insert contact data before 'before' void Clear(); //deletes all contacts, empties list, nothing left @@ -209,11 +209,6 @@ namespace MyStructures if (Empty()) { - if (contacts_ == nullptr) - { - - } - Append(data); size_++; return; @@ -285,6 +280,10 @@ namespace MyStructures template<class C> void ContactList<C>::InsertAfter(const C& data, const C& after) { + if (Empty()) return; + + //if full, double size + } template<class C> void ContactList<C>::InsertBefore(const C& data, const C& before) @@ -319,27 +318,41 @@ namespace MyStructures template<class C> inline C ContactList<C>::Last() const { - return C(); + return contacts_[size_-1]; } template<class C> inline C& ContactList<C>::First() { + return contacts_[0]; // TODO: insert return statement here } template<class C> inline C ContactList<C>::First() const { - return C(); + return contacts_[0]; } template<class C> inline C& ContactList<C>::operator[](const int& index) { + if (index < 0 || index >= static_cast<int>(length_)) + { + Contact EmptyContact; + cout << "The index exceeds the array length!!" << endl; + return EmptyContact; + } + return contacts_[index]; // TODO: insert return statement here } template<class C> inline C ContactList<C>::operator[](const int& index) const { - return index; + if (index < 0 || index >= static_cast<int>(size_)) + { + cout << "The index exceeds the array length!!" << endl; + return NULL; + } + + return contacts_[index]; } template<class C> inline ContactList<C>::operator bool() const |