SHARE
TWEET

Untitled

a guest Oct 21st, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iterator>
  2. #include <cmath>
  3.  
  4. #include <list>
  5. #include <queue>
  6. #include <stack>
  7. #include <vector>
  8.  
  9. #include "../cs225/PNG.h"
  10. #include "../Point.h"
  11.  
  12. #include "ImageTraversal.h"
  13. #include "BFS.h"
  14.  
  15. using namespace cs225;
  16.  
  17. /**
  18.  * Initializes a breadth-first ImageTraversal on a given `png` image,
  19.  * starting at `start`, and with a given `tolerance`.
  20.  * @param png The image this BFS is going to traverse
  21.  * @param start The start point of this BFS
  22.  * @param tolerance If the current point is too different (difference larger than tolerance) with the start point,
  23.  * it will not be included in this BFS
  24.  */
  25. BFS::BFS(const PNG & png, const Point & start, double tolerance) {  
  26.   /** @todo [Part 1] */
  27.   png_ = png;
  28.   start_ = start;
  29.   tolerance_ = tolerance;
  30.   list_.push(start);
  31. }
  32.  
  33. /**
  34.  * Returns an iterator for the traversal starting at the first point.
  35.  */
  36. ImageTraversal::Iterator BFS::begin() {
  37.   /** @todo [Part 1] */
  38.     Iterator iterator = ImageTraversal::Iterator(png_, start_, tolerance_, this);
  39.     return iterator;
  40. }
  41.  
  42. /**
  43.  * Returns an iterator for the traversal one past the end of the traversal.
  44.  */
  45. ImageTraversal::Iterator BFS::end() {
  46.   /** @todo [Part 1] */
  47.     Iterator iterator = ImageTraversal::Iterator(png_, start_, tolerance_, this);
  48.     iterator.setEnd(true);
  49.     return iterator;
  50. }
  51.  
  52. /**
  53.  * Adds a Point for the traversal to visit at some point in the future.
  54.  */
  55. void BFS::add(const Point & point) {
  56.   /** @todo [Part 1] */
  57.   list_.push(point);
  58. }
  59.  
  60. /**
  61.  * Removes and returns the current Point in the traversal.
  62.  */
  63. Point BFS::pop() {
  64.   /** @todo [Part 1] */
  65.     Point temp = list_.front();
  66.     list_.pop();
  67.     return temp;
  68. }
  69.  
  70. /**
  71.  * Returns the current Point in the traversal.
  72.  */
  73. Point BFS::peek() const {
  74.   /** @todo [Part 1] */
  75.     return list_.front();
  76. }
  77.  
  78. /**
  79.  * Returns true if the traversal is empty.
  80.  */
  81. bool BFS::empty() const {
  82.   /** @todo [Part 1] */
  83.     return list_.empty();
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top