Ejemplo n.º 1
0
int main()
{
	LIFO_Stack st;
	string str;
	while(cin>>str&&!st.full())
		st.push(str);
	cout<<'\n'<<"About to call peek with LIFO_Stack"<<endl;
	peek(st,st.top()-1);
	cout<<st;

	Peekback_Stack pst;
	while(!st.empty())
	{
		string t;
		if(st.pop(t))
			pst.push(t);
	}

	cout<<"About to call peek() with Peekback_Stack"<<endl;
	peek(pst,pst.top()-1);
	cout<<pst;

	system("pause");
	return 0;
}
Ejemplo n.º 2
0
void ex5_1()
{
	/*
	once upon a time
	About to call peek() with LIFO_Stack  
    peek failed!

        time
        a
        upon
        once

    About to call peek() with Peekback_Stack
    peek: once

        once
        upon
        a
        time
	*/

	LIFO_Stack st;
	string str;

	cout << "Please enter a series of strings.\n";

	while ( cin >> str && ! st.full() )
		    st.push( str );

	cout << endl << "About to call peek() with LIFO_Stack" << endl;
	peek( st, st.top()-1 );
	cout << st;

    Peekback_Stack pst;
    while ( ! st.empty() ) {
		string t;
		if ( st.pop( t ))
		     pst.push( t );
	}

	cout << "About to call peek() with Peekback_Stack" << endl;	        
	peek( pst, pst.top()-1 );
	cout << pst;
}