(*  Tietorakenteet ja algoritmit 1999 *)
(*    Esimerkki 2-14 : Pinon sisällön kääntäminen *)
(*    9.9.1999 MM *)

program Esim2_14;

import TRA;

procedure reverse(S:STACK); 
var	Q:QUEUE;
begin
	QUEUE_CREATE(Q, STACK_TYPE(S));
	while (not STACK_EMPTY(S)) do
		begin
		 QUEUE_ENQUEUE(Q, STACK_TOP(S));
		 STACK_POP(S);
		end;
	while (not QUEUE_EMPTY(Q)) do
		begin
		 STACK_PUSH(S, QUEUE_FRONT(Q));
		 QUEUE_DEQUEUE(Q);
		end;
end;

var	S:STACK;
begin
	INT_STACK_CREATE(S);
	STACK_CONSTRUCT_RANDOM(S, 5, 1, 10);
	STACK_PRINT(S);
	writeln;
	reverse(S);
	STACK_PRINT(S);
	writeln;
	STACK_FREE(S);
end.
