void ChaincopyChain const other height otherheight width otherwidth length 0

Void chaincopychain const other height otherheight

This preview shows page 4 - 5 out of 5 pages.

*/ void Chain::copy(Chain const& other) { height_ = other.height_; width_ = other.width_; length_ = 0; head_ = new Node(); tail_ = new Node(); head_->next = tail_; tail_->prev = head_; Node *curr_node_to_copy = other.head_->next; for (int i = 1; i <= other.length_; i++) { insertBack(curr_node_to_copy->data); curr_node_to_copy = curr_node_to_copy->next; } } //helper function typename Chain::Node * Chain::copyHelper(Node * other,Node * prev){ Node * curr; if (other == NULL) curr = NULL; else{ curr = new Node(other->data); curr->next = copyHelper(other->next,curr); curr->prev = prev; } return curr; } // return the first node in the given chain and return it typename Chain::Node * Chain::remove(Chain &other){ if (other.head_-> next == other.tail_){ return NULL; }else{ Node* temp= other.head_-> next; other.head_->next=temp->next; temp->next->prev=other.head_; temp->next= NULL; temp->prev= NULL; other.length_--; return temp;
Image of page 4
} } // add the node to the current chain at back; void Chain::add(Node * curr){ Node * temp = tail_->prev; temp->next=curr; curr->prev=temp; curr->next=tail_; tail_->prev=curr; length_++; }
Image of page 5

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture