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

  A palindrome is a number

A palindrome is a number or text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 34543 and 11611. Write a program that reads in a five-digit integer and determines ..

  The rpn calculator program

The RPN calculator program should read the RPN expression as an entire line from stdin.Input will consist of a single line. After completing the evaluation of the expression, the program should print the contents of the entire stack, starting with th..

  Implement random class for generating pseudo-random numbers

Implement a Random class for generating pseudo-random numbers. Implement a Person class. Each object of this class will represent a human being.

  Write a function that takes two point arguments

Write a function that takes two POINT arguments and returns the midpoint between them and define a function distance() that takes two POINT arguments and returns the distance between them.

  What is the size of int in a 64 bit compiler

Can you explain the question in detail - What is the size of int in a 64 bit compiler?

  Prototypes would work for the function called func

Consider the following: int anArray[3][5] =

  Write a program which allows the user to perform simple task

Write a program which allows the user to perform simple tasks on a calculator. A series of functions allows the user to select an operation to perform and then enter operands.

  A list of toppings should be shown on the screen as a menu

Write a menu-driven C++ program that allows a user to select from the following items: Pizza, Cheeseburger, and Hot Dog. Pizza should be represented by the integer value 1. Cheeseburger should be represented by the integer value 2.

  Q1nbspnbspwrite c statements to do the following1 declare

q1nbspnbspwrite c statements to do the following1. declare an array alpha of 15 components of the type int.2. output

  Write a program for implementing array abstract data type

Write a program for implementing array abstract data type.

  Write a very basic doubly-linked list

CptS 122 Lab #2: Linked Lists ,  Along with vectors, linked lists are one of the fundamental data structures in computer science. Unlike vectors, which store information in a contiguous block of computer memory, linked lists have the potential to sto..

  Time constraints and the type of audience

Your supervisor agrees with your proposal but warns you of time constraints and the type of audience you have. Your supervisor outlined the following requirements for you to follow:

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