Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef S_LINKED_LIST
- #define S_LINKED_LIST
- template <typename E>
- class SLinkedList;
- template <typename E>
- class SNode
- {
- private:
- E elem;
- SNode<E> * next;
- friend class SLinkedList<E>;
- };
- template <typename E>
- class SLinkedList
- {
- private:
- SNode<E> * head;
- public:
- SLinkedList();
- ~SLinkedList();
- bool empty() const;
- const E& front() const;
- void addFront(const E& e);
- void removeFront();
- };
- #endif /*SLinkedList.h*/
- #include "SLinkedList.h"
- #include <iostream>
- template <typename E>
- SLinkedList<E>::SLinkedList():head(NULL){}
- template <typename E>
- SLinkedList<E>::~SLinkedList()
- {while(!empty()) removeFront();}
- template <typename E>
- bool SLinkedList<E>::empty() const
- {return head == NULL;}
- template <typename E>
- const E& SLinkedList<E>::front() const
- {return head->elem;}
- template <typename E>
- void SLinkedList<E>::addFront(const E& e)
- {
- SNode<E> * newNode = new SNode<E>;
- newNode->elem = e;
- newNode->next = head;
- head = newNode;
- }
- template <typename E>
- void SLinkedList<E>::removeFront()
- {
- SNode<E> * old = head;
- head = old->next;
- delete old;
- }/*SLinkedList.cpp*/
- #include <iostream>
- #include "SLinkedList.h"
- int main()
- {
- SLinkedList<std::string> newlist;
- newlist.addFront("MSP");
- std::cout << newlist.front();
- return 0;
- }/*test_slinkedlist.cpp*/
- Undefined symbols for architecture x86_64:
- ...
- ld: symbol(s) not found for architecture x86_64
- clang: error: linker command failed with exit code 1 (use -v to see invocation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement