diff options
| author | Yana Blashchishina <[email protected]> | 2024-03-11 19:50:23 -0700 |
|---|---|---|
| committer | Yana Blashchishina <[email protected]> | 2024-03-11 19:50:23 -0700 |
| commit | 2a72393c7c7f683c083153b75c578b4cc65f7ff0 (patch) | |
| tree | 47e24b6016dd0383737214a819eda47fa561068c /Homework 8/MyStructures/ContactList.hpp | |
| parent | errors (diff) | |
| download | homework-8-yanablash-2a72393c7c7f683c083153b75c578b4cc65f7ff0.tar.xz homework-8-yanablash-2a72393c7c7f683c083153b75c578b4cc65f7ff0.zip | |
promptinput undefined
Diffstat (limited to 'Homework 8/MyStructures/ContactList.hpp')
| -rw-r--r-- | Homework 8/MyStructures/ContactList.hpp | 94 |
1 files changed, 83 insertions, 11 deletions
diff --git a/Homework 8/MyStructures/ContactList.hpp b/Homework 8/MyStructures/ContactList.hpp index 3824a0e..f897b5d 100644 --- a/Homework 8/MyStructures/ContactList.hpp +++ b/Homework 8/MyStructures/ContactList.hpp @@ -1,5 +1,5 @@ -#ifndef CONTACT_LIST -#define CONTACT_LIST +#ifndef CONTACT_LIST_HPP +#define CONTACT_LIST_HPP #include <algorithm> @@ -66,7 +66,8 @@ namespace MyStructures template<class C> void ContactList<C>::ContactDelete(const size_t& elementNumber) { - contacts_[elementNumber].Delete(); + size_t index = elementNumber; + contacts_[index].Delete(); } template <class C> @@ -80,6 +81,11 @@ namespace MyStructures } + template<class C> + inline ContactList<C>::ContactList(size_t length) + { + } + template <class C> ContactList<C>::ContactList(const C* contacts, const size_t& length, const size_t size) { @@ -151,6 +157,7 @@ namespace MyStructures rhs.contacts_ = nullptr; } + return *this; } @@ -265,25 +272,88 @@ namespace MyStructures template <class C> void ContactList<C>::RemoveFirst() { + if (Empty()) return; + ContactDelete(0); + size_--; } template <class C> void ContactList<C>::Extract(const C& data) { + for (size_t i = 0; i < size_; ++i;) + { + if (contacts_[i] == data) + { + for (size_t j = i; j < size_ - 1; ++j) + { + } + ContactDelete(size_t - 1); + size_--; + return; + } + } } template<class C> inline void ContactList<C>::InsertAfter(const C& data, const C& after) { - + for (size_t i = 0; i < size_; ++i) { + if (contacts_[i] == after) { + if (size_ >= length_) { + + ContactList newContacts(length_ * 2); + newContacts.size_ = size_; + for (size_t j = 0; j < i + 1; ++j) { + newContacts.contacts_[j] = contacts_[j]; + } + newContacts.contacts_[i + 1] = data; + for (size_t j = i + 2; j < newContacts.size_; ++j) { + newContacts.contacts_[j] = contacts_[j - 1]; + } + *this = std::move(newContacts); + } + else { + for (size_t j = size_; j > i + 1; --j) { + contacts_[j] = contacts_[j - 1]; + } + contacts_[i + 1] = data; + size_++; + } + return; + } + } } template<class C> inline void ContactList<C>::InsertBefore(const C& data, const C& before) { - + for (size_t i = 0; i < size_; ++i) { + if (contacts_[i] == before) { + if (size_ >= length_) { + + ContactList newContacts(length_ * 2); + newContacts.size_ = size_; + for (size_t j = 0; j < i; ++j) { + newContacts.contacts_[j] = contacts_[j]; + } + newContacts.contacts_[i] = data; + for (size_t j = i + 1; j < newContacts.size_; ++j) { + newContacts.contacts_[j] = contacts_[j - 1]; + } + *this = std::move(newContacts); + } + else { + for (size_t j = size_; j > i; --j) { + contacts_[j] = contacts_[j - 1]; + } + contacts_[i] = data; + size_++; + } + return; + } + } } template <class C> @@ -304,13 +374,13 @@ namespace MyStructures template <class C> C ContactList<C>::Last() const { - return contacts_[size_]; + return contacts_[size_ - 1]; } template <class C> C& ContactList<C>::First() { - return contacts_[0]; + return contacts_[size_ - 1]; } template <class C> @@ -320,15 +390,16 @@ namespace MyStructures } template<class C> - inline C& ContactList<C>::operator[](const int& index) + C& ContactList<C>::operator[](const int& index) { if (index < 0 || index >= static_cast<int>(length_)) { - cerr << "The index exceeds the array length" << endl; + Contact emptyContact; + std::cerr << "The index exceeds the array length" << endl; return emptyContact; } - Contact contact = contacts_[index]; - return contact; + + return contacts_[index]; } template <class C> @@ -392,6 +463,7 @@ namespace MyStructures return storage; } + }; #endif
\ No newline at end of file |