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_R(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 Insertion_F(int ele){
- if(front == 0) printf("\nInsertion is not possible");
- else if (front == -1){
- rear = front = 0;
- queue[front] = ele;
- }
- else{
- queue[--front] = ele;
- }
- }
- void Deletion_F(){
- if(rear==-1) printf("\nQueue is already empty");
- else if (rear == front){
- queue[front]=0;
- rear = front = -1;
- }
- else queue[front++] = 0;
- }
- void Deletion_R(){
- if(rear == -1)printf("\nQueue is already empty");
- else if (rear == front){
- queue[rear] = 0;
- rear = front = -1;
- }
- else{
- queue[rear--] = 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,id_choice;
- while(1){
- printf("\n1 for insertion \n2 for deletion\nAny key to just print the queue\n");
- scanf("%d",&choice);
- if(choice==1){
- printf("\nWhich insertion 1 - front and 2 - rear ");
- scanf("%d",&id_choice);
- if(id_choice == 1){
- printf("Enter the element ");
- scanf("%d",&element);
- Insertion_F(element);
- }
- else if(id_choice == 2){
- printf("Enter the element ");
- scanf("%d",&element);
- Insertion_R(element);
- }
- }
- else if(choice==2){
- printf("\nWhich deletion 1 - front and 2 - rear ");
- scanf("%d",&id_choice);
- if(id_choice == 1){
- Deletion_F();
- }
- else if(id_choice == 2){
- Deletion_R();
- }
- }
- 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