#define M 4
#define N 10
#include<stdio.h>
typedef struct Queue
{char *head;
char *tail:
int=length;
}Que;
Que create()
{Que Q;
Q.head=(Queue)malloc(sizeof(Que));
Q.tail=Q.head;
Q.length=0;
return(Q);
}
Que push(Que Q,char c)
{*++Q.tail=c;
Q.length++;
if(Q.length>M)printf("Overflow!");
else return(Q);
}
char pop(Que Q)
{char c;
if(Q.length==0)exit(NULL);
Q.length++;
else return(c);
}
void visit(Que Q)
{int count;
char e;
for(count=0;count<M;count++)
{e=pop(Q);
printf("%c",e);
push(Q,pop(Q));
}
}
main()
{Que Q,p;
char c,e;
c=getchar();
while(c!=NULL)
{for(p=Q.head;p<=Q.tail;p++)
{if(*p==c)visit(Q);
else
{e=pop(Q);
push(Q,c);
}
}
}
}
评论