Reference no: EM132170639
Using Java, in this problem two stacks A and B are to be manipulated using the following operations (n denotes the size of A and m the size of B):
- PushA (x): Push element x on stack A.
- PushB (x): Push element x on stack B.
- MultiPopA (k): Pop min {k, n} elements from A.
- MultiPopB (k): Pop min {k, m} elements from B.
- Transfer (k): Repeatedly pop an element from A and push it on B, until either k elements have been moved or A is empty.
It is assumed that A and B are to be implemented using doubly-linked lists such that PushA and PushB , as well as a single pop from A or B, can be performed in O (1) time worst-case.
Implement the the above operations as their own methods. You are allowed to use the code provided under Support Documents as a starting point.