Based on the class ArrayStack, create a function that has two stacks arguments. The function transfers...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Based on the class ArrayStack, create a function that has two stacks arguments. The function transfers the elements of the first stack to the second. The transfer is done in such a way that the elements that start at the top of the first stack are inserted first to the second stack and the elements at the bottom of S will be at the top of the second stack. Only use the methods defined in the ArrayStack. Your tasks include: a. Create the function (5 Marks) b. Demonstrate that the implementation of the created function works, to do so you can refer to this sample output: Stack S [10, 25, 15, 7] Length of stack S before the transfer: 4 Stack T [] Length of stack T before the transfer: 0 The item at the top of stack S: 7 the item at the top of stack T: 10 The transfer was done sucessfully Length of stack S after the transfer: 0 Length of stack T after the transfer: 4. Stack T after tranfer: [7, 15, 25, 10] Stack S after transfer: [] (6 Marks) [Sub Total 11 Marks] 2.2 Use the function that you have just created to replace the elements of the first stack in reverse order using two temporary stacks. Described how the arguments will be arranged in the function and describe the content that for each time the function is run. (9 Marks) 2.3 Based on the Arraystack class, you have the following stacks: R = [1,2,3], S = [4,5], and T = [6,7,8,9] and would like to proceed with some operations where you will end with R= [1,2,3] and S = [6,7,8,9,4,5]. How will you proceed if r, s and t represent the lend of these stacks. Do not write the code, rather describe the sequence of operations that will be required to achieve this. (10 Marks) Based on the class ArrayStack, create a function that has two stacks arguments. The function transfers the elements of the first stack to the second. The transfer is done in such a way that the elements that start at the top of the first stack are inserted first to the second stack and the elements at the bottom of S will be at the top of the second stack. Only use the methods defined in the ArrayStack. Your tasks include: a. Create the function (5 Marks) b. Demonstrate that the implementation of the created function works, to do so you can refer to this sample output: Stack S [10, 25, 15, 7] Length of stack S before the transfer: 4 Stack T [] Length of stack T before the transfer: 0 The item at the top of stack S: 7 the item at the top of stack T: 10 The transfer was done sucessfully Length of stack S after the transfer: 0 Length of stack T after the transfer: 4. Stack T after tranfer: [7, 15, 25, 10] Stack S after transfer: [] (6 Marks) [Sub Total 11 Marks] 2.2 Use the function that you have just created to replace the elements of the first stack in reverse order using two temporary stacks. Described how the arguments will be arranged in the function and describe the content that for each time the function is run. (9 Marks) 2.3 Based on the Arraystack class, you have the following stacks: R = [1,2,3], S = [4,5], and T = [6,7,8,9] and would like to proceed with some operations where you will end with R= [1,2,3] and S = [6,7,8,9,4,5]. How will you proceed if r, s and t represent the lend of these stacks. Do not write the code, rather describe the sequence of operations that will be required to achieve this. (10 Marks)
Expert Answer:
Answer rating: 100% (QA)
Task 1 Create a function to transfer the elements of the first stack to the second stack in reverse order Python class ArrayStack def initself selfitems def isemptyself return lenselfitems 0 def pushs... View the full answer
Related Book For
Data Structures and Algorithms in Java
ISBN: 978-1118771334
6th edition
Authors: Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
Posted Date:
Students also viewed these programming questions
-
Consider the function f(x) = (10 - x)/(x+11). What is the domain of the inverse function f(x)
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Implement the queue data structure using arrays of size 10 with the following functions Enqueue () - add {2,3,4,5,6,7,8} to the queue Dequeue() - remove 2 elements isFull() - check if the queue is...
-
The joint cost (in dollars) for two products is given by C(x, y) = 30 + x2 + 3y + 2xy where x represents the quantity of product X produced and y represents the quantity of product Y produced. (a)...
-
Blue-Eyed Beauty Supply is the talk of the town. When Elaine started her business, she had no idea it would evolve to be the number-one supplier of cosmetology products in the region. While her...
-
How is the worldwide trend towards urbanisation and greater overseas travel affecting opportunities for international selling?
-
Busytown Corporation, which manufactures shoes, hired a recent college graduate to work in its accounting department. On the first day of work, the accountant was assigned to total a batch of...
-
You have been hired to develop the launch of a new product for fast weight loss for a new start-up called ABC Company. Answer the following questions: How can you develop your competitive advantage...
-
A shell-and-tube exchanger with two tube passes is used to heat ethanol from 60F to 140F with steam condensing at 230F in the shell. The BWG 14 steel tubes are in. OD. The design overall coefficient...
-
Opening inventory at retail for an outerwear department is $575,000. Purchases retail for October are $290,000, net sales are $150,000, markdowns are $46,000, returns to vendors are $10,000,...
-
If you were asked to distill, down to their most essential parts, the constitutional right to privacy and the right to privacy as it applies to abortion, what elements would you include?
-
Explain the role of federal and state governments in the policymaking process?
-
Define the basic elements of health insurance
-
The ACA made it a priority to reduce the number of uninsured. At what point, if any, should the government step in to provide individuals with assistance to purchase insurance coverage? Do you think...
-
Explain the role of interest groups in the policymaking process?
-
Harris, while delivering parts to a customer for his employer, negligently ran into and injured Wolfe. Harris had been asked by his employer to make these deliveries even though Harris was using his...
-
Horse serum containing specific antibody to snake venom has been a successful approach to treating snakebite in humans. How do you think this anti-venom could be generated? What are some advantages...
-
Add support in LinkedBinaryTree for a method, pruneSubtree(p), that removes the entire subtree rooted at position p, making sure to maintain an accurate count of the size of the tree. What is the...
-
Draw a simple, connected, weighted graph with 8 vertices and 16 edges, each with unique edge weights. Identify one vertex as a start vertex and illustrate a running of Dijkstras algorithm on this...
-
In Section 5.2 we prove by induction that the number of lines printed by a call to drawInterval(c) is 2 c 1. Another interesting question is how many dashes are printed during that process. Prove by...
-
Describe circumstances that might cause a client to understate assets such as cash and financial investments.
-
What prevents the person who opens incoming mail from being able to abstract cash collections from customers?
-
Select the best answer for each of the following situations and give reasons for your choice. a. You have been assigned to the year-end audit of a financial institution and are planning the timing of...
Study smarter with the SolutionInn App