반응형
환영큐
#include<stdio.h>
#define Max_Q 5
int Q[Max_Q];
int bot, top;
void firstQ()
{
bot = top = 0;
}
void clearQ()
{
bot = top;
}
int push(int n)
{
if((top+1)%Max_Q==bot){
printf("꽉참\n");
return -1;
}
Q[top] = n;
top++;
top = top%Max_Q;
return n;
}
int pop()
{
int n;
if( bot == top){
printf("빔\n");
return -1;
}
n=Q[bot];
bot++;
bot = bot%Max_Q;
return n;
}
int main()
{
firstQ();
push(1);
push(2);
push(3);
push(4);
int i;
for(i=bot;i!=top;i=++i%Max_Q)
printf("%d\n",Q[i]);
printf("\n");
pop();
for(i=bot;i!=top;i=++i%Max_Q)
printf("%d\n",Q[i]);
printf("\n");
pop();
push(5);
for(i=bot;i!=top;i=++i%Max_Q)
printf("%d\n",Q[i]);
printf("\n");
return 0;
}
반응형
'Programming > C, C++' 카테고리의 다른 글
트리생성 (0) | 2013.05.21 |
---|---|
수식트리 (0) | 2013.05.21 |
Doublelinkedlist (0) | 2012.12.26 |
Linkedlist (0) | 2012.12.26 |
Stack (0) | 2012.12.20 |
댓글