Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void add(int input);
- void show();
- void del();
- bool isFull();
- bool isEmpty();
- const int len=5;
- int queue[len];
- int rear=0,front=0;
- int main(){
- add(1);
- add(2);
- add(3);
- add(4);
- add(5);
- add(6);
- add(7);
- add(8);
- del();
- del();
- del();
- add(1);
- add(2);
- add(3);
- }
- void add(int input){
- if(isFull()) {
- printf("Full!!\n");
- return;
- }
- printf("ADD:%d\n",input);
- queue[rear++]=input;
- show();
- }
- void del(){
- if(isEmpty()){
- printf("Empty!!\n");
- return;
- }
- printf("DEL:%d\n",queue[front]);
- queue[front++]=0;
- show();
- }
- bool isFull(){
- return front==0 && rear==len+1;
- }
- bool isEmpty(){
- return rear==front;
- }
- void show(){
- printf("SHOW:[Front=%d]",front);
- for(int i=front;i<rear;i++){
- printf("%d ",queue[i]);
- }
- printf("[Rear=%d]\n",rear);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement