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];
}

Recommended Answers

yeah, it would work!!!!!


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

Jump to Post

All 2 Replies

yeah, it would work!!!!!


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

>>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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.