chain.cpp - #include\"chain.h#include\"chain_given.cpp PA1 functions Destroys the current Chain This function should ensure that memory does not leak on

chain.cpp - #include"chain.h#include"chain_given.cpp PA1...

This preview shows page 1 - 2 out of 4 pages.

#include "chain.h" #include "chain_given.cpp" // PA1 functions /** * Destroys the current Chain. This function should ensure that * memory does not leak on destruction of a chain. */ Chain::~Chain(){ /*your code here*/ clear(); } /** * Inserts a new node at the back of the List. * This function **SHOULD** create a new ListNode. * * @param ndata The data to be inserted. */ void Chain::insertBack(const Block & ndata){ /*your code here*/ Node * newNode = new Node(ndata); Node * prevNode = tail_-> prev; newNode->next = tail_; tail_->prev = newNode; newNode->prev = prevNode; prevNode->next = newNode; length_++; } /** * Modifies the Chain by moving a contiguous subset of len Nodes * dist nodes toward the end of the chain beginning from startPos * (maintaining the sentinel at the end). Their order is * not changed in the move. You may assume that the startPos and * len parameters are kind: startPos + len -1 <= length. If there * are not enough nodes to shift by dist, just shift as many as * possible. */ void Chain::moveBack(int startPos, int len, int dist){ /*your code here*/ Node* frontStart = walk(head_, startPos); Node* frontEnd = walk(frontStart, len-1); Node* backStart = frontEnd->next; Node* before = frontStart->prev; backStart->prev = before;
Image of page 1
Image of page 2

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture