Advertisement
Guest User

asd

a guest
Apr 20th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. #include "cdll.h"
  2. #include <fstream>
  3. #include <sstream>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <string>
  7. #include <string.h>
  8.  
  9.  
  10. CDLLNode::CDLLNode(const char *ti, const char *tw){
  11. time = ti;
  12. tweet = tw;
  13. next = NULL;
  14. prev = NULL;
  15. }
  16. CDLLNode::~CDLLNode(){
  17.  
  18. }
  19. CDLL::CDLL() {
  20. head = NULL;
  21. current = NULL;
  22. }
  23.  
  24.  
  25. CDLL::~CDLL(){
  26. CDLLNode *temp = head;
  27. CDLLNode *p = head;
  28. while (head -> next) {
  29. temp = head;
  30. head = head -> next;
  31. delete temp;
  32. if (head = p){
  33. return;
  34. }
  35. }
  36. delete p;
  37. }
  38. // makes an insertion at the front of the list
  39. void CDLL::prepend(const char *time, const char *tweet){
  40. CDLLNode *temp1 = new CDLLNode(time, tweet);
  41. if (!head){
  42. temp1 -> prev = temp1;
  43. temp1 -> next = temp1;
  44. head = temp1;
  45. current = temp1;
  46. } else {
  47. temp1 -> prev = head -> prev;
  48. temp1 -> next = head;
  49. head -> prev = temp1;
  50. head = temp1;
  51. head -> prev -> next = temp1;
  52. }
  53. }
  54. // makes an insertion at the end of the list
  55. void CDLL::append(const char *time, const char *tweet){
  56. CDLLNode *temp1 = new CDLLNode(time, tweet);
  57. if (!head){
  58. temp1 -> next = temp1;
  59. temp1 -> prev = temp1;
  60. head = temp1;
  61. current = temp1;
  62. } else {
  63. temp1 -> next = head;
  64. temp1 -> prev = head -> prev;
  65. head -> prev -> next = temp1;
  66. head -> prev = temp1;
  67. }
  68. }
  69. // moves 'current' pointer to the next node (circularly)
  70. void CDLL::go_next(){
  71. if (current) {
  72. current = current -> next;
  73. } else {
  74. }
  75. }
  76.  
  77.  
  78. // moves 'current' pointer to the previous node (circularly)
  79. void CDLL:: go_prev(){
  80. if (current) {
  81. current = current -> prev;
  82. } else {
  83. }
  84. }
  85.  
  86.  
  87. // moves 'current' pointer to the head/first node
  88. void CDLL::go_first(){
  89. if (current) {
  90. current = head;
  91. } else {
  92. }
  93. }
  94.  
  95.  
  96. // moves 'current' pointer to the last node
  97. void CDLL::go_last(){
  98. if (current) {
  99. current = head -> prev;
  100. } else {
  101. }
  102. }
  103.  
  104.  
  105. // moves 'current' pointer n elements ahead (circularly)
  106. void CDLL::skip(unsigned int n){
  107. for (unsigned int p = 0; p < n; p++){
  108. current = current -> next;
  109. }
  110. }
  111.  
  112.  
  113. // prints the contents of the 'current' node
  114. void CDLL::print_current(){
  115. if (current) {
  116. std::cout << current -> time.substr(0, 100) << " " << current->tweet << std::endl;
  117. }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement