Moved datastructures into src directory and added insert method into Linked List #1
This commit is contained in:
commit
7cabc13196
@ -8,17 +8,17 @@ namespace Generic {
|
||||
public:
|
||||
DirectedNode(T value, std::shared_ptr<NodeType> left = nullptr, std::shared_ptr<NodeType> right = nullptr);
|
||||
~DirectedNode();
|
||||
T value;
|
||||
std::shared_ptr<NodeType> left;
|
||||
std::shared_ptr<NodeType> right;
|
||||
protected:
|
||||
T mValue;
|
||||
std::shared_ptr<NodeType> mLeft;
|
||||
std::shared_ptr<NodeType> mRight;
|
||||
};
|
||||
|
||||
template <typename T, typename NodeType>
|
||||
DirectedNode<T, NodeType>::DirectedNode(T value, std::shared_ptr<NodeType> left, std::shared_ptr<NodeType> right) {
|
||||
this->mValue = value;
|
||||
this->mLeft = left;
|
||||
this->mRight = right;
|
||||
this->value = value;
|
||||
this->left = left;
|
||||
this->right = right;
|
||||
}
|
||||
|
||||
template <typename T, typename NodeType>
|
||||
|
@ -8,15 +8,14 @@ namespace Generic {
|
||||
public:
|
||||
UndirectedNode(T value, std::shared_ptr<NodeType> next = nullptr);
|
||||
~UndirectedNode();
|
||||
protected:
|
||||
T mValue;
|
||||
std::shared_ptr<NodeType> mNext;
|
||||
T value;
|
||||
std::shared_ptr<NodeType> next;
|
||||
};
|
||||
|
||||
template <typename T, typename NodeType>
|
||||
UndirectedNode<T, NodeType>::UndirectedNode(T value, std::shared_ptr<NodeType> next) {
|
||||
this->mValue = value;
|
||||
this->mNext = next;
|
||||
this->value = value;
|
||||
this->next = next;
|
||||
}
|
||||
|
||||
template <typename T, typename NodeType>
|
||||
|
@ -9,9 +9,6 @@ namespace Datastructures {
|
||||
public:
|
||||
//Inherit Constructor and destructor from generic Undirectetd Node
|
||||
using Generic::UndirectedNode<T, LinkedListNode<T>>::UndirectedNode;
|
||||
|
||||
template <typename T>
|
||||
friend class LinkedList;
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
@ -44,13 +44,14 @@ namespace Datastructures {
|
||||
template <typename T>
|
||||
void LinkedList<T>::append(T value) {
|
||||
mCount++;
|
||||
if (mCount == 0) {
|
||||
if (mHead == nullptr) {
|
||||
mHead = std::make_shared<Nodes::LinkedListNode<T>>(value);
|
||||
mTail = mHead;
|
||||
return;
|
||||
}
|
||||
|
||||
//Add new node and set to tail.
|
||||
<<<<<<< HEAD:DataStructures/src/linkedlist.h
|
||||
mTail->mNext = std::make_shared<Nodes::LinkedListNode<T>>(value);
|
||||
mTail = mTail->mNext;
|
||||
}
|
||||
@ -78,5 +79,9 @@ namespace Datastructures {
|
||||
node = node->mNext;
|
||||
}
|
||||
return node;
|
||||
=======
|
||||
(*mTail).next = std::make_shared<Nodes::LinkedListNode<T>>(value);
|
||||
mTail = (*mTail).next;
|
||||
>>>>>>> 700d6696c82b4ea8ba783238ef73b7efc630dd54:DataStructures/src/LinkedList/linkedlist.h
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user