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

#include "TRA.h"
#include <stdio.h>

void reverse(STACK S) {
	QUEUE Q;
	QUEUE_CREATE(Q, STACK_TYPE(S));

	while ( !STACK_EMPTY(S)) {
		QUEUE_ENQUEUE(Q, STACK_TOP(S));
		STACK_POP(S);
	}
	while ( !QUEUE_EMPTY(Q)) {
		STACK_PUSH(S, QUEUE_FRONT(Q));
		QUEUE_DEQUEUE(Q);
	}  
}

void main() {
	STACK S;
	INT_STACK_CREATE(S);
	STACK_CONSTRUCT_RANDOM(S, 5, 1, 10);
	STACK_PRINT(S);
	putchar('\n');
	reverse(S);
	STACK_PRINT(S);
	putchar('\n');
	STACK_FREE(S);
}