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:
|
public:
|
||||||
DirectedNode(T value, std::shared_ptr<NodeType> left = nullptr, std::shared_ptr<NodeType> right = nullptr);
|
DirectedNode(T value, std::shared_ptr<NodeType> left = nullptr, std::shared_ptr<NodeType> right = nullptr);
|
||||||
~DirectedNode();
|
~DirectedNode();
|
||||||
|
T value;
|
||||||
|
std::shared_ptr<NodeType> left;
|
||||||
|
std::shared_ptr<NodeType> right;
|
||||||
protected:
|
protected:
|
||||||
T mValue;
|
|
||||||
std::shared_ptr<NodeType> mLeft;
|
|
||||||
std::shared_ptr<NodeType> mRight;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename NodeType>
|
template <typename T, typename NodeType>
|
||||||
DirectedNode<T, NodeType>::DirectedNode(T value, std::shared_ptr<NodeType> left, std::shared_ptr<NodeType> right) {
|
DirectedNode<T, NodeType>::DirectedNode(T value, std::shared_ptr<NodeType> left, std::shared_ptr<NodeType> right) {
|
||||||
this->mValue = value;
|
this->value = value;
|
||||||
this->mLeft = left;
|
this->left = left;
|
||||||
this->mRight = right;
|
this->right = right;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename NodeType>
|
template <typename T, typename NodeType>
|
||||||
|
@ -8,15 +8,14 @@ namespace Generic {
|
|||||||
public:
|
public:
|
||||||
UndirectedNode(T value, std::shared_ptr<NodeType> next = nullptr);
|
UndirectedNode(T value, std::shared_ptr<NodeType> next = nullptr);
|
||||||
~UndirectedNode();
|
~UndirectedNode();
|
||||||
protected:
|
T value;
|
||||||
T mValue;
|
std::shared_ptr<NodeType> next;
|
||||||
std::shared_ptr<NodeType> mNext;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename NodeType>
|
template <typename T, typename NodeType>
|
||||||
UndirectedNode<T, NodeType>::UndirectedNode(T value, std::shared_ptr<NodeType> next) {
|
UndirectedNode<T, NodeType>::UndirectedNode(T value, std::shared_ptr<NodeType> next) {
|
||||||
this->mValue = value;
|
this->value = value;
|
||||||
this->mNext = next;
|
this->next = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename NodeType>
|
template <typename T, typename NodeType>
|
||||||
|
@ -9,9 +9,6 @@ namespace Datastructures {
|
|||||||
public:
|
public:
|
||||||
//Inherit Constructor and destructor from generic Undirectetd Node
|
//Inherit Constructor and destructor from generic Undirectetd Node
|
||||||
using Generic::UndirectedNode<T, LinkedListNode<T>>::UndirectedNode;
|
using Generic::UndirectedNode<T, LinkedListNode<T>>::UndirectedNode;
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
friend class LinkedList;
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -44,13 +44,14 @@ namespace Datastructures {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
void LinkedList<T>::append(T value) {
|
void LinkedList<T>::append(T value) {
|
||||||
mCount++;
|
mCount++;
|
||||||
if (mCount == 0) {
|
if (mHead == nullptr) {
|
||||||
mHead = std::make_shared<Nodes::LinkedListNode<T>>(value);
|
mHead = std::make_shared<Nodes::LinkedListNode<T>>(value);
|
||||||
mTail = mHead;
|
mTail = mHead;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add new node and set to tail.
|
//Add new node and set to tail.
|
||||||
|
<<<<<<< HEAD:DataStructures/src/linkedlist.h
|
||||||
mTail->mNext = std::make_shared<Nodes::LinkedListNode<T>>(value);
|
mTail->mNext = std::make_shared<Nodes::LinkedListNode<T>>(value);
|
||||||
mTail = mTail->mNext;
|
mTail = mTail->mNext;
|
||||||
}
|
}
|
||||||
@ -78,5 +79,9 @@ namespace Datastructures {
|
|||||||
node = node->mNext;
|
node = node->mNext;
|
||||||
}
|
}
|
||||||
return node;
|
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