Friday
April 18, 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 Programming - can anyone give me site about programming I need a sample...
math - A stadium have to section a & B . tickets for section A cost $A each . ...
FRENCH - HOW WOULD U SAY "TRAVEL SECTION" AS IN A NEWSPAPER SECTION. IM MAKING A...
PROBLEM SOLVING IN MATHEMATICS - The Andersons are buying a new home. They need ...
c programming - To see how the four steps of the software development procedure ...
c# programming - To see how the four steps of the software development procedure...
social - Ok, I think both of these are syndicated but im so confused! The type ...
social - Ok, I think both of these are syndicated but im so confused! The type ...
Spanish: H Barrero - Nada te turbe; nada te espante; todo se pasa; Dios no se ...
Spanish for Torey - oops! This was posted to H Barrero, the author! Nada te ...

Search
Members