/** 251.Flatten 2D Vector * 2016-6-20 by Mingyang *-------Boolean hasnext () * Returns true if the iteration have more E Lements. * (in other words, returns True if Next () would return a element rather than throwing an exception.) *-------E Next () *returns the next element in the iteration. *returns: *the next element in the iteration *throws: *nosuchelementexception-if The iteration have no more elements * key questions The problem is to master the use of good iterator*/classvector2d {Privateiterator<list<integer>> row =NULL; Privateiterator<integer> col =NULL; PublicVector2d (list<list<integer>>vec2d) {Row=Vec2d.iterator (); if(Row.hasnext ()) Col=Row.next (). iterator (); } Public intNext () {intLastvalue =Col.next (); returnLastvalue; } Public BooleanHasnext () {if(col = =NULL) { return false; } if(Col.hasnext ()) {return true; } Else { while(Row.hasnext ()) {col=Row.next (). iterator (); if(Col.hasnext ())return true; } return false; } }
251.Flatten 2D Vector