chain_given.cpp - #include\"chain.h no-argument Chain:Chain head = new tail = new head->next tail->prev constructor w 2 sentinels length(0 cfw Node Node

chain_given.cpp - #include"chain.h no-argument Chain:Chain...

This preview shows page 1 - 3 out of 3 pages.

#include "chain.h" /* no-argument constructor w 2 sentinels */ Chain::Chain() : length_(0) { head_ = new Node(); tail_ = new Node(); head_->next = tail_; tail_->prev = head_; } /* Most useful constructor. requires your * implementation of Block and insertBack. * Builds a chain out of the blocks in the * given image. The blocks we create * have width equal to imIn.width()/cols, * and height equal to imIn.height()/rows. * Our Chain has one * sentinel node at the head, and another * at the tail. */ Chain::Chain(PNG & imIn, int cols){ width_ = imIn.width()/cols; // approx width of a block height_ = imIn.height(); head_ = new Node(Block()); tail_ = new Node(Block()); head_->next = tail_; tail_->prev = head_; length_ = 0; for (int j = 0; j < cols; j++){ Block b; b.build(imIn , j*width_, width_); insertBack(b); } } /** * accessor for the length of the chain. */ int Chain::size() const { return length_; } /* copy constructor */ Chain::Chain(Chain const& other) { copy(other); } /* assignment operator */ Chain & Chain::operator=(Chain const& rhs) { if (this != &rhs) { clear(); // you'll implement clear copy(rhs); } return *this; } /** * checks for empty list */ bool Chain::empty() const {
Image of page 1
return length_ == 0; } /**
Image of page 2
Image of page 3

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture