00:01
This question is given that we have a deck d containing the numbers 1, 3, 4, 5, 6, 7, 8 in that order.
00:07
And suppose that we have also an initial q.
00:10
We're asked to give a code fragment that uses only d and q and no other variables, and results in d storing the elements in the same order, 1, 3, 4, 6, 7, 8.
00:24
So we need to rearrange d from 1, 3, 4, 5, 6, 7, 8 to 1, 2, 3, 5, 6, 7, 8 to 1, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7.
00:31
By using only d and q.
00:37
So the code fragment we'll have is the steps will take, right? initially we'll have d and we'll have q initialized and then we'll start by popping the first three elements from d into q, then pop the 4 from the beginning of d to its end, then pop the 5 from the beginning of d, add that to q, then pop the 4 from the back of d, add that to q, and then pop the last three from d and add them to q, and then we'll refill d in the the new order.
01:04
So to make that easier, i'll just write out what i'm saying.
01:07
So we'll have deck integer d equals a new array deck.
01:22
And then inside arrays dot as list.
01:28
And then the list will have one, two, three, and then list them using commas all the way to eight...