Advertisement
Guest User

list.cpp

a guest
Nov 5th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include "List.h"
  2.  
  3. template<class T> void List<T>::push_front(T data)
  4. {
  5. Node<T> * curr = new Node<T>(data);
  6.  
  7. if(!head){
  8. head = curr;
  9. tail = head;
  10. tail->next = NULL;
  11. }
  12. else{
  13. Node<T> * temp = head;
  14. head = curr;
  15. head->next = temp;
  16. }
  17.  
  18. }
  19.  
  20. template<class T> void List<T>::push_back(T data)
  21. {
  22. Node<T> * curr = new Node<T>(data);
  23.  
  24. if(!head){
  25. head = curr;
  26. tail = head;
  27. tail->next = NULL;
  28. }
  29. else{
  30. Node<T> * temp = head;
  31. while(temp->next != NULL)
  32. temp = temp->next;
  33. temp->next = curr;
  34. curr->next = NULL;
  35. }
  36. }
  37.  
  38. template<class T> T List<T>::pop_front()
  39. {
  40. T data = head->entry;
  41. Node<T> * temp = head;
  42. head = head->next;
  43. delete temp;
  44. return data;
  45. }
  46.  
  47. template<class T> T List<T>::pop_back()
  48. {
  49. T data = tail->entry;
  50. Node<T> * curr = head;
  51. while(curr->next != NULL)
  52. curr = curr->next;
  53. delete tail;
  54. curr->next = NULL;
  55.  
  56. return data;
  57. }
  58.  
  59. template<class T> void Stack<T>::push_front(T data)
  60. {
  61. list.push_front(data);
  62. }
  63.  
  64. template<class T> void Queue<T>::push_back(T data)
  65. {
  66. list.push_back(data);
  67. }
  68.  
  69. template<class T> T Queue<T>::pop_back()
  70. {
  71. T data = list.pop_back();
  72. return data;
  73. }
  74.  
  75. template<class T> T Stack<T>::pop_front()
  76. {
  77. T data = list.pop_front();
  78. return data;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement