Modify this pop() function, so that it uses recursion.

Assignment Help C/C++ Programming
Reference no: EM13937016

1. Modify this pop() function, so that it uses recursion.

int Stack::pop()
{
if (isEmpty())
{
cerr << "Attempting to Pop from an Empty stack!!" << endl;
return -1;
}
else
{
int temp = nodes[curTop];
curTop--;
return temp;
}

}

2. Rewrite the following power() function so that it uses recursion. Provide a function main to test the implementation.

power.cpp

#include <iostream>

using namespace std;

int power(int number, int exponent)
{
int retval = 1;
for (int i=0; i < exponent; i++)
{
retval = retval * number;
}
return retval;
}

int main(int argc, char **argv)
{
cout << power(2, 3) << endl;
cout << power(3, 6) << endl;
cout << power(4, 9) << endl;

return 0;
}

Reference no: EM13937016

Questions Cloud

Most effective websites that reflect : Write extended paragraphs to answer each question below. Answer ALL PARTS of the question. Your answers may consist of 3 or 4 paragraphs for each question.
Conduct a marketing audit for an organisation : Conduct a marketing audit for an organisation of your choice and propose EITHER a new product/service (or new variant) for inclusion in the organisation's portfolio OR a new communication plan for an existing product/service
What viruses were very deadly and were eliminated : The rapid rate of reproduction combined with the many different mutations has had a limiting effect on the effectiveness of HIV therapy using antibiotics. Without the mutations the virus would fall victim to antibiotics.Are there other viruses whi..
What is the importance of chain of custody : Explain and describe the best practices for collection, preservation, transportation, and storage of electronic evidence. What is the importance of chain of custody as it relates to computer crime
Modify this pop() function, so that it uses recursion. : Rewrite the following power() function so that it uses recursion. Provide a function main to test the implementation.
Integrated marketing communications plan report : Development of a comprehensive, detailed Integrated Marketing Communications plan report and presentation - 1400 - 1500 words.
Network according to a business specification : Networks are fundamental to every aspect of our society. Designing a network that is both adequate to current and future needs is important. In this assignment, you are asked to design a network according to a business specification. Business Str..
Is evolution a proven fact or a theory : Is "evolution" a proven fact or a theory? What other ideas compete with evolution to explain changes in populations? What are the differences between these competing ideas?
What type of nic is installed in your comptuter : What type of NIC is installed in your comptuter - an expansion card, a wireless card or an embedded NIC?  Use the status of your Local Area Connection object to determine the speed of your network adapter

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Type two numbers from range 20-60

Ask the user to type two numbers from range 20-60. Keep on asking until he types in the range of 20-60. Display the numbers between those two numbers in ascending order.

  Logical address of an instruction

Consider the logical address of an instruction in a program memory is 7632 and the contents of relocation register are 2500. To which location in the memory will this address be mapped?

  Write a c program that copies the contents of one file

write a c program that copiest the contents of one file to a destination file. This program works by first prompting the user for the name of the source file and destination file.

  Create valle products accdb database file

Create a new table named Orders using the table design below. You may create your table in design view or datasheet view. Save the Orders table as Orders Your Name. Define a one-to-many relationship between the Customer table and Orders table. Ri..

  Modify the program in 6a so that, in addition to the cents

Modify the program in 6a so that, in addition to the cents, the user enters the denomination of the coin to which to convert the pennies, such as 5 for nickles or 25 for quarters.

  Use structures to create c program to compute student record

Explain the following and give their suitable syntax. A pointer. Use structures to create C program to compute and store student records of class.

  Programing for financial system

Write c++ programing for financial system using class and object

  Potential classes to be implemented in the future

Discuss any potential classes to be implemented in the future

  Functions to make a main program

write the required functions to make a main program that is already written

  Implement a class called hugeinteger

Using your own Linked List implementation (see attached), implement a class called HugeInteger that represents arbitrary sized integers and supports addition only. You may only use the tools that have introduced in class, and you MAY NOT use Java'..

  Create a class called bank account

Create a class called BankAccount. The BankAccount class should contain a String to store the customer name and a double to store the account balance. The BankAccount class should have two constructors, as follows

  Write a menu-driven c program

Write a menu-driven C program with appropriate functions that allows the user to fill an array of 50 integers with random numbers on the range 1...999, inclusive, sort it, and then find search it to determine if a given random number was generated..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd