6 Replies - 1198 Views - Last Post: 12 April 2011 - 06:55 AM Rate Topic: -----

#1 nadheshiko  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 11
  • Joined: 11-December 10

circular queue

Posted 12 April 2011 - 06:16 AM

while performing circular queue operations i'm getting wrong output
is this code correct
class cqueue
{
int cq[5],f,r;
public:
cqueue();
void insert();
void delete();
void display();
};
cqueue::cqueue()
{
f=-1;
r=-1;
for(int i=0;i<5;i++)
cq[i]=0;
}
void cqueue::insert()
{
int ele;
cout<<"enter element";
cin>>ele;
if((r<4)&&(f==0))
cout<<"cq s full";
else
{
r++;
cq[r]=ele;
}
if(f==-1)
f=0;
if((r==4)&&(f!=0))
r=0;
}
void cqueue::delete()
{
int data;
if(f<0)
cout<<"cq is empty";
else
{
data=cq[f];
cq[f]=0;
f++;
}
if(f==r)
{
f=-1;
r=-1;
}
if(f==4)
f=0;
void cqueue::display()
{
if(r>f)
for(int i=f;i<=r;i++)
cout<<cq[i];
}
else
{
for(int i=f;i<=4;i++)
cout<<cq[i];
for(int i=0;i<=r;i++)
cout<<cq[i];
}


MOD EDIT: Added code tags...when posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 17 May 2011 - 03:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: circular queue

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: circular queue

Posted 12 April 2011 - 06:19 AM

1. Please edit your post and :code: to make it legible.

2. Please describe your problem more precisely. What does "getting wrong output" mean? What information are you entering, what output do you expect, and what output are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is online

  • member icon


Reputation: 4019
  • View blog
  • Posts: 12,407
  • Joined: 25-December 09

Re: circular queue

Posted 12 April 2011 - 06:21 AM

First use code tags!!!!!

Quote

is this code correct

Second, does the code compile without error/warning messages?

Third, does the program produce the desired output?

If either of the questions above is no then I would say your code is probably not correct.

If the code compiles without error/warning messages.

If you tell us what inputs you supplied the program, what you expect the output to be, and what the output actually is we might be able to help.

If it does not compile post the complete exact error messages.

Jim
Was This Post Helpful? 0
  • +
  • -

#4 nadheshiko  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 11
  • Joined: 11-December 10

Re: circular queue

Posted 12 April 2011 - 06:34 AM

View Postjimblumberg, on 12 April 2011 - 06:21 AM, said:

First use code tags!!!!!

Quote

is this code correct

Second, does the code compile without error/warning messages?

Third, does the program produce the desired output?

If either of the questions above is no then I would say your code is probably not correct.

If the code compiles without error/warning messages.

If you tell us what inputs you supplied the program, what you expect the output to be, and what the output actually is we might be able to help.

If it does not compile post the complete exact error messages.

Jim

it compiles without any warning messagea and errors
but if if i pass(insert) 10 20 30 40 50 as my inputs
it displays as 0 0 0 0 50
and if i delete 1 time
it displays as 0 0 0 0 51
and if i delete 2nd time
it displays as 0 0 0 0 52
but the exact out put is
10 20 30 40 50
10 20 30 40
10 20 30
can you help with this
Was This Post Helpful? 0
  • +
  • -

#5 jimblumberg  Icon User is online

  • member icon


Reputation: 4019
  • View blog
  • Posts: 12,407
  • Joined: 25-December 09

Re: circular queue

Posted 12 April 2011 - 06:46 AM

When I compile your code I get the following error messages:

main.cpp|8|error: expected unqualified-id before ‘delete’|
main.cpp|35|error: expected unqualified-id before ‘delete’|



In C++ delete is a reserved word and can not be used for variable or function names.

Jim
Was This Post Helpful? 0
  • +
  • -

#6 nadheshiko  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 11
  • Joined: 11-December 10

Re: circular queue

Posted 12 April 2011 - 06:50 AM

View Postjimblumberg, on 12 April 2011 - 06:46 AM, said:

When I compile your code I get the following error messages:

main.cpp|8|error: expected unqualified-id before ‘delete’|
main.cpp|35|error: expected unqualified-id before ‘delete’|



In C++ delete is a reserved word and can not be used for variable or function names.

Jim

then what we have to use instead of that
when our professor did it on some other system he got the correct output
but when we did it we can't get
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is online

  • member icon


Reputation: 4019
  • View blog
  • Posts: 12,407
  • Joined: 25-December 09

Re: circular queue

Posted 12 April 2011 - 06:55 AM

It doesn't really matter what you call it as long as it is not a reserved word.

See this link for reserved words.

Jim
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1