#include <stdio.h>
#include "SequenceQueue.h"
#include <stdlib.h>
void Traverse(Queue q)
{
int i;
for(i = q.front; i != q.rear; i++)
{
if (q.data[i] != 0)
{
printf("%d ", q.data[i]);
}
}
printf("\n");
}
int main()
{
int ret, num, i, top;
Queue q1, q2;
if (InitQueue(&q1) != SUCCESS || InitQueue(&q2) != SUCCESS)
{
printf("Init Failure!\n");
exit(1);
}
printf("Plesae input line:\n");
scanf("%d", &num);
for (i = 0; i < num; i++)
{
if (i == 0)
{
EnterQueue(&q1, 0);
EnterQueue(&q1, 1);
EnterQueue(&q1, 0);
}
else
{
while (LengthQueue(q1) != 1)
{
top = DeleteQueue(&q1);
EnterQueue(&q2, top + GetFront(q1));
}
while (LengthQueue(q2) != 0)
{
EnterQueue(&q1, DeleteQueue(&q2));
}
EnterQueue(&q1, 0);
}
Traverse(q1);
}
return 0;
}