Create a function that takes a list of functions and sorts them in ascending order based on how many calls are needed for them to return a non-function. Examples f1 ==> "hello" // f1() → "hello" f2 = => // f2() () "edabit" => "edabit" f3 = => => => "user" // f3() () () → "user" funcSort ([f2, f3, f1]) → [f1, f2, f3] // [f2, f3, f1] [2, 3, 1] [1, 2, 3] 1 funcSort ([f1, f2, f3]) → [f1, f2, f3] // [f1, f2, f3] - [1, 2, 3] [1, 2, 3] - funcSort([f2, "func"]) // [f2, "func"] [2, 0] - ["func", f2] - - [f1, f2, f3] [f1, f2, f3] [0, 2] - ["func", f2]

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 17PE
icon
Related questions
Question

Answe the Question

Create a function that takes a list of functions and sorts them in ascending order based on
how many calls are needed for them to return a non-function.
Examples
f1 = => "hello"
// f1() → "hello"
f2 = => => "edabit"
// f2() () → "edabit"
f3 = _ => => => "user"
// f3() () () → "user"
funcSort([f2, f3, f1]) → [f1, f2, f3]
// [f2, f3, f1] [2, 3, 1] → [1, 2, 3] → [f1, f2, f3]
-
funcSort([f1, f2, f3])
// [f1, f2, f3]
-
[f1, f2, f3]
[1, 2, 3] - [1, 2, 3] → [f1, f2, f3]
funcSort ([f2, "func"])
// [f2, "func"] -
-
["func", f2]
[2, 0] 1 [0, 2] ["func", f2]
Transcribed Image Text:Create a function that takes a list of functions and sorts them in ascending order based on how many calls are needed for them to return a non-function. Examples f1 = => "hello" // f1() → "hello" f2 = => => "edabit" // f2() () → "edabit" f3 = _ => => => "user" // f3() () () → "user" funcSort([f2, f3, f1]) → [f1, f2, f3] // [f2, f3, f1] [2, 3, 1] → [1, 2, 3] → [f1, f2, f3] - funcSort([f1, f2, f3]) // [f1, f2, f3] - [f1, f2, f3] [1, 2, 3] - [1, 2, 3] → [f1, f2, f3] funcSort ([f2, "func"]) // [f2, "func"] - - ["func", f2] [2, 0] 1 [0, 2] ["func", f2]
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning