/* 
   Laboratorium Praktyki Programowania  
*/


/* Należ pozostawić definicję tylko jednej ze stałych : */

/* dla nowszych kompilatorów */
#define ANSI

/* dla starszych kompilatorów */
//#define ARM


#ifdef ANSI
#include <iostream>
#include <cstring>
using namespace std;
#endif

#ifdef ARM
#include <iostream.h>
#include <string.h>
#endif

#define MAX 40
/** Program z implementacją stosu - kolejki LIFO (Last In First Out) */

typedef char Elem[MAX];

typedef struct lifo{
  Elem napis;
  struct lifo *nast;
} Lifo;

Lifo *Stos=NULL;;
                        
/** Push odkłada element na stos */
void Push(Elem napis){
  Lifo *nowy=new Lifo;
  strcpy(nowy->napis,napis);
  nowy->nast=Stos;
  Stos=nowy;
}

/** Pop zdejmuje elementu ze stosu */
void Pop(Elem target){
  Lifo *n=Stos->nast;
  if ( Stos ){
    strcpy(target,Stos->napis);
    delete Stos;
    Stos=n;
  }
}

int main(){
  Elem tekst;

  while ( cin ){
    cout << "Podaj slowo (max " << MAX-1 
	 << " liter) ctrl-Z (lub ctrl-D) aby zakonczyc: "<<endl;
    strcpy(tekst,"");
    cin >> tekst;
    if (strcmp(tekst,"") )
      Push(tekst);
  }
  
  while ( Stos ){
    Pop(tekst);
    cout << " zdejmuje ze stosu slowo " << tekst << endl;
  }
  cout << "Stos pusty!" << endl;
  return 0;
} 
  

