Hi everyone!
This might sound a noob question, but i never used a for cycle this way before.
I have a Vector which contains self defined Classes. These classes have 3 variables, i want to choose the Element which has the lovest sourceIndex. Then i would like to remove it from the Vector and start it again. I thought of this:
Question: If i have a vector of 3 elements, the inner cycle runs and removes one element, what happens then to the outer cycle? will realMatches.size( ) be calculated again(and set to 2) or will it be 3?
Another question: not using it here, but how can i use "break", to get out from the inner cycle, but still stay in the outer?
Thanks!
Aeren
PS: I can't test the code right now, but still i would like to know the working mechanics of my questions.
This might sound a noob question, but i never used a for cycle this way before.
I have a Vector which contains self defined Classes. These classes have 3 variables, i want to choose the Element which has the lovest sourceIndex. Then i would like to remove it from the Vector and start it again. I thought of this:
Code:
Vector realMatches; //it's already filled
[ ... ]
for( int j = 0; j < realMatches.size( ); j++ ) {
int biggestElementIndex = 0;
int biggestElementSIndex = realMatches.elementAt( 0 ).getSourceIndex( );
for( int i = 1; i < realMatches.size( ); i++ ) {
if ( realMatches.elementAt( i ).getSourceIndex( ) < biggestElementSIndex ) {
biggestElementSIndex = realMatches.elementAt( i ).getSourceIndex( );
biggestElementIndex = i;
}
}
realMatches.removeElementAt( biggestElementIndex );
}
Another question: not using it here, but how can i use "break", to get out from the inner cycle, but still stay in the outer?
Thanks!
Aeren
PS: I can't test the code right now, but still i would like to know the working mechanics of my questions.