Nov 24, 2011 at 3:59pm UTC
I want to chang this program to char and the user continue to input and it is full, Display a message, "It's Full!". also
Allow the user to choose an option, to delete an item or not, if the user delete an item, display the item deleted. If the user choose not to delete, display all the items.
this is the program:
# include<iostream.h>
# include<conio.h>
# define SIZE 3
class queue
{
int a[SIZE];
int front;
int rear;
public:
queue();
~queue();
void insert(int i);
int remove();
int isempty();
int isfull();
};
queue::queue()
{
front=0;
rear=0;
}
queue::~queue()
{
delete []a;
}
void queue::insert(int i)
{
if(isfull())
{
cout<<"\n******Queue is FULL !!!No insertion allowed further.******";
return;
}
a[rear] = i;
rear++;
}
int queue::remove()
{
if(isempty())
{
cout<<"\n******Queue Empty !!!Value returned will be garbage.******\n";
return (-9999);
}
return(a[front++]);
}
int queue::isempty()
{
if(front == rear)
return 1;
else
return 0;
}
int queue::isfull()
{
if(rear == SIZE)
return 1;
else
return 0;
}
void main()
{
clrscr();
queue q;
int item;
while (!q.isfull())
{
cin>>item;
q.insert(item);
}
while(!q.isempty())
cout<<"\n "<<q.remove();
cout<<"\n"<<q.remove();
getch();
}
Nov 25, 2011 at 9:25am UTC
Thank you alot..But I want to know how to chang this program to make it enter character..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
# include<iostream>
using namespace std;
# define SIZE 3
class queue
{
private :
int a[SIZE];
int front;
int rear;
public :
queue();
~queue();
void insert(int i);
int remove();
int isempty();
int isfull();
int display(int n);
};
queue::queue()
{
front=0;
rear=0;
}
queue::~queue()
{
}
void queue::insert(int i)
{
if (isfull())
{
cout<<"\n******Queue is FULL !!!No insertion allowed further.******" ;
return ;
}
a[rear] = i;
rear++;
}
int queue::remove()
{
if (isempty())
{
cout<<"\n******Queue Empty !!!Value returned will be garbage.******\n" ;
return (-9999);
}
int i = SIZE ;
while ( i--)
{
a[i] = 0;
};
return (a[0]);
}
int queue::isempty()
{
if (front == rear)
return 1;
else
return 0;
}
int queue::isfull()
{
if (rear == SIZE)
return 1;
else
return 0;
}
int queue::display( int n )
{
int i = a[n];
return i;
}
void main()
{
queue q;
int item;
while (!q.isfull())
{
cin>>item;
q.insert(item);
}
while (!q.isempty())
{
int n = SIZE ;
cout<<q.display(n);
n--;
}
cout<<"\n " <<q.remove();
cout<<"\n" <<q.remove();
}
Last edited on Nov 25, 2011 at 11:34am UTC
Nov 25, 2011 at 4:57pm UTC
Last edited on Nov 25, 2011 at 4:58pm UTC
Nov 25, 2011 at 6:31pm UTC
I mean insted of int i use want to use char..
Nov 27, 2011 at 8:21am UTC
I have another problem when I compile it I have so many 0000000 with no end to this process..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
# include<iostream>
using namespace std;
# define SIZE 3
class queue
{
private :
char a[SIZE];
int front;
int rear;
public :
queue();
~queue();
void insert(int i);
char remove();
int isempty();
int isfull();
char display(int n);
};
queue::queue()
{
front=0;
rear=0;
}
queue::~queue()
{
}
void queue::insert(int i)
{
if (isfull())
{
cout<<"\n******Queue is FULL !!!No insertion allowed further.******" ;
return ;
}
a[rear] = i;
rear++;
}
int queue::remove()
{
if (isempty())
{
cout<<"\n******Queue Empty !!!Value returned will be garbage.******\n" ;
return (-9999);
}
int i = SIZE ;
while ( i--)
{
a[i] = 0;
};
return (a[0]);
}
int queue::isempty()
{
if (front == rear)
return 1;
else
return 0;
}
int queue::isfull()
{
if (rear == SIZE)
return 1;
else
return 0;
}
int queue::display( int n )
{
int i = a[n];
return i;
}
void main()
{
queue q;
int item;
while (!q.isfull())
{
cin>>item;
q.insert(item);
}
while (!q.isempty())
{
int n = SIZE ;
cout<<q.display(n);
n--;
}
cout<<"\n " <<q.remove();
cout<<"\n" <<q.remove();
}
Last edited on Nov 27, 2011 at 8:22am UTC
Nov 27, 2011 at 9:29am UTC
just use trim function on the string .
Nov 29, 2011 at 2:53pm UTC
How can i use trim function