#include "misc.h"
#include "queue.h"

int main(void)
{
    char type[10];
    QUEUE *q = QueueAlloc(10);
    int count = 0;

    printf("input and output into/out of queues.\n");
    printf("sample input: 'i 42 d 3.14 f 2.71 pi pd pf' puts an int, a\n");
    printf("double, and a float into the queue, and then prints them.\n");
    while(scanf("%s", type) == 1)
    {
	double d;
	float f;
	int i;

	switch(type[0])
	{
	case 'd': scanf("%lf", &d);
	    QueuePut(q, (float)d);
	    break;

	case 'f': scanf("%f", &f);
	    QueuePut(q, f);
	    break;

	case 'i': scanf("%d", &i);
	    QueuePut(q, i);
	    break;

	case 'p':
	    switch(type[1])
	    {
	    case 'd':
	    case 'f':
		printf("%.16g\n", QueueGet(q).f);
		break;
	    case 'i': printf("%d\n", QueueGet(q).i);
		break;
	    default: printf("print huh?\n");
		break;
	    }
	    break;
	default:
	    printf("read huh?\n");
	    break;
	}
    }
    return 0;
}
