- #1
ineedhelpnow
- 651
- 0
which loop is correct for reversing a vector? please help.
A.
for (i = 0 ; i < NUM_ELEMENTS ; ++i ) {
tmpValue = revVctr .at (i ) ;
revVctr .at (i ) = revVctr .at (NUM_ELEMENTS - 1 - i ) ;
revVctr .at (NUM_ELEMENTS - 1 - i ) = tmpValue ;
}
B.
for (i = 0 ; i < (NUM_ELEMENTS / 2 ) ; ++i ) {
tmpValue = revVctr .at (i ) ;
revVctr .at (i ) = revVctr .at (NUM_ELEMENTS - 1 - i ) ;
revVctr .at (NUM_ELEMENTS - 1 - i ) = tmpValue ;
}
C.
for (i = 0; i < NUM_ELEMENTS; ++i) {
revVctr.at(i) = revVctr.at(NUM_ELEMENTS - i);
}
D.
for (i = 0 ; i < NUM_ELEMENTS ; ++i ) {
revVctr .at (i ) = revVctr .at (NUM_ELEMENTS - 1 - i ) ;
}
A.
for (i = 0 ; i < NUM_ELEMENTS ; ++i ) {
tmpValue = revVctr .at (i ) ;
revVctr .at (i ) = revVctr .at (NUM_ELEMENTS - 1 - i ) ;
revVctr .at (NUM_ELEMENTS - 1 - i ) = tmpValue ;
}
B.
for (i = 0 ; i < (NUM_ELEMENTS / 2 ) ; ++i ) {
tmpValue = revVctr .at (i ) ;
revVctr .at (i ) = revVctr .at (NUM_ELEMENTS - 1 - i ) ;
revVctr .at (NUM_ELEMENTS - 1 - i ) = tmpValue ;
}
C.
for (i = 0; i < NUM_ELEMENTS; ++i) {
revVctr.at(i) = revVctr.at(NUM_ELEMENTS - i);
}
D.
for (i = 0 ; i < NUM_ELEMENTS ; ++i ) {
revVctr .at (i ) = revVctr .at (NUM_ELEMENTS - 1 - i ) ;
}