Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "List.h"
- template<class T> void List<T>::push_front(T data)
- {
- Node<T> * curr = new Node<T>(data);
- if(!head){
- head = curr;
- tail = head;
- tail->next = NULL;
- }
- else{
- Node<T> * temp = head;
- head = curr;
- head->next = temp;
- }
- }
- template<class T> void List<T>::push_back(T data)
- {
- Node<T> * curr = new Node<T>(data);
- if(!head){
- head = curr;
- tail = head;
- tail->next = NULL;
- }
- else{
- Node<T> * temp = head;
- while(temp->next != NULL)
- temp = temp->next;
- temp->next = curr;
- curr->next = NULL;
- }
- }
- template<class T> T List<T>::pop_front()
- {
- T data = head->entry;
- Node<T> * temp = head;
- head = head->next;
- delete temp;
- return data;
- }
- template<class T> T List<T>::pop_back()
- {
- T data = tail->entry;
- Node<T> * curr = head;
- while(curr->next != NULL)
- curr = curr->next;
- delete tail;
- curr->next = NULL;
- return data;
- }
- template<class T> void Stack<T>::push_front(T data)
- {
- list.push_front(data);
- }
- template<class T> void Queue<T>::push_back(T data)
- {
- list.push_back(data);
- }
- template<class T> T Queue<T>::pop_back()
- {
- T data = list.pop_back();
- return data;
- }
- template<class T> T Stack<T>::pop_front()
- {
- T data = list.pop_front();
- return data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement