Question 4. Cool numbers [12 points] A number is COOL if the sum of two opposite...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 4. Cool numbers [12 points] A number is COOL if the sum of two "opposite" digits in base 10 is always 10. More precisely if the digits are ad ad-1... a1 a0 then the number is cool if ad+ao=10, ad-1+a₁ =10,..., a₁ + ad-1-10, ao+ad =10. For example, 1829 is cool, 18529 is cool, 721933 is not cool. Note that 7212983 is not cool since a3-2 and 2+2+ 10, but 7215983 is cool since a3-5 and 5+5=10. In this problem, the digits of the number are stored in nodes of a singly-linked list L. You are only allowed to read or process each list node only once. Give pseudocode or Java-like code for a method that uses a stack and a queue to determine if the number is cool. boolean sCool ( LinkedList<Integer> L) { // Write a code that returns true if the number is cool and false if it is not. } Note: You do not need to give the implementation for the stack or the queue. Just assume these classes exist and have their standard methods. In addition to the queue and stack, you are only allowed a constant amount of temporary variables, so you cannot use another array, for example. Question 4. Cool numbers [12 points] A number is COOL if the sum of two "opposite" digits in base 10 is always 10. More precisely if the digits are ad ad-1... a1 a0 then the number is cool if ad+ao=10, ad-1+a₁ =10,..., a₁ + ad-1-10, ao+ad =10. For example, 1829 is cool, 18529 is cool, 721933 is not cool. Note that 7212983 is not cool since a3-2 and 2+2+ 10, but 7215983 is cool since a3-5 and 5+5=10. In this problem, the digits of the number are stored in nodes of a singly-linked list L. You are only allowed to read or process each list node only once. Give pseudocode or Java-like code for a method that uses a stack and a queue to determine if the number is cool. boolean sCool ( LinkedList<Integer> L) { // Write a code that returns true if the number is cool and false if it is not. } Note: You do not need to give the implementation for the stack or the queue. Just assume these classes exist and have their standard methods. In addition to the queue and stack, you are only allowed a constant amount of temporary variables, so you cannot use another array, for example.
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
103) What time-saving options are available to a busy manager who needs to conduct a job analysis and write job descriptions? Explain your answer in a brief essay. 104) What are the advantages and...
-
Need help in this homework In this problem, you will learn how to perform an impressivemagic trick. As all tricks, once you understand it, it becomes lessimpressive. But then you can impress other...
-
Using priority queues to implement a loan approval system for a financial institute that funds startups. Problem: Our financial institute receives many loan applications and rejects them only if the...
-
At the beginning of compression in a diesel cycle, T = 540 R, P = 30 lbf/in. 2 , and the state after combustion (heat addition) is 2600 R and 1000 lbf/in. 2 . Find the compression ratio, the thermal...
-
Your classmate says that the speed of sound and the frequency of sound depend on the medium in which the sound travels. What part of this statement do you disagree with?
-
Piper High School is in Piper, Kansas, a town located about 20 miles west of Kansas City, Missouri. Christine Pelton was a high school science teacher there. Ms. Pelton, age 26, had a degree in...
-
The heat equation problem is solved using the explicit scheme (6.2). Find the maximum grid steps \(\Delta x\) and \(\Delta t\) at which the expected error of the solution is less than \(\sim...
-
Picard Landscaping plants grass seed as the basic landscaping for business campuses. During a recent month, the company worked on three projects (Remington, Chang, and Wyco). The company is...
-
Y8 . TD Bank believes Swedish krona (SEK) will depreciate over the next 45 days from $0.097 to $0.095. The following annual interest rates apply: Currency Lending Rate Borrowing Rate Dollars 7.20%...
-
Go Times Inc. has current sales of $7,500 (in millions), an operating ratio of 6%, a capital requirement ratio of 40%, a tax rate of 40% and a corporate cost of capital of 8%. Under new management...
-
1. What is the mutation that causes 70% of cases of Cystic Fibrosis? Does it cause a frameshift? What is the inheritance pattern of the disease? What population has a high number of heterozygotes? 4...
-
Puan Delima is considering depositing her money into one of the banks for three years. She now has RMIO,OOO in her hand. She is considering the three following alternatives: Alternative 1: Bank A...
-
Injury year | Estimated # | Estimated $/p 1994 | 1,021 | $415,326.26 1995 |1,087 | $448,871.57 1996 |1,184 | $477,333.66 1997 |1,291 | $490,215.19 1998 |1,191 | $516,696.63 1999 |1,098 | $587,233.93...
-
What are the molecular interactions involved in signal transduction pathways, and how do these pathways regulate cellular responses to extracellular stimuli, particularly in the context of...
-
includes any criminal activity which involves the unauthorized access, dissemination, manipulation, destruction, or corruption of electronically stored data. Identity theft Digital crime Organized...
-
Assuming market risk premium is 9% and risk free rate is 3%. a)What is the expected return on the market? b) What is beta for a security that has a required rate of return of 15%? c)If this stock is...
-
The consulting agency looks for available land in a region to build a centrally located water/wastewater treatment facility. They then prepare capital investment estimates for the country. The...
-
What is the difference between direct materials and indirect materials?
-
Assuming that chemical types and bolts are fixed, estimate the model parameters i and j in Problem 4-1. Problem 4-1. A chemist wishes to test the effect of four chemical agents on the strength of a...
-
The breaking strength of a fiber is required to be at least 150 psi. Past experience has indicated that the standard deviation of breaking strength is = 3 psi. A random sample of four specimens is...
-
Repeat Problem 7-7 assuming that four blocks are necessary. Suggest a reasonable con-founding scheme. Problem 7-7 An experiment was run in a semiconductor fabrication plant in an effort to increase...
-
Which statement is false? a. Waste Management made top drawer entries. b. Richard Scrushy of Tyco was never convicted. c. Adelphia used special purpose entities to commit their fraud. d....
-
Which statement is false? a. SASNo. 99 does not prohibit clients from preparing confirmations. b. Enron issued \(\$ 1.2\) billion of stock to an SPE and recorded a \(\$ 1.2\) billion notes...
-
Who is responsible for internal controls? a. External auditors b. Internal auditors c. Management d. Audit Committee e. Board of Directors
Study smarter with the SolutionInn App