Alice has three array-based stacks,A,B, and C , such that A has capacity100, B h
ID: 3649566 • Letter: A
Question
Alice has three array-based stacks,A,B, and C , such that A has capacity100, B has capacity 5, and C has capacity 3. Initially, A is full, and B and C are empty. Unfortunately, the person who programmed the class for these stacks made the push and pop functions private. The only function Alice can use is a static function, transfer (S,T ), which transfers (by iteratively applying the privatePop and push functions) elements from stack S to stack T until either S becomes empty or T becomes full. So, for example,starting from our initial con?guration and performing transfer( A,C ) re-sults in A now holding 97 elements and C holding 3. Describe a sequence of transfer operations that starts from the initial con?guration and results in B holding 4 elements at the end.
Explanation / Answer
//psuedocode { for i -> 1 to 32 { transfer(A,C) // Every transfer(A,C) gives A->97 and C->3, so after looping 32 times it will be A->4 and C->3*32 } then transfer(A,B) // this will transfer rest 4 from A to B }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.