Advertisement
ssnr

Untitled

Nov 6th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1.  
  2. #include "linkedlist.h"
  3.  
  4. LL::LL() { }
  5.  
  6. bool LL::empty() {
  7. return head == NULL;
  8. }
  9.  
  10. size_t LL::size() {
  11. int total = 0;
  12. node *curr = head;
  13. while (curr != NULL) {
  14. total++;
  15. curr = curr->next;
  16. }
  17. return total;
  18. }
  19.  
  20. void LL::clear() {
  21. node *curr = head;
  22. node *todelete = curr;
  23. while (curr != NULL) {
  24. curr = curr->next;
  25. delete todelete;
  26. todelete = curr;
  27. }
  28. head = NULL;
  29. }
  30.  
  31. void LL::pop_front() {
  32. if (head != NULL) {
  33. node *newhead = head->next;
  34. delete head;
  35. head = newhead;
  36. }
  37. }
  38.  
  39. void LL::push_front(const int &x) {
  40. node *newhead = new node;
  41. newhead->data = x;
  42. newhead->next = head;
  43. head = newhead;
  44. }
  45.  
  46. int& LL::front() {
  47. return head->data;
  48. }
  49.  
  50. const int& LL::front() const {
  51. return head->data;LINKEDLIST_H
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement