Thursday
July 24, 2014

Homework Help: programming

Posted by Aleen on Saturday, January 14, 2012 at 10:28pm.

I need help in the TODO section.
/**
* Driver.cpp - This file contains the driver code to test the
* linkedStackType class implementation
*
*/

#include <iostream>

#include "linkedStack.h"

using namespace std;

template <class Type>
void printStack(linkedStackType<Type>& stack);

template <class Type>
void transferStack(linkedStackType<Type>& stack1,
linkedStackType<Type>& stack2);

int main(int argc, char *argv)
{
// Declare stack variables
linkedStackType<int> stack1;
linkedStackType<int> stack2;

// Add some data to stack 1
stack1.push(21);
stack1.push(13);
stack1.push(43);
stack1.push(15);
stack1.push(62);
stack1.push(74);

cout << "\nStack 1:\n ";
printStack(stack1);


cout << "\nStack 2:\n ";
transferStack(stack1, stack2);
printStack(stack2);

cout << "\nStack 1 is unchanged:\n ";
printStack(stack1);

cout << "\n\n** Press any key to continue **\n";
getchar();

return 0;
}

template <class Type>
void printStack(linkedStackType<Type>& stack)
{
Type item;
linkedStackType<Type> tmpStack = stack;

while (stack.isEmptyStack() == false)
{
item = stack.top();
stack.pop();
cout << item << " ";
}

stack = tmpStack;

}

template <class Type>
void transferStack(linkedStackType<Type>& stack1,
linkedStackType<Type>& stack2)
{
// TODO: implement the transferStack() function so that the items
// found in stack1 are placed in the same order into stack2.
//
// Suggestions:
// 1. Create a Type item variable and a temporary stack like
// those found in the printStack() function, but do not
// initialize the temporary stack.
//
// 2. Create a while-loop to walk through the items in stack1.
// Place each of these items on the temporary stack using the
// push() method.
//
// 3. Create a second loop to walk through the temporary stack and
// place each item on stack2.
//
// 4. Finally, set stack1 equal to stack2 so that stack1 will
// remain unchanged.

return;
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

computer science - Algorithm for Binomial Numbers Task Binomial numbers (or ...
computer science - ineed help with c++. i am using code blocks and i have a ...
C++ Algorithms - Binomial numbers (or binomial coefficients) are important ...
computer programming - Construct a structure chart, as well as a flowchart and ...
Programming Problems - Include names of students from the user, terminated by ...
Driver Education - I'm attempting to schedule a road test so I can obtain a ...
language - In this case, the injured driver received payment from his own ...
C++ Programming - Hello. I use Visual C++ 2010 Express and don't know why this ...
C++ Programming - I have to redo programming exercise 5 of chapter 9 using ...
bcis MS Projects - I downloaded the trail version. got the free key code...the ...

Search
Members