Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Esimerkki pinon käytöstä

Code Block
#include &ltiostream><iostream>
#include "stack.h"

using namespace std ;

void main()
{
	    Stack <float> FloatStack ;
	    Stack <int> IntStack ;

	    FloatStack fs(5) ;
	    float f = 1.1 ;
	    cout << "laitetaan luku reaalilukupinoon fs" << endl ;
	    while (fs.push(f))
	    {
		        cout << f << ' ' ;
		        f += 1.1 ;
	    }
	    cout << endl << "Pino täynnä." << endl
	    << endl << "Otetaan elementi pinosta" << endl ;
	    while (fs.pop(f))
    		cout << f << ' ' ;
	    cout << endl << "pino tyhjä" << endl ;
	    cout << endl ;

	    IntStack is ;
	    int i = 1.1 ;
	    cout << "laitetaan luku kokonaislukupinoon" << endl ;
	    while (is.push(i))
	    {
		        cout << i << ' ' ;
		        i += 1 ;
	    }
	    cout << endl << "pino täynnä" << endl
	    << endl << "otetaan elementti pinosta" << endl ;
	    while (is.pop(i))
			        cout << i << ' ' ;
	    cout << endl << "pino tyhjä" << endl ;
}