#1 Removed tail property from Linked List

This commit is contained in:
Luke Else 2022-11-21 14:23:39 +00:00
parent e338ddb255
commit 954ea3f949

View File

@ -18,7 +18,6 @@ namespace Datastructures {
private:
std::shared_ptr<Nodes::LinkedListNode<T>> getIndex(int index);
std::shared_ptr<Nodes::LinkedListNode<T>> mHead;
std::shared_ptr<Nodes::LinkedListNode<T>> mTail;
int mCount;
};
@ -27,7 +26,6 @@ namespace Datastructures {
LinkedList<T>::LinkedList() {
mCount = 0;
mHead = nullptr;
mTail = nullptr;
}
//Class constructor for the Linked List, taking a preset value to go into the head of the list
@ -35,7 +33,6 @@ namespace Datastructures {
LinkedList<T>::LinkedList(T value) {
mCount = 1;
mHead = std::make_shared<Nodes::LinkedListNode<T>>(value);
mTail = mHead;
}
template <typename T>
@ -46,13 +43,12 @@ namespace Datastructures {
mCount++;
if (mHead == nullptr) {
mHead = std::make_shared<Nodes::LinkedListNode<T>>(value);
mTail = mHead;
return;
}
//Add new node and set to tail.
mTail->next = std::make_shared<Nodes::LinkedListNode<T>>(value);
mTail = mTail->next;
//Add new node (Count already altered so we need to look a node before the end)
std::shared_ptr<Nodes::LinkedListNode<T>> node = this->getIndex(mCount - 2);
node->next = std::make_shared<Nodes::LinkedListNode<T>>(value);
}
template <typename T>