-
#include <iostream>
-
using namespace std;
-
-
void insert_q(char *q, int *next, int &front, int &rear, char c){
-
if(front==-1){
-
front=0;
-
}
-
if(rear==-1){
-
rear=0;
-
} else {
-
rear=next[rear];
-
}
-
q[rear]=c;
-
}
-
-
void delete_q(char *q, int *next, int &front, int &rear){
-
front=next[front];
-
}
-
-
void print_q(char *q, int *next, int front, int rear){
-
cout<<"현재 큐의 상태는 아래와 같다"<<endl;
-
while(front!=rear){
-
cout<<q[front]<<endl;
-
front=next[front];
-
}
-
cout<<q[rear]<<endl; //마지막 rear까지 루프 한방에 출력하는 방법이 떠오르지 않아서...
-
}
-
-
int main(){
-
char q[5];
-
int next[5]={1,2,3,4,0};
-
int front=-1, rear=-1;
-
-
insert_q(q, next, front, rear, 'P');
-
insert_q(q, next, front, rear, 'R');
-
insert_q(q, next, front, rear, 'B');
-
delete_q(q, next, front, rear);
-
delete_q(q, next, front, rear);
-
insert_q(q, next, front, rear, 'J');
-
insert_q(q, next, front, rear, 'G');
-
insert_q(q, next, front, rear, 'K');
-
insert_q(q, next, front, rear, 'S');
-
-
print_q(q, next, front, rear);
-
-
return 0;
-
}