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...
-
Ten thousand airline reservation stations are competing for the use of a single slotted ALOHA channel. The average station makes 18 requests/hour. A slot is 125 sec. What is the approximate total...
-
Does 17 divide each of these numbers? a) 68 b) 84 c) 357 d) 1001?
-
The tube shown in Figure 9.8 is subjected to an internal pressure, \(p=5 \mathrm{MPa}\), instead of a torque. Neglecting the stress along the longitudinal axis of the tube, and assuming that the mode...
-
Profit margins and turnover ratios vary from one industry to another. What differences would you expect to find between a grocery chain such as Safeway and a steel company? Think particularly about...
-
Primare Corporation has provided the following data concerning last month's manufacturing operations. Purchases of raw materials Indirect materials used in production Direct labor $ 30,000 $ 4,790 $...
-
The Excel worksheet form that appears below is to be used to recreate the Review Problem related to Mynor Corporation. Download the workbook containing this form from Connect, where you will also...
-
When conducting a review engagement of a nonissuer, each of the following is considered an analytical procedure, except a comparison of the current-year's financial information to A. Expectations...
-
How has the role of HRM changed in recent years? Discuss three trends that are changing the HRM function. Why have these roles changed?
-
Compare and contrast the various worker's representation models that exist in Japan and United States of America. Give examples related.
-
Compare and contrast various models of worker's representation that exists in the US and Japan. Gi ve examples of your answers.
-
Role of HR analytics in aligning HRM to an organisations strategic goals You can focus on a certain aspect of the topic. Do ensure that the focus you place and the examples you choose are relevant to...
-
Explain the meaning of the terms arbitrable and inarbitrable . Provide an example for each At an arbitration hearing either of the parties can make arguments in the alternative Explain what this...
-
which of the following is correct? Efficiency means that investors wont earn profits for an extended period of time. Efficiency means that investors wont earn normal profits for an extended period of...
-
What are technical skills At what level are they most important and why?
-
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...
-
Using the data in exercise 2, determine how many units of resources the firm will want to acquire. Data from in exercise 2 Using the information in the following table, calculate the marginal revenue...
-
What does it mean to say that the demand for resources is a derived demand? Is the demand for all goods and services a derived demand?
-
Using the information in the following table, calculate the marginal revenue product (MRP = MPP MR). Unit of Resources Total Resource Output Price Price 1 10 $5 $10 2 25 $5 $10 345 35 $5 $10 40 $5...
Study smarter with the SolutionInn App