hi everyone..
i need to ask 2 questions..
first..is the below code done using recursion or not?
second..i have 2 errors in the following code..they relate to x.push(item); and x.print_reverse();
Quote:
1- error C2664: 'stack: : push' : cannot convert parameter 1 from 'ItemType' to 'int'
2- error C2660: 'stack: : print_reverse' : function does not take 0 arguments
1>unsorted list - 2 error(s), 0 warning(s)
the code is here:
Code:
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include<cstdlib>
#include <fstream>
using std::ifstream;
using std::ofstream;
#include"ItemType.h"
using namespace std;
class stack
{
private:
        static const int MAX=10;  
        int st[MAX];
        int top;
public:
               stack():top(-1){}
               void push(int v){st[++top]=v;}
               int pop(){return st[top--];}
               bool isempty(){return (top==-1);}  
               bool isfull(){return top==MAX-1;} 

void print()
{
while(!isempty())
cout<<pop()<<endl;
}
void print_reverse(int i)
{
if( i < MAX)
        		print_reverse(++i);
cout << st[i] << "\n";
}};
int main()
{  
stack x;
int data;
ItemType item;

	ifstream instream; 
	ofstream outstream;

while(!x.isfull()) 
{

	while ( !instream.eof() )
	{	
		instream>> data;	
		item.Initialize(data);
		x.push(item); 
		x.print();

	}
	instream.close();
}
cout<<"--------\n";
x.print_reverse();
cin.get();
    return 0;
}

Last edited by elsa87; 24Nov2008 at 22:27..