Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class SinglyLinkedList
- {
- public:
- SinglyLinkedList();
- SinglyLinkedList(const SinglyLinkedList& other);
- ~SinglyLinkedList();
- void push_back(T data);
- void push_front(T data);
- void pop_front();
- void clear();
- void build_empty(size_t sizeOfList);
- void insert(T data, int index);
- void removeAt(int index);
- void pop_back();
- int getSize(){ return size;}
- T operator[] (const int index);
- private:
- template<typename T>
- class Node
- {
- public:
- Node *pNext;
- T data;
- Node(T data = T(), Node *pNext = nullptr)
- {
- this->data = data;
- this->pNext = pNext;
- }
- };
- Node<T> *head;
- size_t size;
- };
- template<typename T>
- SinglyLinkedList<T>::SinglyLinkedList(const SinglyLinkedList &other)
- {
- this->size = other.size;
- this->head = other.head;
- Node<T>* current = this->head;
- while (current->pNext != nullptr)
- {
- Node<T>* newcar = new Node<T>;
- newcar->data = other->data;
- newcar->pNext = other->pNext;
- current = current->pNext;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement