Q5

#define MAX 100
#include<stdio.h>
void Nqueue();
int delStart();
int delEnd();
int queue[MAX];
int rear =0, front =0;
void display();
int main()
{
  int choice, c, token;
  scanf("%d",&c);
  while(c!=0)
  {
          switch(c)
          {
            case 1:    Nqueue(token);
                       break;
            case 2:    token=delStart();
                       break;
            case 3:    token=delEnd();
                       break;
            case 4:    display();
                       printf("\n");
                       break;
          }
          scanf("%d",&c);   
  }
  return 0;
}
void display()
{
     int i;
     for(i=rear;i<front;i++)
           printf("%d->",queue[i]);
}
void Nqueue()

     int token;
     scanf("%d",&token);
     queue[front]=token;
     front=front+1;
}
int delEnd()
{
     int t;
     if(front==rear)
     {
            printf("Underflow\n");
            return 0;
     }
     front=front-1;
     t=queue[front+1];
     return t;
}
int delStart()
{
     int t;
     rear=rear+1;
     t=queue[rear-1];
     return t;
}

5 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. #include
    using namespace std;

    int flag=0;

    struct node{

    int info;
    node* next=NULL;

    }*ptr,*newptr,*front,*rear,*save;



    node* Create_new_node(int n){

    ptr=new node;
    ptr->info=n;
    ptr->next=NULL;
    //cout<<"node created with info part "<info<next=np;
    rear=np;
    }

    }

    node* Deletequefromfront(){

    if(front==NULL) {cout<<"Underflow "<next;
    delete save;

    }

    }

    node* Deletequefromrear(node* nf){

    if(rear==NULL) {cout<<"Underflow "<next->next!=NULL)
    secondlast=secondlast->next;

    rear=secondlast;
    delete(secondlast->next);

    secondlast->next=NULL;
    }

    }


    node* displayque(node* np){

    while(np!=NULL){

    cout<info<<"->";
    np=np->next;
    }

    }

    void Nqueue(){}

    int main(){

    int ch;
    int inf;
    cin>>ch;
    do{

    if(ch==1){
    //cout<<"1 called "<>inf;
    newptr=Create_new_node(inf);
    Insert(newptr);
    }

    else if(ch==2){

    if(flag!=1)
    Deletequefromfront();

    else break;

    }

    else if(ch==4){

    displayque(front);
    cout<>ch;

    }while(ch!=0);


    return 0;
    }

    ReplyDelete
  4. https://hasteb.in/acagajad.cpp Works. 100%!

    ReplyDelete

SRM ELAB SOLUTUONS   DATA-STRUCTURE                                                                             **IF THE PROGRAM DON...