Write the pseudo code of the function isSorted (Stack S) that takes as parameter a stack...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write the pseudo code of the function isSorted (Stack S) that takes as parameter a stack S, and checks if the stack is sorted (either in increasing or decreasing order) or not. When the function is done, the stack should be in its original state. The only operations that you can do on the stack are the following: push(), pop 0, top (), isFullStack(), and isEmptyStack(). You are allowed to use only one extra stack data structure. No additional arrays or lists. You answer should be similar the example that was presented in the lecture and here it is again. Question: Write the pseudo-code for an algorithm to reverse the order of elements on a stack with n elements. The algorithm should use two additional stacks. Answer: while (!S.isEmpty()) S1. push (S.pop(); while (!S1.isEmpty()) S2. push (S1.pop()); Reverse everything from S into S1 Reverse everything from S1 into S2 while (!S2.isEmpty ()) S. push(S2.pop()); Reverse everything from S2 into S Write the pseudo code of the function isSorted (Stack S) that takes as parameter a stack S, and checks if the stack is sorted (either in increasing or decreasing order) or not. When the function is done, the stack should be in its original state. The only operations that you can do on the stack are the following: push(), pop 0, top (), isFullStack(), and isEmptyStack(). You are allowed to use only one extra stack data structure. No additional arrays or lists. You answer should be similar the example that was presented in the lecture and here it is again. Question: Write the pseudo-code for an algorithm to reverse the order of elements on a stack with n elements. The algorithm should use two additional stacks. Answer: while (!S.isEmpty()) S1. push (S.pop(); while (!S1.isEmpty()) S2. push (S1.pop()); Reverse everything from S into S1 Reverse everything from S1 into S2 while (!S2.isEmpty ()) S. push(S2.pop()); Reverse everything from S2 into S
Expert Answer:
Answer rating: 100% (QA)
Python programing language to recreate stack elements in the same order by using extra ... View the full answer
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Write a method called removeZeroe s that takes as a parameter an ArrayList of integers and eliminates any occurrences of the number 0 from the list. For example, if the list stores the values [0, 7,...
-
Write a method called rangeBetweenZeroe s that takes as a parameter an ArrayList of integers and returns the number of indexes apart the two farthest occurrences of the number 0 are. For example, if...
-
In Figure two isotropic point sources S1 and S2 emit light in phase at wavelength 1 and at the same amplitude. The sources are separated by distance d = 6.00? on an x axis. A viewing screen is at...
-
Can you find a function such that (-2) = -2, (2) = 6, and '(x) < 1 for all x? Why or why not?
-
Give a brief explanation of the economic impact of tourism. Name two organizations that influence or further the economic impact of tourism.
-
Analyzing account balances and reconhsetprhue cting transactions Yi Min started an engineering firm called Min Engineering. He began operations and completed seven transactions in May, which included...
-
Find an article that discusses ethics and the use of social media by paralegals.
-
On January 1, Year 6, HD Ltd., a building supply company, JC Ltd., a construction company, and Mr. Saeid, a private investor, signed an agreement to carry out a joint operation under the following...
-
Quanta Inc. has a beta of 1.5. The market risk premium is 7% and the risk-free rate is 3%. Assuming that the market is in equilibrium and the stock currently sells for $30 a share, Quanta just paid...
-
The following trial balance of Oakley NV does not balance. Each of the listed accounts should have a normal balance per the general ledger. An examination of the ledger and journal reveals the...
-
A mixture consisting of isobutane, n-butane, isopentane and n- pentane is to be distilled. The following tabulation gives the composition of the streams in mole fraction: isobutane n-butane...
-
Use the prime rate data given in Table 3.6 in the text to construct cumulative frequency and cumulative relative frequency tables. Table 3.6 Class (%) 0-1.49 1.50-3.49 3.50-5.49 5.50-6.49 6.50 and...
-
Choose five companies from different industries and locate their statements of cash flows for the most recent year. (a) Create a table to compare the dollars provided or used by operating, investing,...
-
Tequila Crisis (D) (web exercise). Log in to IMF International Financial Statistics to present and analyze Mexicos official reserve account over the period 19921996. What can you infer about Mexicos...
-
You are given the following exchange rate information for the number of dollars it takes to buy 1 British pound and the number of dollars it takes to buy 100 Japanese yen: (a) Draw a line chart...
-
Gentilotti, father of an illegitimate son, drew a check for $20,000 in 1969 payable to the sons order. The check was dated July 1, 1985, but provided on the face of the check that, should Gentilotti...
-
Prepare journal entries as below: The budget for FY 20x5 provided for General Fund estimated revenues totaling $3,100,000 and appropriations totaling $3,140,000. The property tax levy for FY 20x4 was...
-
Modify the counter from Exercise 5.44 such that the counter will either increment by 4 or load a new 32-bit value, D, on each clock edge, depending on a control signal Load. When Load = 1, the...
-
What is the most likely system acquisition method in-house, turnkey, backbone, or vendor-supported for each of the following situations? A plumbing supply company with I2 employees that sells...
-
How can spooling present an added exposure?
-
What are the primary goals of lean manufacturing?
-
Comment on the dividend yield of Alemouth plc.
-
Comment on the relationship between the net assets per share of Beermouth plc and its share price (or on the relationship of the total of shareholders funds to the market capitalization).
-
What is the level of the FTSE 100 today? What is the average P/E ratio of the top 100 companies? What is their dividend yield and dividend cover? You are given the following information about the...
Study smarter with the SolutionInn App