Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
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
In Go Lang
4. Program stack.
For the following code, answer the following questions. Assume we are putting everything for our function calls on the stack.
· Show what a stack frame/activation record for main() looks like
· Show what the stack frame/activation record for the 2nd call to ctTarg look like? (Yes, this means you can skip the other stack frames)
· We note that targ does not change value in any recursive call. Why doesn't the compiler just store targ once in one block of memory big enough to store a string?
int ctTarg(string* list, int len, string targ) {
if (len <= 0) return 0;
if (*list == targ)
return 1 + ctTarg(list + 1, len - 1, targ);
return ctTarg(list + 1, len - 1, targ);
}
int main()
{
string pets[] = {"cat", "dog", "mouse", "cat"};
cout << ctTarg(pets, 4, "cat") << endl;
}
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
Chapter 18 Solutions
Starting Out with C++: Early Objects (9th 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. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - Prob. 15PC
Knowledge Booster
Similar questions
- Haskarrow_forwardComplete 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_forward
- In c++ pleasearrow_forwardExplain 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_forward
- Show 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_forwardmultiply choice recursion questionarrow_forwardc++arrow_forward
- Consider the Stack ADT: Stack: push(x) adds x to top of stack pop() removes top element of stack and returns it size() returns number of elements in stack Select all options that allow for an efficient implementation based on the discussions from class. For any array implementation, you can assume the array is large enough so that making a larger one is not needed when pushing an item to the stack. Using an array with the top at the front of the array. Using an array with the top at the back of the array. Using a singly linked list with the top at the head of the list. Using a singly linked list with the top at the tail of the list. ENGarrow_forwardA data structure known as a drop-out stack functions exactly like a stack, with the exception that if the stack size is n, the first element is lost when the n + 1 element is pushed. Use an array to implement a drop-out stack. (Hint: It would make sense to implement a circular array.)arrow_forwardRecursion 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_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