Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cdll.h"
- #include <fstream>
- #include <sstream>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <string.h>
- CDLLNode::CDLLNode(const char *ti, const char *tw){
- time = ti;
- tweet = tw;
- next = NULL;
- prev = NULL;
- }
- CDLLNode::~CDLLNode(){
- }
- CDLL::CDLL() {
- head = NULL;
- current = NULL;
- }
- CDLL::~CDLL(){
- CDLLNode *temp = head;
- CDLLNode *p = head;
- while (head -> next) {
- temp = head;
- head = head -> next;
- delete temp;
- if (head = p){
- return;
- }
- }
- delete p;
- }
- // makes an insertion at the front of the list
- void CDLL::prepend(const char *time, const char *tweet){
- CDLLNode *temp1 = new CDLLNode(time, tweet);
- if (!head){
- temp1 -> prev = temp1;
- temp1 -> next = temp1;
- head = temp1;
- current = temp1;
- } else {
- temp1 -> prev = head -> prev;
- temp1 -> next = head;
- head -> prev = temp1;
- head = temp1;
- head -> prev -> next = temp1;
- }
- }
- // makes an insertion at the end of the list
- void CDLL::append(const char *time, const char *tweet){
- CDLLNode *temp1 = new CDLLNode(time, tweet);
- if (!head){
- temp1 -> next = temp1;
- temp1 -> prev = temp1;
- head = temp1;
- current = temp1;
- } else {
- temp1 -> next = head;
- temp1 -> prev = head -> prev;
- head -> prev -> next = temp1;
- head -> prev = temp1;
- }
- }
- // moves 'current' pointer to the next node (circularly)
- void CDLL::go_next(){
- if (current) {
- current = current -> next;
- } else {
- }
- }
- // moves 'current' pointer to the previous node (circularly)
- void CDLL:: go_prev(){
- if (current) {
- current = current -> prev;
- } else {
- }
- }
- // moves 'current' pointer to the head/first node
- void CDLL::go_first(){
- if (current) {
- current = head;
- } else {
- }
- }
- // moves 'current' pointer to the last node
- void CDLL::go_last(){
- if (current) {
- current = head -> prev;
- } else {
- }
- }
- // moves 'current' pointer n elements ahead (circularly)
- void CDLL::skip(unsigned int n){
- for (unsigned int p = 0; p < n; p++){
- current = current -> next;
- }
- }
- // prints the contents of the 'current' node
- void CDLL::print_current(){
- if (current) {
- std::cout << current -> time.substr(0, 100) << " " << current->tweet << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement