aboutsummaryrefslogtreecommitdiff
path: root/Homework 8/MyStructures
diff options
context:
space:
mode:
authorYana Blashchishina <[email protected]>2024-03-10 18:40:00 -0700
committerYana Blashchishina <[email protected]>2024-03-10 18:40:00 -0700
commita685a01c122b6650931bcef1c2493232fcddaef4 (patch)
treebc1413765969d6201b588bedaaf8b18875d0af43 /Homework 8/MyStructures
parentvoids (diff)
downloadhomework-8-yanablash-a685a01c122b6650931bcef1c2493232fcddaef4.tar.xz
homework-8-yanablash-a685a01c122b6650931bcef1c2493232fcddaef4.zip
i keep forgetting to commit
Diffstat (limited to 'Homework 8/MyStructures')
-rw-r--r--Homework 8/MyStructures/Contact.hpp3
-rw-r--r--Homework 8/MyStructures/ContactList.hpp200
2 files changed, 190 insertions, 13 deletions
diff --git a/Homework 8/MyStructures/Contact.hpp b/Homework 8/MyStructures/Contact.hpp
index 5d47aed..e079797 100644
--- a/Homework 8/MyStructures/Contact.hpp
+++ b/Homework 8/MyStructures/Contact.hpp
@@ -110,7 +110,8 @@ void Contact<T>::SetCustomValue(T& newValue)
template<typename T>
void Contact<T>::Print()
{
-
+ std::cout << "Name: " << name_ << std:: endl;
+ std::cout << "Age: " << age_ << std::endl;
}
diff --git a/Homework 8/MyStructures/ContactList.hpp b/Homework 8/MyStructures/ContactList.hpp
index c8c299a..0cee43f 100644
--- a/Homework 8/MyStructures/ContactList.hpp
+++ b/Homework 8/MyStructures/ContactList.hpp
@@ -5,9 +5,9 @@
namespace MySStructures
{
- template<class C>
- class ContactList
- {
+ template<class C>
+ class ContactList
+ {
public:
/**
* Contains an array of Contacts or othe C class objects
@@ -15,17 +15,17 @@ namespace MySStructures
ContactList() = default;
ContactList(size_t length); //Creates contact list of this size
ContactList(const C* contacts, const size_t& length); //Makes a copy of another contact list
- ~ContactList();
+ ~ContactList();
ContactList(const ContactList& copy); //deep copy constructor
ContactList& operator=(const ContactList& rhs); //deep copy assignment
ContactList(ContactList&& move); //reference(move) constructor
ContactList& operator=(ContactList&& rhs); //reference(move) assignment
-
+
void Print() const; //Print the Contact List, calling Print on each element.
size_t Size() const; //Return the size of the contact list
-
+
void Append(const C& data); //Add contact to back of list
void Prepend(const C& data); //add contact as first contact
void RemoveLast(); //removes last contact
@@ -47,7 +47,7 @@ namespace MySStructures
bool operator==(const ContactList<C>& rhs) const; //if (newContact == old Contact)
bool Empty() const; //is the list empty
-
+
@@ -57,7 +57,7 @@ namespace MySStructures
size_t size_{ 0 }; //number of actual numbers
C* AllocateContactList(const size_t& length);
- };
+ };
template <class C>
ContactList<C>::ContactList(size_t length)
@@ -133,9 +133,186 @@ namespace MySStructures
size_ = rhs.size_;
rhs.contacts_ = nullptr;
-
+
+ }
+ }
+
+
+
+ template <class C>
+ void ContactList<C>::Print() const
+ {
+ for (auto i = 0u; i < length_; ++i)
+ {
+ contacts_[i].Print();
+ }
+ }
+
+ template <class C>
+ size_t ContactList<C>::Size() const
+ {
+
+ }
+
+ template <class C>
+ void ContactList<C>::Append(const C& data)
+ {
+
+ size_t index = 0;
+
+ // whatifs;
+ //whatif: end of the array is the beginning
+ //whatif: in the body of the array
+ if (size_ < length_)
+ {
+ index = size_;
+ }
+ //whatif: end of the array
+ //length_ == 10;
+ // size_ ==10
+ // contacts_[10] is out of bounds!
+ //whatif: array is full
+
+ if (size_ >= length_)
+ {
+ //increase size of array
+ *this = ContactList(contacts_, length_ * 2);
}
+
+
+ // Add to end of the array
+ contacts_[index] = data;
+ size_++;
}
+
+ template <class C>
+ void ContactList<C>::Prepend(const C& data)
+ {
+ if (Empty())
+ {
+ Append(data);
+ return;
+ }
+ if (!Full())
+ {
+ for (auto i = size_ - 1; i >= 0; i--)
+ {
+ contacts_[i + 1] = contacts_[if;]
+ }
+ }
+ auto temp = ContactList<C>(length_);
+ temp.Append(data);
+ for (auto i = 0; i < size_; ++i)
+ {
+ temp.Append(contacts_[i]);
+ }
+ delete[] contacts_;
+ contacts_ = nullptr;
+
+ *this = std::move(temp);
+ }
+
+ template <class C>
+ void ContactList<C>::RemoveLast()
+ {
+
+ }
+
+ template <class C>
+ void ContactList<C>::RemoveFirst()
+ {
+
+ }
+
+ template <class C>
+ void ContactList<C>::Extract(const C& data)
+ {
+
+ }
+
+ template <class C>
+ void ContactList<C>::InsertAfter(const C& data const C& data)
+ {
+
+ }
+
+ template <class C>
+ void ContactList<C>::InsertBefore(const C& data const C& data)
+ {
+
+ }
+
+ template <class C>
+ void ContactList<C>::Clear()
+ {
+ size_ = 0;
+ length_ = 0;
+ delete[] contacts_;
+ contacts_ = nullptr;
+ }
+
+ template <class C>
+ C& ContactList<C>::Last()
+ {
+ return contacts_[size_];
+ }
+
+ template <class C>
+ C ContactList<C>::Last() const
+ {
+ return contacts_[size_];
+ }
+
+ template <class C>
+ C& ContactList<C>::First()
+ {
+ return contacts_[0];
+ }
+
+ template <class C>
+ C ContactList<C>::First() const
+ {
+ return contacts_[0];
+ }
+
+ template <class C>
+ C ContactList<C>::operator[](const int& index) const
+ {
+ //TODO CHECK RANGE
+ return contacts_[index];
+ }
+
+ template <class C>
+ ContactList<C>::operator bool() const
+ {
+ bool var = contacts_ != nullptr;
+ return (var); //if(addressBook)
+ }
+
+ template <class C>
+ bool ContactList<C>::operator==(const ContactList<C>& rhs) const
+ {
+ //TODO check both arrays to see if equivalent
+ //Performance
+ //shortcut easy ways of knowing the same
+ if (contacts_ == rhs.contacts_)return true;
+ if (size_ != rhs.size_)return false;
+ if (length_ != rhs.length_)return false;
+
+ //if those fields are equivalent, then check every value
+ for (auto i = 0u; i < size_; ++i)
+ {
+ if (contacts_[i] != rhs.contacts_[i]) return false;
+ }
+ return true;
+ }
+
+ template <class C>
+ bool ContactList<C>::Empty() const
+ {
+ return size_ == 0;
+ }
+
template <class C>
C* ContactList<C>::AllocateContactList(const size_t& length)
{
@@ -143,11 +320,10 @@ namespace MySStructures
length_ = length;
- storage = new C[length]{};
+ storage = new C[length]{};
return storage;
}
-}
-
+};
#endif \ No newline at end of file