SlideShare a Scribd company logo
1 of 16
1) ‘C’ program
/*************************************************************
         Program for implementing the Queue using arrays

*************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define size 5
struct queue
{
  int que[size];
  int front,rear;
}Q;
/*
  The Qfull Function
  Input:none
  Output:1 or 0 for q full or not
  Called By:main
  Calls:none
*/
  Qfull()
  {
  if(Q.rear >=size–1)
    return 1;
  else
    return 0;
}
/*
  The insert Function
  Input:item -which is to be inserted in the Q
  Output:rear value
  Called By:main
  Calls:none
*/
int insert(int item)
{
    if(Q.front == –1)
     Q.front++;
    Q.que[++Q.rear] = item;
    return Q.rear;
}
int Qempty()
{
  if((Q.front == – 1) || (Q.front > Q.rear))
    return 1;
  else
    return 0;
}
/*
  The delete Function
  Input:none
  Output:front value
  Called By:main
Calls:none
*/
int delete()
{
  int item;
  item = Q.que[Q.front];
  Q.front++;
  printf(―n The deleted item is %d‖,item);
  return Q.front;
}
/*
  The display Function
  Input:none
  Output:none
  Called By:main
  Calls:none
*/
void display()
{
    int i;
    for(i=Q.front;i<=Q.rear;i++)
     printf(―    %d‖,Q.que[i]);
}
void main(void)
{
  int choice,item;
  char ans;
  clrscr();
  Q.front = –1;
  Q.rear = –1;
  do
  {
     printf(―n Main Menu‖);
     printf(―n1.Insertn2.Deleten3.Display‖);
     printf(―n Enter Your Choice‖);
     scanf(―%d‖,&choice);
     switch(choice)
        {
        case 1:if(Qfull())        //checking for Queue overflow
                    printf(―n Can not insert the element‖);
              else
              {
                    printf(―n Enter The number to be inserted‖);
                    scanf(―%d‖,&item);
                    insert(item);
              }
              break;
        case 2:if(Qempty())
                     printf(―n Queue Underflow!!‖);
                    else
                     delete();
                    break;
        case 3:if(Qempty())
                     printf(―nQueue Is Empty!‖);
else
                  display();
                 break;
      default:printf(―n Wrong choice!‖);
                 break;
      }
  printf(―n Do You Want to continue?‖);
  ans =getche();
  }while(ans ==‘Y‘||ans ==‘y‘);
}
/********************** End Of Program ***********************/
2) ‘C’ program

/*************************************************************
Program For circular queue using arrays.It performs the basic
operations such as insertion,deletion of the elements by taking
care of queue Full and queue Empty conditions.The appropriate
display is for displaying the queue
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 5
int queue[size];
int front=–1;
int rear =0;
/*
  The qFull Function
  Input:none
  Output:returns 1 or 0 for q.full or not
  Called By:add
  Calls:none
*/
int qFull()
{
  if(front==(rear+1)%size)
   return 1;
  else
  return 0;
}
/*
  The qEmpty Function
  Input:none
  Output:returns 1 or 0 for q.empty or not
  Called By:delete and display
  Calls:none
*/
int qEmpty()
{
  if(front ==–1)
   return 1;
  else
   return 0;
}
/*
  The add Function
  Input:the element to be inserted
  Output:none
  Called By:main
  Calls:qFull
*/
void add(int Item)
{
  if(qFull())
    printf(―n The circular Queue is full!‖);
  else
  {
    if(front ==–1)
    front=rear=0;
    else
    rear =(rear+1)%size;
    queue[rear]=Item;
  }
}
/*
  The delete Function
  Input:none
  Output:returns the deleted element
  Called By:main
  Calls:qEmpty
*/
void delete()
{
  int Item;
    if(qEmpty())
     printf(―n Queue Is Empty!‖);
    else

  {
   Item=queue[front];
   if(front ==rear)
   {
      front=rear=–1;
   }
   else
      front =(front+1)%size;
   printf(―n The deleted item is %d‖,Item);
  }
  }
/*
  The display Function
  Input: none
  Output: prints the contents of the queue
  Called By:main
  Calls:qEmpty
*/
void display()
{
int i;
  if(qEmpty())
  {
   printf(―nThe Queue Is Empty‖);
   return;
  }
  i=front;
  while(i!=rear)
  {
   printf(― %d‖,queue[i]);
   i=(i+1)%size;
  }
  printf(― %d‖,queue[i]);
  }
/*
  The main Function
  Input:none
  Output:none
  Called By:O.S.
  Calls:add,delete,display
*/
void main(void)
{
  int choice,Item;
  char ans;
  clrscr();
  do
  {
    printf(―n Main Menu‖);
    printf(―n 1.Insertn2.Deleten3.Display‖);
    printf(―n Enter Your Choice‖);
    scanf(―%d‖,&choice);
    switch(choice)
    {
     case 1:printf(―nEnter The element‖);
             scanf(―%d‖,&Item);
             add(Item);
             break;
     case 2:delete();
             break;
     case 3:display();
             break;
     default:exit(0);
    }
    printf(―n Do u want to continue?‖);
    ans =getch();
  }while(anvb ==‘Y‘||ans == ‗y‘);
  getch();
}
/************************ End Of Main ***********************/
3)C Program
/*************************************************************
Program for implementing the Queue using one dimensional array

*************************************************************/

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define size 20

/*data structure for multiple queue*/
struct mult_que {
                         int que[size];
                         int rear[size],front[size];
                        }Q;
int sz[size];/*stores sizes of individual queue*/
/*
  The set_que function
Purpose:This function initialises all the front and rear positions of
individual queues.All thses queues has to      be in a single dimensional
array
Input:index of the queue
Output:none,it simply initializes the locations of front and rear
Called By:main,before performing any operation on individual queue
  Calls:none
*/
void set_que(int index)
{
  int sum,i;
  if(index==1)
  {
  Q.front[index]=0;
  Q.rear[index]=Q.front[index]-1;
}
  else
  {
  sum=0;
  for(i=0;i<index-1;i++)
    sum=sum+sz[i];
Q.front[index]=sum;
Q.rear[index]=Q.front[index]-1;/*computed the rear position
                             based on previous queues */
  }
}
/* The Qfull Function
  Purpose:to check whethe queue is full or not
  Input:index of the queue
  Output:1 or 0 for q full or not
  Called By:main
  Calls:none
*/
int Qfull(int index)
{
 int sum,i;
 sum=0;
 for(i=0;i<index;i++)
   sum=sum+sz[i];
 if(Q.rear[index]==sum-1)
   return 1;
 else
   return 0;
}
/*
  The insert Function
  Purpose:This function if for inserting the items in the requested queue
  Input:item which is to be inserted in the queue
  Output:rear value
  Called By:main
  Calls:none
*/
void insert(int item,int index)
{
    int j;
   j=Q.rear[index];
   Q.que[++j] = item;
   Q.rear[index]=Q.rear[index]+1;
}
/*
  The Qempty function
  Purpose:It Checks whether the queue is empty or not
  Input:index of the queue
  Output: returns 1 if queue is empty otherwise 0
  Called By:main
  Calls:none
*/
int Qempty(int index)
{
  if(Q.front[index]>Q.rear[index])
   return 1;
  else
   return 0;
}
/*
  The delet Function
  Purpose:for deletion of the element from the requeseted queue
  Input:index of the que
  Output:item which is deleted
  Called By:main
  Calls:none
*/
int delet(int index)
{
  int item;
  item = Q.que[Q.front[index]];
  Q.que[Q.front[index]]=-1;
  Q.front[index]++;
return item;
}
/*
  The display Function
  Purpose:displays all the queues
  Input:num which indicates total number of queues
  Output:none
  Called By:main
  Calls:none
*/
void display(int num)
{
   int index,i;
   index=1;
   do

     {
      if(Qempty(index))
         printf(―n The Queue %d is Empty‖,index);
      else
      {
         printf(―n Queue number %d is:‖,index);
         for(i=Q.front[index];i<=Q.rear[index];i++)
      {
         if(Q.que[i]!=-1)
         printf(― %d‖,Q.que[i]);
     }
 }
  index++;
 }while(index<=num);

}
/*
  The main function
  Input:none
  Output:none
  Called By:O.S.
  Calls:set_que,Qfull,Qempty,insert,delete,display
*/
void main(void)
{
  int choice,item,num,i,index;
  char ans;
  clrscr();
  printf(―ntt Program For Multiple Queues‖);
  printf(―n How many Queues do you want?‖);
  scanf(―%d‖,&num);
  printf(―n Enter The size of queue(Combined size of all Queues is 20)‖);
  for(i=0;i<num;i++)
    scanf(―%d‖,&sz[i]);
  for(index=1;index<=num;index++)
    set_que(index);/*initialized front and rear of each queue*/
  do
  {
printf(―n Main Menu‖);
   printf(―n1.Insertn2.Deleten3.Display‖);
   printf(―n Enter Your Choice‖);
   scanf(―%d‖,&choice);
   switch(choice)
   {
      case 1: printf(―n Enter in which queue you wish to
                  insert the item?‖);
                              scanf(―%d‖,&index);
                              if(Qfull(index))
                              /*checking for Queue overflow*/
                  printf(―n Can not insert the elemnt‖);
               else
               {
                  printf(―n Enter The number to be inseted‖);
                  scanf(―%d‖,&item);
                  insert(item,index);
               }
               break;
      case 2: printf(―n Enter From which queue you wish to
      delete the item?‖);
                  scanf(―%d‖,&index);
                  if(Qempty(index))
                     printf(―n Queue Underflow!!‖);
                  else
                  {
                    item= delet(index);
                    printf(―n The deleted item is %d‖,item);
                  }
                  break;
      case 3:display(num);
                    break;
      default:printf(―n Wrong choice!‖);
                     break;
      }
  printf(―n Do You Want to continue?‖);
  ans =getche();
  }while(ans ==‘Y‘||ans ==‘y‘);

}
4)C Program
/*************************************************************
         Program To implement Doubly ended queue using arrays

*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 5
/*Data structure for deque*/
struct queue {
                   int que[size];
                   int front,rear;
                   }Q;
/* The Qfull function
  Input:none
  Output:returns 1 if Queue is full otherwise 0
  Called By:main
  Calls:none
*/
int Qfull()
{
  if(Q.rear==size-1)
   return 1;
  else
   return 0;
}
/* The function
  Input:Qempty
  Output:none
  Called By:main
  Calls: none
*/
int Qempty()
{
    if((Q.front>Q.rear)||(Q.front==-1&&Q.rear==-1))
       return 1;
    else
       return 0;
}
/* The Qfull function
  Input:
  Output:
  Called By:
  Calls:
*/
int insert_rear(int item)
{
  if(Q.front==-1&&Q.rear==-1)
  Q.front++;
  Q.que[++Q.rear]=item;
  return Q.rear;
}
/* The delete_front function
  Input:none
  Output:returns the deleted item
  Called By:main
  Calls:none
*/
int delete_front()
{
  int item;
  if(Q.front==-1)
  Q.front++;
  item=Q.que[Q.front];
  Q.que[Q.front]=-1;
  Q.front++;
  return item;
}
/* The insert_front function
  Input:the item to be inserted by front
  Output:returns the front
  Called By:main
  Calls:none
*/
int insert_front(int item)
{
  int i,j;
  if(Q.front==-1)
  Q.front++;
  i=Q.front-1;
  while(i>=0)
  {
    Q.que[i+1]=Q.que[i];
    i—;
  }
  j=Q.rear;
  while(j>=Q.front)
  {
    Q.que[j+1]=Q.que[j];
    j—;
  }
  Q.rear++;
  Q.que[Q.front]=item;
  return Q.front;
}
/* The delete_rear function
  Input: none
  Output: the item to deleted
  Called By:main
  Calls:none
*/
int delete_rear()
{
  int item;
  item=Q.que[Q.rear];
  Q.que[Q.rear]=-1;/*logical deletion*/
  Q.rear—;
  return item;
}
/* The display function
  Input:none
  Output:none,it displays the contents in the queue
  Called By:main
  Calls:none
*/
void display()
{
  int i;
  printf(―n Straight Queue is:‖);
    for(i=Q.front;i<=Q.rear;i++)
    printf(― %d‖,Q.que[i]);
}
/* The main function
  Input:none
  Output:none
  Called By:O.S.

Calls:Qfull,Qempty,insert_rear,Insert_front,delete_front,delete_rear,displ
ay
*/
void main()
{
  int choice,i,item;
  char ans;
  ans=‘y‘;
  Q.front=-1;
  Q.rear=-1;
  for(i=0;i<size;i++)
    Q.que[i]=-1;
  clrscr();
  printf(―ntt Program For doubly ended queue using arrays‖);
  do
  {
  printf(―n1.insert by rearn2.delete by frontn3.insert by
frontn4.delete by rear‖);
  printf(―n5.displayn6.exit‖);
  printf(―n Enter Your choice‖);
  scanf(―%d‖,&choice);
  switch(choice)
    {
     case 1:if(Qfull())
                 printf(―n Doubly ended Queue is full‖);
               else
               {
                 printf(―n Enter The item to be inserted‖);
                 scanf(―%d‖,&item);
                 Q.rear=insert_rear(item);
               }
               break;
     case 2:if(Qempty())
                 printf(―n Doubly ended Queue is Empty‖);
               else
               {
               item=delete_front();
              printf(―n The item deleted from queue is
%d‖,item);
               }
               break;
     case 3:if(Qfull())
                 printf(―n Doubly ended Queue is full‖);
               else
               {
                 printf(―n Enter The item to be inserted‖);
                 scanf(―%d‖,&item);
                 Q.front=insert_front(item);
}
               break;
    case 4:if(Qempty())
                printf(―n Doubly ended Queue is Empty‖);
               else
               {
               item=delete_rear();
              printf(―n The item deleted from queue is
%d‖,item);
               }
               break;
    case 5:display();
               break;
    case 6:exit(0);
   }
   printf(―n Do You Want To Continue?‖);
   ans=getch();
  }while(ans==‘y‘||ans==‘Y‘);
  getch();
}
5)‘C’ program
/************************************************************
Program for implementing the ascending priority Queue
  ************************************************************/
/*Header Files*/
#include<stdio.h>
#include<conio.h>
#include<process.h>
#define size 5

int rear,front;
int que[size];
/*
  The Qfull function
  Input:none
  Output:1 or 0 for Qfull or not resp.
  Called By:main
  Calls:none
*/
Qfull()
{
if(rear ==size-1)
  return 1;
  else
   return 0;
}

/* The insert function
 Input:none
 Output:none
 Called By:main
 Calls:priority
*/
void insert()
{    int item;
     void priority();
     printf(―nEnter the elementn‖);
     scanf(―%d‖,&item);
     if(front ==-1)
     front++;
     que[++rear]= item;
     priority();
}
/*
  The priority function
  Input:none
  Output:none
  Called By:insert
  Calls:none
*/
void priority()
{
  int i,j,temp;
  for(i=front;i<=rear-1;i++)
    for(j=front;j<rear;j++)
        if(que[j]>que[j+1])
        {
          temp = que[j];
          que[j] = que[j+1];
          que[j+1] =temp;
        }
  }
/*
  The Qempty function
  Input:none
  Output:1 or 0
  Called By:main
  Calls:none
*/
Qempty()
{
  if((front==-1)||(front>rear))
    return 1;
  else
    return 0;
}
/*
  The delet function
  Input:none
  Output:none
  Called By:main
  Calls:none
*/
void delet()
{
    int item;
    item=que[front];
    printf(―n The item deleted is %d‖,item);
front++;
}
/*
  The display function
  Input:none
  Output:none
  Called By:main
  Calls:none
*/
void display()
{ int i;
  printf(―n The queue is:‖);
  for(i=front;i<=rear;i++)
  printf(― %d‖,que[i]);
}
/*
       Name:main()
       Input:none
       Output:none
       Calls:Qfull,Qempty,insert,delet,display
*/
void main(void)
    {
       int choice;
       char ans;
       clrscr();
       front=rear=-1;
       printf(―ntt Priority Queuen‖);
       do
       {
         printf(―n Main Menu‖);
         printf(―n1.Insertn2.Deleten3.Display‖);
         printf(―n Enter Your Choice‖);
         scanf(―%d‖,&choice);
         switch(choice)
         {
           case 1:if(Qfull())
                       printf(―n Queue IS full‖);
                     else
                       insert();
                     break;
           case 2:if(Qempty())
                       printf(―n Cannot delete element‖);
                      else
                       delet();
                      break;
           case 3:if(Qempty())
                      printf(―n Queue is empty‖);
                     else
                      display();
                     break;
            default:printf(―n Wrong choice‖);
                       break;
         }
printf(―n Do You Want TO continue?‖);
        ans =getche();
  }while(ans==‘Y‘ ||ans==‘y‘);
 getch();
}
/***************** End Of the program********************/

More Related Content

What's hot

C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6Rumman Ansari
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rathSANTOSH RATH
 
Circular linked list
Circular linked listCircular linked list
Circular linked listSayantan Sur
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
Single linked list
Single linked listSingle linked list
Single linked listSayantan Sur
 
Double linked list
Double linked listDouble linked list
Double linked listSayantan Sur
 
C programming function
C  programming functionC  programming function
C programming functionargusacademy
 
C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2Rumman Ansari
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
Double linked list
Double linked listDouble linked list
Double linked listraviahuja11
 
Queue implementation
Queue implementationQueue implementation
Queue implementationRajendran
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shortingargusacademy
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 

What's hot (20)

C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Daa practicals
Daa practicalsDaa practicals
Daa practicals
 
C programming function
C  programming functionC  programming function
C programming function
 
05 queues
05 queues05 queues
05 queues
 
C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
Function (rule in programming)
Function (rule in programming)Function (rule in programming)
Function (rule in programming)
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Cpds lab
Cpds labCpds lab
Cpds lab
 

Viewers also liked

Telecamere a1
Telecamere a1Telecamere a1
Telecamere a1GpsLazio
 
Presentatie Brabantse beleidsmedewerkers VVE 18-10-2011
Presentatie Brabantse beleidsmedewerkers VVE 18-10-2011Presentatie Brabantse beleidsmedewerkers VVE 18-10-2011
Presentatie Brabantse beleidsmedewerkers VVE 18-10-2011KPC Groep
 
Helgeland Sparebank regnskapspresentasjon 3. kvartal 2011
Helgeland Sparebank regnskapspresentasjon 3. kvartal 2011Helgeland Sparebank regnskapspresentasjon 3. kvartal 2011
Helgeland Sparebank regnskapspresentasjon 3. kvartal 2011Helgeland Sparebank
 
09 04-28 renstra-ditjenanggaran05-09
09 04-28  renstra-ditjenanggaran05-0909 04-28  renstra-ditjenanggaran05-09
09 04-28 renstra-ditjenanggaran05-09Novit Yanto
 
Diseño interior tienda de ropa Lepreg
Diseño interior tienda de ropa LepregDiseño interior tienda de ropa Lepreg
Diseño interior tienda de ropa LepregMireia Llobera
 
Leticia e alessandro 2 d
Leticia e alessandro 2 dLeticia e alessandro 2 d
Leticia e alessandro 2 dmarciochriste
 
Osteocardix: Брошура на продукта
Osteocardix: Брошура на продуктаOsteocardix: Брошура на продукта
Osteocardix: Брошура на продуктаSpas Petkov
 
Newcom research & consultancy Vertrouwensindex 2011
Newcom research & consultancy   Vertrouwensindex 2011Newcom research & consultancy   Vertrouwensindex 2011
Newcom research & consultancy Vertrouwensindex 2011* Neil Van Der Veer
 

Viewers also liked (9)

Telecamere a1
Telecamere a1Telecamere a1
Telecamere a1
 
Presentatie Brabantse beleidsmedewerkers VVE 18-10-2011
Presentatie Brabantse beleidsmedewerkers VVE 18-10-2011Presentatie Brabantse beleidsmedewerkers VVE 18-10-2011
Presentatie Brabantse beleidsmedewerkers VVE 18-10-2011
 
Helgeland Sparebank regnskapspresentasjon 3. kvartal 2011
Helgeland Sparebank regnskapspresentasjon 3. kvartal 2011Helgeland Sparebank regnskapspresentasjon 3. kvartal 2011
Helgeland Sparebank regnskapspresentasjon 3. kvartal 2011
 
09 04-28 renstra-ditjenanggaran05-09
09 04-28  renstra-ditjenanggaran05-0909 04-28  renstra-ditjenanggaran05-09
09 04-28 renstra-ditjenanggaran05-09
 
Diseño interior tienda de ropa Lepreg
Diseño interior tienda de ropa LepregDiseño interior tienda de ropa Lepreg
Diseño interior tienda de ropa Lepreg
 
Leticia e alessandro 2 d
Leticia e alessandro 2 dLeticia e alessandro 2 d
Leticia e alessandro 2 d
 
Osteocardix: Брошура на продукта
Osteocardix: Брошура на продуктаOsteocardix: Брошура на продукта
Osteocardix: Брошура на продукта
 
First World
First WorldFirst World
First World
 
Newcom research & consultancy Vertrouwensindex 2011
Newcom research & consultancy   Vertrouwensindex 2011Newcom research & consultancy   Vertrouwensindex 2011
Newcom research & consultancy Vertrouwensindex 2011
 

Similar to Qprgs

VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using CBilal Mirza
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020vrgokila
 
#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docxajoy21
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptxsinghprpg
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfarorasales234
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresLakshmi Sarvani Videla
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 

Similar to Qprgs (20)

VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
week-15x
week-15xweek-15x
week-15x
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Queue oop
Queue   oopQueue   oop
Queue oop
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx#include fstream#include iostream#include cstdlib#includ.docx
#include fstream#include iostream#include cstdlib#includ.docx
 
Array menu
Array menuArray menu
Array menu
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 

More from Ssankett Negi

More from Ssankett Negi (9)

Binary tree
Binary treeBinary tree
Binary tree
 
Multi way&btree
Multi way&btreeMulti way&btree
Multi way&btree
 
Heapsort
HeapsortHeapsort
Heapsort
 
Binary trees
Binary treesBinary trees
Binary trees
 
Threaded binarytree&heapsort
Threaded binarytree&heapsortThreaded binarytree&heapsort
Threaded binarytree&heapsort
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
Recursion
RecursionRecursion
Recursion
 
Circular queues
Circular queuesCircular queues
Circular queues
 
U2.linked list
U2.linked listU2.linked list
U2.linked list
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Qprgs

  • 1. 1) ‘C’ program /************************************************************* Program for implementing the Queue using arrays *************************************************************/ #include<stdio.h> #include<stdlib.h> #include<conio.h> #define size 5 struct queue { int que[size]; int front,rear; }Q; /* The Qfull Function Input:none Output:1 or 0 for q full or not Called By:main Calls:none */ Qfull() { if(Q.rear >=size–1) return 1; else return 0; } /* The insert Function Input:item -which is to be inserted in the Q Output:rear value Called By:main Calls:none */ int insert(int item) { if(Q.front == –1) Q.front++; Q.que[++Q.rear] = item; return Q.rear; } int Qempty() { if((Q.front == – 1) || (Q.front > Q.rear)) return 1; else return 0; } /* The delete Function Input:none Output:front value Called By:main
  • 2. Calls:none */ int delete() { int item; item = Q.que[Q.front]; Q.front++; printf(―n The deleted item is %d‖,item); return Q.front; } /* The display Function Input:none Output:none Called By:main Calls:none */ void display() { int i; for(i=Q.front;i<=Q.rear;i++) printf(― %d‖,Q.que[i]); } void main(void) { int choice,item; char ans; clrscr(); Q.front = –1; Q.rear = –1; do { printf(―n Main Menu‖); printf(―n1.Insertn2.Deleten3.Display‖); printf(―n Enter Your Choice‖); scanf(―%d‖,&choice); switch(choice) { case 1:if(Qfull()) //checking for Queue overflow printf(―n Can not insert the element‖); else { printf(―n Enter The number to be inserted‖); scanf(―%d‖,&item); insert(item); } break; case 2:if(Qempty()) printf(―n Queue Underflow!!‖); else delete(); break; case 3:if(Qempty()) printf(―nQueue Is Empty!‖);
  • 3. else display(); break; default:printf(―n Wrong choice!‖); break; } printf(―n Do You Want to continue?‖); ans =getche(); }while(ans ==‘Y‘||ans ==‘y‘); } /********************** End Of Program ***********************/ 2) ‘C’ program /************************************************************* Program For circular queue using arrays.It performs the basic operations such as insertion,deletion of the elements by taking care of queue Full and queue Empty conditions.The appropriate display is for displaying the queue *************************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> #define size 5 int queue[size]; int front=–1; int rear =0; /* The qFull Function Input:none Output:returns 1 or 0 for q.full or not Called By:add Calls:none */ int qFull() { if(front==(rear+1)%size) return 1; else return 0; } /* The qEmpty Function Input:none Output:returns 1 or 0 for q.empty or not Called By:delete and display Calls:none */ int qEmpty() { if(front ==–1) return 1; else return 0; }
  • 4. /* The add Function Input:the element to be inserted Output:none Called By:main Calls:qFull */ void add(int Item) { if(qFull()) printf(―n The circular Queue is full!‖); else { if(front ==–1) front=rear=0; else rear =(rear+1)%size; queue[rear]=Item; } } /* The delete Function Input:none Output:returns the deleted element Called By:main Calls:qEmpty */ void delete() { int Item; if(qEmpty()) printf(―n Queue Is Empty!‖); else { Item=queue[front]; if(front ==rear) { front=rear=–1; } else front =(front+1)%size; printf(―n The deleted item is %d‖,Item); } } /* The display Function Input: none Output: prints the contents of the queue Called By:main Calls:qEmpty */ void display() {
  • 5. int i; if(qEmpty()) { printf(―nThe Queue Is Empty‖); return; } i=front; while(i!=rear) { printf(― %d‖,queue[i]); i=(i+1)%size; } printf(― %d‖,queue[i]); } /* The main Function Input:none Output:none Called By:O.S. Calls:add,delete,display */ void main(void) { int choice,Item; char ans; clrscr(); do { printf(―n Main Menu‖); printf(―n 1.Insertn2.Deleten3.Display‖); printf(―n Enter Your Choice‖); scanf(―%d‖,&choice); switch(choice) { case 1:printf(―nEnter The element‖); scanf(―%d‖,&Item); add(Item); break; case 2:delete(); break; case 3:display(); break; default:exit(0); } printf(―n Do u want to continue?‖); ans =getch(); }while(anvb ==‘Y‘||ans == ‗y‘); getch(); } /************************ End Of Main ***********************/
  • 6. 3)C Program /************************************************************* Program for implementing the Queue using one dimensional array *************************************************************/ #include<stdio.h> #include<stdlib.h> #include<conio.h> #define size 20 /*data structure for multiple queue*/ struct mult_que { int que[size]; int rear[size],front[size]; }Q; int sz[size];/*stores sizes of individual queue*/ /* The set_que function Purpose:This function initialises all the front and rear positions of individual queues.All thses queues has to be in a single dimensional array Input:index of the queue Output:none,it simply initializes the locations of front and rear Called By:main,before performing any operation on individual queue Calls:none */ void set_que(int index) { int sum,i; if(index==1) { Q.front[index]=0; Q.rear[index]=Q.front[index]-1; } else { sum=0; for(i=0;i<index-1;i++) sum=sum+sz[i]; Q.front[index]=sum; Q.rear[index]=Q.front[index]-1;/*computed the rear position based on previous queues */ } } /* The Qfull Function Purpose:to check whethe queue is full or not Input:index of the queue Output:1 or 0 for q full or not Called By:main Calls:none */ int Qfull(int index)
  • 7. { int sum,i; sum=0; for(i=0;i<index;i++) sum=sum+sz[i]; if(Q.rear[index]==sum-1) return 1; else return 0; } /* The insert Function Purpose:This function if for inserting the items in the requested queue Input:item which is to be inserted in the queue Output:rear value Called By:main Calls:none */ void insert(int item,int index) { int j; j=Q.rear[index]; Q.que[++j] = item; Q.rear[index]=Q.rear[index]+1; } /* The Qempty function Purpose:It Checks whether the queue is empty or not Input:index of the queue Output: returns 1 if queue is empty otherwise 0 Called By:main Calls:none */ int Qempty(int index) { if(Q.front[index]>Q.rear[index]) return 1; else return 0; } /* The delet Function Purpose:for deletion of the element from the requeseted queue Input:index of the que Output:item which is deleted Called By:main Calls:none */ int delet(int index) { int item; item = Q.que[Q.front[index]]; Q.que[Q.front[index]]=-1; Q.front[index]++;
  • 8. return item; } /* The display Function Purpose:displays all the queues Input:num which indicates total number of queues Output:none Called By:main Calls:none */ void display(int num) { int index,i; index=1; do { if(Qempty(index)) printf(―n The Queue %d is Empty‖,index); else { printf(―n Queue number %d is:‖,index); for(i=Q.front[index];i<=Q.rear[index];i++) { if(Q.que[i]!=-1) printf(― %d‖,Q.que[i]); } } index++; }while(index<=num); } /* The main function Input:none Output:none Called By:O.S. Calls:set_que,Qfull,Qempty,insert,delete,display */ void main(void) { int choice,item,num,i,index; char ans; clrscr(); printf(―ntt Program For Multiple Queues‖); printf(―n How many Queues do you want?‖); scanf(―%d‖,&num); printf(―n Enter The size of queue(Combined size of all Queues is 20)‖); for(i=0;i<num;i++) scanf(―%d‖,&sz[i]); for(index=1;index<=num;index++) set_que(index);/*initialized front and rear of each queue*/ do {
  • 9. printf(―n Main Menu‖); printf(―n1.Insertn2.Deleten3.Display‖); printf(―n Enter Your Choice‖); scanf(―%d‖,&choice); switch(choice) { case 1: printf(―n Enter in which queue you wish to insert the item?‖); scanf(―%d‖,&index); if(Qfull(index)) /*checking for Queue overflow*/ printf(―n Can not insert the elemnt‖); else { printf(―n Enter The number to be inseted‖); scanf(―%d‖,&item); insert(item,index); } break; case 2: printf(―n Enter From which queue you wish to delete the item?‖); scanf(―%d‖,&index); if(Qempty(index)) printf(―n Queue Underflow!!‖); else { item= delet(index); printf(―n The deleted item is %d‖,item); } break; case 3:display(num); break; default:printf(―n Wrong choice!‖); break; } printf(―n Do You Want to continue?‖); ans =getche(); }while(ans ==‘Y‘||ans ==‘y‘); } 4)C Program /************************************************************* Program To implement Doubly ended queue using arrays *************************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> #define size 5 /*Data structure for deque*/ struct queue { int que[size]; int front,rear; }Q;
  • 10. /* The Qfull function Input:none Output:returns 1 if Queue is full otherwise 0 Called By:main Calls:none */ int Qfull() { if(Q.rear==size-1) return 1; else return 0; } /* The function Input:Qempty Output:none Called By:main Calls: none */ int Qempty() { if((Q.front>Q.rear)||(Q.front==-1&&Q.rear==-1)) return 1; else return 0; } /* The Qfull function Input: Output: Called By: Calls: */ int insert_rear(int item) { if(Q.front==-1&&Q.rear==-1) Q.front++; Q.que[++Q.rear]=item; return Q.rear; } /* The delete_front function Input:none Output:returns the deleted item Called By:main Calls:none */ int delete_front() { int item; if(Q.front==-1) Q.front++; item=Q.que[Q.front]; Q.que[Q.front]=-1; Q.front++; return item;
  • 11. } /* The insert_front function Input:the item to be inserted by front Output:returns the front Called By:main Calls:none */ int insert_front(int item) { int i,j; if(Q.front==-1) Q.front++; i=Q.front-1; while(i>=0) { Q.que[i+1]=Q.que[i]; i—; } j=Q.rear; while(j>=Q.front) { Q.que[j+1]=Q.que[j]; j—; } Q.rear++; Q.que[Q.front]=item; return Q.front; } /* The delete_rear function Input: none Output: the item to deleted Called By:main Calls:none */ int delete_rear() { int item; item=Q.que[Q.rear]; Q.que[Q.rear]=-1;/*logical deletion*/ Q.rear—; return item; } /* The display function Input:none Output:none,it displays the contents in the queue Called By:main Calls:none */ void display() { int i; printf(―n Straight Queue is:‖); for(i=Q.front;i<=Q.rear;i++) printf(― %d‖,Q.que[i]);
  • 12. } /* The main function Input:none Output:none Called By:O.S. Calls:Qfull,Qempty,insert_rear,Insert_front,delete_front,delete_rear,displ ay */ void main() { int choice,i,item; char ans; ans=‘y‘; Q.front=-1; Q.rear=-1; for(i=0;i<size;i++) Q.que[i]=-1; clrscr(); printf(―ntt Program For doubly ended queue using arrays‖); do { printf(―n1.insert by rearn2.delete by frontn3.insert by frontn4.delete by rear‖); printf(―n5.displayn6.exit‖); printf(―n Enter Your choice‖); scanf(―%d‖,&choice); switch(choice) { case 1:if(Qfull()) printf(―n Doubly ended Queue is full‖); else { printf(―n Enter The item to be inserted‖); scanf(―%d‖,&item); Q.rear=insert_rear(item); } break; case 2:if(Qempty()) printf(―n Doubly ended Queue is Empty‖); else { item=delete_front(); printf(―n The item deleted from queue is %d‖,item); } break; case 3:if(Qfull()) printf(―n Doubly ended Queue is full‖); else { printf(―n Enter The item to be inserted‖); scanf(―%d‖,&item); Q.front=insert_front(item);
  • 13. } break; case 4:if(Qempty()) printf(―n Doubly ended Queue is Empty‖); else { item=delete_rear(); printf(―n The item deleted from queue is %d‖,item); } break; case 5:display(); break; case 6:exit(0); } printf(―n Do You Want To Continue?‖); ans=getch(); }while(ans==‘y‘||ans==‘Y‘); getch(); } 5)‘C’ program /************************************************************ Program for implementing the ascending priority Queue ************************************************************/ /*Header Files*/ #include<stdio.h> #include<conio.h> #include<process.h> #define size 5 int rear,front; int que[size]; /* The Qfull function Input:none Output:1 or 0 for Qfull or not resp. Called By:main Calls:none */ Qfull() { if(rear ==size-1) return 1; else return 0; } /* The insert function Input:none Output:none Called By:main Calls:priority */ void insert()
  • 14. { int item; void priority(); printf(―nEnter the elementn‖); scanf(―%d‖,&item); if(front ==-1) front++; que[++rear]= item; priority(); } /* The priority function Input:none Output:none Called By:insert Calls:none */ void priority() { int i,j,temp; for(i=front;i<=rear-1;i++) for(j=front;j<rear;j++) if(que[j]>que[j+1]) { temp = que[j]; que[j] = que[j+1]; que[j+1] =temp; } } /* The Qempty function Input:none Output:1 or 0 Called By:main Calls:none */ Qempty() { if((front==-1)||(front>rear)) return 1; else return 0; } /* The delet function Input:none Output:none Called By:main Calls:none */ void delet() { int item; item=que[front]; printf(―n The item deleted is %d‖,item);
  • 15. front++; } /* The display function Input:none Output:none Called By:main Calls:none */ void display() { int i; printf(―n The queue is:‖); for(i=front;i<=rear;i++) printf(― %d‖,que[i]); } /* Name:main() Input:none Output:none Calls:Qfull,Qempty,insert,delet,display */ void main(void) { int choice; char ans; clrscr(); front=rear=-1; printf(―ntt Priority Queuen‖); do { printf(―n Main Menu‖); printf(―n1.Insertn2.Deleten3.Display‖); printf(―n Enter Your Choice‖); scanf(―%d‖,&choice); switch(choice) { case 1:if(Qfull()) printf(―n Queue IS full‖); else insert(); break; case 2:if(Qempty()) printf(―n Cannot delete element‖); else delet(); break; case 3:if(Qempty()) printf(―n Queue is empty‖); else display(); break; default:printf(―n Wrong choice‖); break; }
  • 16. printf(―n Do You Want TO continue?‖); ans =getche(); }while(ans==‘Y‘ ||ans==‘y‘); getch(); } /***************** End Of the program********************/