Question
July 25, 2007 at 04:34 AM
manojgadiyar

Transfering element from one queue to another queue

by manojgadiyar . Updated 19 years, 1 month ago

Hi,

Now the maximum number of element i can insert in the queue(q1 or q2 or q3 ) is 5.
After inserting 5 elements in one of the queue, if i try to insert any more element,
that element will automatically go to wait queue.Now what i want is if i remove one
element from the say q1(which already had 5 elements)manually.one element from wait queue
must get inserted in the q1 at last position automatically.

I have given my program below. Can anyone please help.

#include
#include
#include
# define MAX 5
void cash_wd();
void cash_d();
void pass_entry();
void rem();
void display();
void wait_queue();
int f1,f2,f3,f4;
int r1,r2,r3,r4;
int q1[MAX],q2[MAX],q3[MAX],q4[1000];
int n;
char name[25];
void main()
{
int choice=0;
f1=f2=f3=f4=0;
r1=r2=r3=r4=-1;
clrscr();
for(;;)
{
printf(“\n ____________CUSTOMER ENTRY____________\n”);
printf(“\n _______________________________________ \n “);
printf(“\n** Please Enter the transaction **\n”);
printf(“\n _______________________________________ \n “);
printf(“\n 1. Cash Withdrawal “);
printf(“\n 2. Cash Deposit “);
printf(“\n 3. Pass Book Entry “);
printf(“\n 4. Display Queue”);
printf(“\n 5. Remove Customer from queue”);
printf(“\n 6. Exit: \n”);
printf(“\n _________________________________________ \n”);
printf(“\n Please Enter your Choice”);
scanf(“%d”,&choice);
switch(choice)
{
case 1: cash_wd();
break;
case 2: cash_d();
break;
case 3: pass_entry();
break;
case 4: display();
break;
case 5: rem();
break;
case 6: exit(0);
break;
}
}
}
void cash_wd()
{
int temp;
if(r1==MAX-1)
{
printf(“\t Queue for Cash Withdrawal is full. Please Wait\n”);
wait_queue();
return;
}
else
{
printf(“\n Enter customer Name\n”);
scanf(“%s”,&name);
printf(“\n Enter customer Account Number \n”);
scanf(“%d”,&n);
q1[++r1]=n;
}

}
void cash_d()
{
if(r2==MAX-1)
{
printf(“\tQueue for Cash Deposite is full. Please Wait\n”);
wait_queue();
return;
}
else
{
printf(“\n Enter customer Name\n”);
scanf(“%s”,&name);
printf(“\n Enter customer Account Number \n”);
scanf(“%d”,&n);
q2[++r2]=n;
}
}
void pass_entry()
{
if(r3==MAX-1)
{
printf(“\tQueue for Pass Book Entery is full. Please Wait\n”);
wait_queue();
return;
}
else
{
printf(“\n Enter customer Name\n”);
scanf(“%s”,&name);
printf(“\n Enter customer Account Number \n”);
scanf(“%d”,&n);
q3[++r3]=n;
}
}
void display()
{
int i;
if(f1>r1)
printf(“\n No Customers for Cash Withdrawal. No Customers in Queue \n”);
else
{
printf(“\n ___________________________________ \n”);
printf(“\n Customer/s Queue for Cash Withdrawal \n”);
for(i=f1;i<=r1;i++) printf("%d->“,q1[i]);
printf(“\n _______________________________ \n”);
printf(“\n”);
}
if(f2>r2)
printf(“\n No Customers for Cash Deposit. No Customers in Queue \n”);
else
{
printf(“\n _______________________________ \n”);
printf(“\n Customer/s Queue for Cash Deposit \n”);
for(i=f2;i<=r2;i++) printf("%d->“,q2[i]);
printf(“\n ________________________________ \n”);
printf(“\n”);
}
if(f3>r3)
printf(“\n No Customers for Passbook Entry. No Customers in Queue \n”);
else
{
printf(“\n __________________________________ \n”);
printf(“\n Customer/s Queue for Passbook Entry \n”);
for(i=f3;i<=r3;i++) printf("%d->“,q3[i]);
printf(“\n __________________________________ \n”);
printf(“\n”);
}
if(f4>r4)
printf(“\n No Customers in Wait Queue.Wait Queue is Empty\n”);
else
{
printf(“\n __________________________________ \n”);
printf(“\n Customer/s Queue Waiting For their Turn \n”);
for(i=f4;i<=r4;i++) printf("%d->“,q4[i]);
printf(“\n __________________________________ \n”);
printf(“\n”);
}
}
void rem()
{
int flag=0;
flag=pop(1);
if(flag==1)
{
printf(“\n Customer Removed from the queue\n”);
return;
}
flag=pop(2);
if(flag==1)
{
printf(“\n Customer removed from the queue\n”);
return;
}
flag=pop(3);
if(flag==1)
{
printf(“\n Customer Removed from the queue \n”);
return;
}
if(flag==0)
printf(“\n There are no Customers to get deleted from the Queue \n”);
return;
}
int pop(int q)
{
printf(“\n _________EXIT_________”);
printf(“\n 1. Customer to be Exited from Cash Withdrawal Queue “);
printf(“\n 2. Customer to be Exited from Cash Deposit Queue “);
printf(“\n 3. Customer to be Exited from Pass Book Entry Queue”);
printf(“\n —————————“);
printf(“\n Please Enter your Choice”);
scanf(“%d”,&q);
switch(q)
{
case 1:
if(f1>r1)
{
printf(“\n No Customer/s in the queue”);
return 0;
}
else
{
f1++;
return 1;
}
case 2:
if(f2>r2)
{
printf(“\n No Customer/s in the queue”);
return 0;
}
else
{
f2++;
return 1;
}
case 3:
if(f3>r3)
{
printf(“\n No Customer/s in the queue”);
return 0;
}
else
{
f3++;
return 1;
}
}
return 0;
}
void wait_queue()
{
if(r1==1000-1)
{
printf(“\t Wait Queue is Full. Sorry \n”);
return;
}
else
{ printf(“\n Please Enter your name”);
scanf(“%s”,&name);
printf(“\n Enter customer Account Number \n”);
scanf(“%d”,&n);
q4[++r4]=n;
}
}

This discussion is locked

All Comments