From dad5a33695e983c56fb552cef97db6bd25bd9f88 Mon Sep 17 00:00:00 2001 From: peet Date: Fri, 14 Jun 2024 08:08:10 +0000 Subject: [PATCH] implemented hasnext --- bin/uebung05/logistics/Demo.class | Bin 897 -> 1684 bytes bin/uebung05/logistics/demo.class | Bin 1684 -> 0 bytes bin/uebung09/iterator/Array2dIterator.class | Bin 1597 -> 1145 bytes src/uebung09/iterator/Array2dIterator.java | 60 ++++---------------- 4 files changed, 10 insertions(+), 50 deletions(-) delete mode 100644 bin/uebung05/logistics/demo.class diff --git a/bin/uebung05/logistics/Demo.class b/bin/uebung05/logistics/Demo.class index 33773c74c312c71a0b53c602bb56e0e7bd52ba3a..fef009cf0b1b30d1a3cb806f2e5d68533ed47bce 100644 GIT binary patch literal 1684 zcmah}OH&(15dH=vR+2Y17UpST@DqW+5{j`Cu$}NQ5wQ>$3E8q!sTx+})xc_3S?${8 zq;kn2w^SvU9DGYEe;^m+GF7?cmLHW$&mtE-tixe@dwQmOzOSdd|M~arUjUZzm4+UM zVPEX|wwYVVT8=5(o;2FoHPLi5L>T(_`3s)4xNT;)_V$J0G4$P)w)E~Z^rok)43Sl* zE)wWPTt^gr4Cji{7A3#AC)^6(vjju3=os9pa#yN#*BJ2{vdu7B{J`}~6uQZ!%`lXH zRy=`G_FQS3OVd>i=NZOAyf?YcP2ncckGO^l;S4L>K8Rt6LEGlG*HFg?Frp}oG7P4} zE{x$K!+J-tswmS8iCtSZ9W$THoXX$OZ4#Za6QuUI>?4R!N9@0(soh@G-+w2*@TUc9L7!q9kQa zing$HEZ{b!$Q0g2sa#nutv+DLq^H9$g!wNiIG^bF6pIWo1xMjvmm@K%K71<*>T zC;mMT)oa`}sT~JGT8%p05Dr5s40E^HD1z2HZln(!d{=Z7%~H{#o@xsEH|FyTP4)NN z2d^07-@bGzj%};GMA`9OL##_x%W*Z7ZmL0mNl+9TVL%UkG<9gLk(Q-DQR@s)5~!Dz8a=|*TJm}aQ;U6pnpUconLWfzW=@IGNFbwu>OyF9JJxzq5Twwi9O0F-nLNgj+|F7^R5M6fw$ErQgGO6lkbz;sSOsh$k4r z*BC|}BiP3nY+Qs-92t$QlqkyNVk*1ONQ;OAtXa50+ Cxt}%w literal 897 zcmcIj!EO^V5Pc45lPrOhKnoQYtEbRI!vQW7AyEpa6(CxQ5GSv9v~laTS6*+$m9Ihq z3GRFpVzwm>pd7gL;IU`?_RaXs?2n&cz5#fO%^o@ew;ReDSKNO%wZ1TQG`gPVRQeve z0&B1n7*r{Jq6(5*7u9UZ+*2)`kFr!z&tzmgeXO{e zKk@Tt>?}S!r#5BfLzEX`sg-NVGLrMsE(4gFNMYYlO?GLGfV?EyX>u zap`@6KCTV1g6jh7lXM~dK@7$fyKQSmsd4nODKiR(iq#evr(P?2q=ISv-@$I2nOa~o zoh$gyAnbCJOJ$tE#^l4YOnqz!eEN?@U#=tq$$@WzrWdAt>tLUUc&8Nx52FC0Sa1*yU(lTuS#jw7F;qDnj Mo0oqzwjJF01@&kEJpcdz diff --git a/bin/uebung05/logistics/demo.class b/bin/uebung05/logistics/demo.class deleted file mode 100644 index fef009cf0b1b30d1a3cb806f2e5d68533ed47bce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1684 zcmah}OH&(15dH=vR+2Y17UpST@DqW+5{j`Cu$}NQ5wQ>$3E8q!sTx+})xc_3S?${8 zq;kn2w^SvU9DGYEe;^m+GF7?cmLHW$&mtE-tixe@dwQmOzOSdd|M~arUjUZzm4+UM zVPEX|wwYVVT8=5(o;2FoHPLi5L>T(_`3s)4xNT;)_V$J0G4$P)w)E~Z^rok)43Sl* zE)wWPTt^gr4Cji{7A3#AC)^6(vjju3=os9pa#yN#*BJ2{vdu7B{J`}~6uQZ!%`lXH zRy=`G_FQS3OVd>i=NZOAyf?YcP2ncckGO^l;S4L>K8Rt6LEGlG*HFg?Frp}oG7P4} zE{x$K!+J-tswmS8iCtSZ9W$THoXX$OZ4#Za6QuUI>?4R!N9@0(soh@G-+w2*@TUc9L7!q9kQa zing$HEZ{b!$Q0g2sa#nutv+DLq^H9$g!wNiIG^bF6pIWo1xMjvmm@K%K71<*>T zC;mMT)oa`}sT~JGT8%p05Dr5s40E^HD1z2HZln(!d{=Z7%~H{#o@xsEH|FyTP4)NN z2d^07-@bGzj%};GMA`9OL##_x%W*Z7ZmL0mNl+9TVL%UkG<9gLk(Q-DQR@s)5~!Dz8a=|*TJm}aQ;U6pnpUconLWfzW=@IGNFbwu>OyF9JJxzq5Twwi9O0F-nLNgj+|F7^R5M6fw$ErQgGO6lkbz;sSOsh$k4r z*BC|}BiP3nY+Qs-92t$QlqkyNVk*1ONQ;OAtXa50+ Cxt}%w diff --git a/bin/uebung09/iterator/Array2dIterator.class b/bin/uebung09/iterator/Array2dIterator.class index 1226fc4b8ab3ea946f007ccd850209e87a614ece..53abed53a9febf4b798c4148e8edc85a5f103088 100644 GIT binary patch delta 634 zcmZXRJx|+E6o%hxn+B3=^AUneDJ6Ua5>tpoC)A07p+aS$LJAWmiUcGf2nFbty-X+@ zV~PX=1C>INikfZ=?LR>LkuIh0agZ4pe7>&ld7pFcPyM$u`upFH7Jvn0kE354bFXr! zpgt&=`AX^dZr+P)IOu1d&a8GpVL&4WEzwI2yB)pKh@i7xROdYk_Da>y7eD&DpZtwd zq24gk?-bG+qZo_8Q%G+62Yzd?9S624(n~SAFxv*1R{G2cBR<|lUQDhLWm(8OZ zV2A|qOzJu4X5PijKo5H9w;37q{oXbDJo5?(F|Id#g~4yZts&Y0bkN$c5asO{`#6ZR z*X!UcxQ}7HVa84}2(?BS>lyD@4IH6H%RffQP&=&&x#3%0fJ#2bfMqqdC%`iT1;ZUC$Urlm*V05hxzeJsZ!o|Or0QhgG}xk)4xJA8OL3ddEDIGCI4(gIh+_Ih)}tk e>yhQPSyInfq>|*hu<+sJ)!s5RF!T6&v;P5D7gs|7 literal 1597 zcmah}OHPeP9z>mnI!%++?P>bbw8-ZN-S%5+ln@ zvdc}9lUBywjNLNM0St-1Qlt8BDxb}m7w_*Er+2}CkY|U%R&ZhJo zWyelE*mZgW^R+iNg9%TaMR>A5K*_&3d{8uFSN0y*k6Cl(yltRJsi(cV=lh;Nh7Se4 z{m%96p4U0BTUOKS?mJB0@my=)_o%*Gw#;Om0<5mn>&l?HTeh0gb-jRx-2>YXtVh1r zwdz*jSq;zY*wQsk6mUxwyu^m*hbCkr@Ex}ub;b>~O$;hLGzw51DpU&F96yK8 zozk^6CL%?+>bH|_h5YW~Ezt945$7pSh(%R_~TQCDAg4b9u&zC~hjokOSb z8R0vjW|r$DuXzF{AI{>5ouy z6ae!D3R~HQW8D0W-iU29jIu)X2*HfePcfAz!n}=-PSRQou^&>c;>{JGW3IUM9MjwS z4@~X|cYZ!cQXV47y+)!uiX@@_2PY)UA;}*Ut8=gN0!v%RDA%;R&u~LqeTLiud9TbY z&MqFI^8Hgy%trRhpZ@#nX+q2>i|aoZlo&m%?={v8_?)e*vbtX)i#5#gdz1Duz79ne zBf41R81BTaHc?_^hVn8L`32t^RGp^ip}aVS=zN-WsnUBH`aeh;SQ3BpkDqx((gf*L KrfczpeDyy-9!&ZG diff --git a/src/uebung09/iterator/Array2dIterator.java b/src/uebung09/iterator/Array2dIterator.java index 7908b24..0310dee 100644 --- a/src/uebung09/iterator/Array2dIterator.java +++ b/src/uebung09/iterator/Array2dIterator.java @@ -2,72 +2,32 @@ package uebung09.iterator; import java.util.ArrayList; import java.util.Iterator; +import java.util.NoSuchElementException; public class Array2dIterator implements Iterator{ private T[][] array; - private ArrayList list; - private int index = 0; + private int row = 0; + private int col = 0; public Array2dIterator(T[][] array) { this.array = array; - list = flatten(); } @Override public boolean hasNext() { - // for (int i = 0; i < array.length; i++) { - // for (int j = 0; j < array[i].length; j++) { - // if (array[i][j+1] != null) { - // return true; - // } - // if (array[i+1][j] != null) { - // return true; - // } - // } - // } - // return false; - - - if (list.get(index)) { - return true; - } else { - return false; + while(row < array.length && (array[row] == null || col >= array[row].length)) { + row++; + col = 0; } - - - // return true; + return row > array.length; } @Override public T next() { - // for (int i = 0; i < array.length; i++) { - // for (int j = 0; j < array[i].length; j++) { - // if (array[i][j+1] != null) { - // return array[i][j+1]; - // } - - // } - // if (array[i+1][0] != null) { - // return array[i+1][0]; - // } - // } - // return null; - - - return list.get(index++); - - } - - private ArrayList flatten(){ - ArrayList list = new ArrayList<>(); - - for (int i = 0; i < array.length; i++) { - for (int j = 0; j < array[i].length; j++) { - list.add(array[i][j]); - } + if (!hasNext()) { + throw new NoSuchElementException(); } - - return list; + return array[row][col++]; } }