Guest User

Untitled

a guest
Apr 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. class Vector2D {
  2. private:
  3. vector<vector<int>>::iterator row, iBegin, iEnd;
  4. vector<int>::iterator col;
  5. public:
  6. Vector2D(vector<vector<int>>& vec2d) {
  7. iBegin = row = vec2d.begin();
  8. iEnd = vec2d.end();
  9. if(vec2d.size())
  10. col = row->begin();
  11. //remove();
  12. //col++;
  13. //col++;
  14. /*
  15. if(hasNext())
  16. cout<<next()<<endl;
  17. if(hasNext())
  18. cout<<next()<<endl;
  19.  
  20. if(hasNext())
  21. remove();
  22. row = iBegin;
  23. col = row->begin();
  24. */
  25. }
  26.  
  27. int next() {
  28. if(hasNext()){
  29. int val = *col;
  30. col++;
  31. return val;
  32. }
  33. }
  34.  
  35. bool hasNext() {
  36. while(row != iEnd && col == row->end()){
  37. row++;
  38. col = row->begin();
  39. }
  40. return row != iEnd;
  41. }
  42.  
  43. bool remove(){
  44. if(col == row->begin()){
  45. auto pre = prev(row);
  46. while(pre != iBegin && (*pre).empty()) pre = prev(pre);
  47. //cout<<"remove sz"<<(*pre).size()<<endl;
  48. if(!(*pre).empty()) {
  49. cout<<"remove "<<*prev((*pre).end())<<endl;
  50. (*pre).erase(prev((*pre).end()));
  51. }
  52. }
  53. else{
  54. (*row).erase(prev(col));
  55. col--;
  56. }
  57. return true;
  58. }
  59. };
  60.  
  61. /**
  62. * Your Vector2D object will be instantiated and called as such:
  63. * Vector2D i(vec2d);
  64. * while (i.hasNext()) cout << i.next();
  65. */
Add Comment
Please, Sign In to add comment