Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #define q_s 10
- int rear,front;
- int queue[q_s];
- void Insertion(int ele){
- if(rear+1 == q_s) {
- printf("\nQueue is full");
- return;
- }
- else if (rear==-1 && front == -1){
- rear = front = 0;
- }
- else rear++;
- queue[rear] = ele;
- }
- void Deletion(){
- if(rear==-1) printf("\nQueue is already empty");
- else if (rear == front){
- queue[front]=0;
- rear = front = -1;
- }
- else queue[front++] = 0;
- }
- void Print(){
- if(rear == -1) {
- printf("\nQueue is empty");
- return;
- }
- for(int i = front ; i<=rear ; i++){
- printf("%d ",queue[i]);
- }
- }
- int main()
- {
- rear = front = -1;
- int key,choice,element;
- while(1){
- printf("\n1 for insertion \n2 for deletion\nAny key to just print the queue\n");
- scanf("%d",&choice);
- if(choice==1){
- printf("\nEnter the element ");
- scanf("%d",&element);
- Insertion(element);
- }
- else if(choice==2){
- Deletion();
- }
- else Print();
- printf("\n1 - for repeat and any key to exit ");
- scanf("%d",&key);
- if(key!=1)break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment