0

So my Turbo C doesn't handle errors. And in school we used VC++ but I don't have it at home. So can anyone tell if the code snippets for Queue and Dequeuing a Queue and Pop and Push operations in Stack are right?

\int queue::dequeue()
{
try
{
if(front>rear)
throw 0;
}
catch(int)
{
cout<<"queue is empty\n";
return 0;
}
return a[rear];
}

void queue::enqueue(int ch)
{
try
{
if(cap==size)
throw size;
}
catch(int)
{
cout<<"queue is full\n";
return;
}
a[++rear]=ch;
size++;
}

void stack::push(int op)
{
try
{
if(top==SIZE)
throw top;
}
catch(int)
{
cout<<"Stack is Full \n";
return;
}
++top;
stck[top]=op;
}
int stack::pop()
{
try
{
int(top==0)
throw 0;
}
catch(int)
{
cout<<"Stack is Empty!\n";
return 0;
}
top--
return stck[top];
}
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

yeah, it would work!!!!!


But try using exception hierarchy in future.....it is more elegant, easy for complex problems

0

>>And in school we used VC++ but I don't have it at home

Why not? The express version is free for the asking (downloading). Would you build an engine for a 50 year-old car and expect it to work on a 2010 model?

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.