Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include "browserhistory.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5.  
  6.  
  7. BrowserHistory::BrowserHistory(string default_url)
  8. {
  9. head = new Node;
  10. head->url = default_url;
  11. head->next = nullptr;
  12. head->prev = nullptr;
  13. tail, current = head;
  14. }
  15. string BrowserHistory::current_url()
  16. {
  17. return current->url;
  18. }
  19. void BrowserHistory::go_to_url(string url)
  20. {
  21. Node* temp = new Node;
  22. temp->prev = current;
  23. temp->next = nullptr;
  24. temp->url = url;
  25. current->next = temp;
  26. tail, current = temp;
  27. }
  28. void BrowserHistory::back()
  29. {
  30. if(current->prev != nullptr)
  31. current = current->prev;
  32. }
  33. bool BrowserHistory::can_go_back()
  34. {
  35. if (current->prev != nullptr)
  36. return true;
  37. else
  38. return false;
  39. }
  40. int BrowserHistory::past_url_count()
  41. {
  42. Node* temp;
  43. temp = current;
  44. int count = 0;
  45. while (temp->prev != nullptr)
  46. {
  47. count += 1;
  48. temp = temp->prev;
  49. }
  50. return count;
  51. }
  52. void BrowserHistory::forward()
  53. {
  54. if (current->next != nullptr)
  55. current = current->next;
  56. }
  57. bool BrowserHistory::can_go_forward()
  58. {
  59. if (current->next != nullptr)
  60. return true;
  61. else
  62. return false;
  63. }
  64. int BrowserHistory::future_url_count()
  65. {
  66. Node* temp;
  67. temp = current;
  68. int count = 0;
  69. while (temp->next != nullptr)
  70. {
  71. count += 1;
  72. temp = temp->next;
  73. }
  74. return count;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement