Finally store the profits of all the transactions
while ( ! transaction . isEmpty ( ) ) { profits . add ( prices [ transaction . peek ( ) [ 1 ] - 1 ] - prices [ transaction . peek ( ) [ 0 ] ] ) ; transaction . pop ( ) ; }