Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 13PC
Program Plan Intro
Stack Based Fibonacci Function
Program Plan:
- Define the main function.
- Include required header files.
- Prompt user to enter a positive integer till which fibonacci series needs to be found.
- Print the Fibonacci series.
- Create a fibonacci function that computes the last term of the fibonacci sequence using stack operations.
- Push the first two terms of the Fibonacci sequence into a stack using the push () operation.
- Push the rest of the terms from 2 till last term into the stack.
- Pop last two elements off the stack using the stack pop() operation.
- The sum of element t1 and t2 is calculated and pushed onto the stack.
- Return element present at top of the stack.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write 2 recursive functions
1. to count number of even values in an
array
2. to count number of even values in a
simply linked list
A tail recursion is a type of recursion in which the access of the tail pointer of a linked list is recursive
a) true
b)false
Hask
Chapter 18 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - The STL stack is considered a container adapter....Ch. 18 - What types may the STL stack be based on? By...
Ch. 18 - Prob. 7RQECh. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - Prob. 17RQECh. 18 - Prob. 18RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Prob. 6PCCh. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 14PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 15PC
Knowledge Booster
Similar questions
- Complete using Standard C programming. Implement a singly linked list that performs the following: Displays the maximum value in the linked list using recursion. Displays the linked list in reverse order using recursion. Merge two single linked lists and display.arrow_forwardalgorithm trace Write a recursive function to find summation of the first n positive numbers (for example, if n=5 then summation of 1+2+3+4+5=15). Then, trace its execution by showing stack contents.arrow_forwardIn c++ pleasearrow_forward
- Explain how to use a stack to remove recursion.arrow_forwardQuestion 1:Convert a decimal to binary and binary to decimal using recursionTest your implementation with following examples:● (1947)10 = (11110011011)2● (1992)10 = (11111001000)2● (2021)10 = (11111100101)2Question 2:Implement a member function that prints a singly linked list in reverse order without creating acopy or changing the original List.void printBackwards() constQuestion 3:Implement a recursive member function “isSorted” which recursively checks whether the linked listis sorted (ascendingly).bool isSorted() constQuestion 4:You will implement a function bool Equalize_Occurrences (char key, int maxcount) of theclass list, that will take a character key and maximum count for the consecutive occurrences of thekey inparameters. It will then traverse the list, verify and update the consecutive occurrences of the keyaccordingto maximum count and returns true. It returns false if no occurrence of key is found.Note: You can traverse the list only once for this task.arrow_forwardShow a complete run of Quicksort on the following array X :X: 1 2 3 4 5 6 7 8 9 1017 5 -3 40 46 50 16 0 22 4 show all recursive calls using the stack below. Show the results of each call to below Split on a newline in the table to the left.arrow_forward
- Recursion and list processing Write a maxel that returns the maximum element in an arbitrarily complex list (e.g., list that may contain lists, which may contain lists, and so on). For example, (maxel '(((5)) (9 (3)) 7)-> 9arrow_forwardHelp me with question please. Thank You EXERCISE 2 May use either stack array implementation or stack linked list implementation.arrow_forwardAlgorithmarrow_forward
- 1. a function that takes in a list (L), and creates a copy of L. note: The function should return a pointer to the first element in the new L. [iteration and recursion]. 2. a function that takes in 2 sorted linked lists, and merges them into a single sorted list. note: This must be done in-place, and it must run in O(n+m).arrow_forwardShow the call stack for sort([2, 3, 5, 1]) using the function defined inListing 15.5. LISTING 15.5 RecursiveSelectionSort.py1 def sort(lst):2 # Sort the entire list345 if low < high:6 # Find the smallest element and its index in lst[low .. high]7 indexOfMin = low 8 min = lst[low]9 for i in range(low + 1, high + 1):10 if lst[i] < min:11 min = lst[i]12 indexOfMin = i1314 # Swap the smallest in lst[low .. high] with lst[low]15 lst[indexOfMin] = lst[low]16 lst[low] = min1718 # Sort the remaining lst[low+1 .. high]192021 def main():22 lst = [3, 2, 1, 5, 9, 0]23 sort(lst)24 print(lst)2526 main() # Call the main functionarrow_forwardRecursive Multiplication Given an JavaScript object list of books that each have a pages attribute to define the number of pages in the book, find the product of all the pages in the object list of books using recursion (you must use recursion to solve this problem). Keep in mind: The input list object may be completely empty (ex. {}) The next attribute may not be defined function getPageCount(list) {// your code here// returns an integer}Example test case:Input: {"book":"A","pages":1,"next":{"book":"B","pages":2,"next":{"book":"C","pages":3,"next": null}}}Output: 6Reasoning: 1 * 2 * 3 pagesarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education