473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Inserting into a queue

JC
Hello all,

I was wondering if someone can give me some tips on this problem.

I'm trying to take content of a queue (Xqueue) and copy it into another
queue (Yqueue)
I tried using a while and/or for loop.

for example if queue X contains numbers (3,5,8,6)
I want to copy number (3,5) into queue Y, then I want to delete number 8
from queue X.
I then want to copy number (6) to queue Y (to keep them in order)
I'll then move them back to queue X which at this point will look like this
(3,5,6)

Thanks in advance you for all your help
JC
Jul 19 '05 #1
5 5178
In article <r6********************@comcast.com>, ke****@secret.com
says...
Hello all,

I was wondering if someone can give me some tips on this problem.

I'm trying to take content of a queue (Xqueue) and copy it into another
queue (Yqueue)
I tried using a while and/or for loop.

for example if queue X contains numbers (3,5,8,6)
I want to copy number (3,5) into queue Y, then I want to delete number 8
from queue X.
I then want to copy number (6) to queue Y (to keep them in order)
I'll then move them back to queue X which at this point will look like this
(3,5,6)


Why don't you try to tell us more precisely what you want as a result
instead of the way you're trying to produce that result?

Right now, it's not clear exactly what criteria you're using to decide
that 8 should be removed from the queue, nor is it clear exactly why you
have two queues involved. Just for example, something like this might
be useful: "I have an std::queue of int's and I want to remove from it
any item that is greater than the number that follows it."

Posting a minimal piece of compilable code that demonstrates what you're
doing is also _very_ helpful.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #2
JC <ke****@secret.com> writes

I'm trying to take content of a queue (Xqueue) and copy it into another
queue (Yqueue)
I tried using a while and/or for loop.


If the queue is an STL container, would the insert() member function be
what you're looking for?

You can do things like:

std::vector<int> foo;
std::vector<int> bar;
std::vector<int>::iterator foo_ptr;

foo.push_back(42);
foo.push_back(43);

bar.push_back(1);
bar.push_back(2);

foo_ptr = std::find(foo.begin(), foo.end(), 42);
if (foo_ptr != foo.end())
{
foo.insert(foo_ptr, 41);
}

// The iterator may have been invalidated so need to find "42" again.
foo_ptr = std::find(foo.begin(), foo.end(), 42);
if (foo_ptr != foo.end())
{
foo.insert (foo_ptr, bar.begin(), bar.end());
}
--
Simon Elliott
http://www.ctsn.co.uk/


Jul 19 '05 #3
JC
Hi Jerry,

here is the main code, I've writen so far. Let me know if you need to see
more....

Thanks
JC

-----------------
int main()
{
queue_num Q;
queue_tempg T;
int QCount, i, n, count;
// char ans;

Q.clear_queue();
T.clear_tempg();
i = 0;
QCount = 0;
count = 0;

cout <<"\n\tEnter a number\n\t==> ";
while ( !(Q.full_queue() ) )
{
cin >> n;
Q.insert_queue(n);
QCount++;
count++;
}

int rem;
cout <<"\n\tEnter a number to remove==> ";
cin >> rem;

if ( !(Q.empty_queue()) )
{
QCount = 0;
while ( !(Q.empty_queue() ) && ( QCount <= maxqueue ) )
{
if (rem == Q.queuearray[QCount] )
{
cout << "\n\tI found number "<<rem";
Q.delete_queue(QCount);

while ( !(Q.empty_queue()) )
{
n = Q.queuearray[QCount];
T.insert_tempg(n);
QCount++;
}
}
else
{
n = Q.queuearray[QCount];
cout << "\n\tNumber "<<rem<<" was NOT found";
T.insert_tempg(n);
QCount++;
}
}
}
---------------------------------
"Jerry Coffin" <jc*****@taeus.com> wrote in message
news:MP************************@news.clspco.adelph ia.net...
In article <r6********************@comcast.com>, ke****@secret.com
says...
Hello all,

I was wondering if someone can give me some tips on this problem.

I'm trying to take content of a queue (Xqueue) and copy it into another
queue (Yqueue)
I tried using a while and/or for loop.

for example if queue X contains numbers (3,5,8,6)
I want to copy number (3,5) into queue Y, then I want to delete number 8
from queue X.
I then want to copy number (6) to queue Y (to keep them in order)
I'll then move them back to queue X which at this point will look like this (3,5,6)


Why don't you try to tell us more precisely what you want as a result
instead of the way you're trying to produce that result?

Right now, it's not clear exactly what criteria you're using to decide
that 8 should be removed from the queue, nor is it clear exactly why you
have two queues involved. Just for example, something like this might
be useful: "I have an std::queue of int's and I want to remove from it
any item that is greater than the number that follows it."

Posting a minimal piece of compilable code that demonstrates what you're
doing is also _very_ helpful.

--
Later,
Jerry.

The universe is a figment of its own imagination.

Jul 19 '05 #4
JC wrote:
Hi Jerry,

here is the main code, I've writen so far. Let me know if you need to see
more....

Thanks
JC

-----------------
int main()
{ [...] if (rem == Q.queuearray[QCount] )
{
cout << "\n\tI found number "<<rem";
Q.delete_queue(QCount);

while ( !(Q.empty_queue()) ) [...]
}

"Jerry Coffin" <jc*****@taeus.com> wrote
Posting a minimal piece of compilable code that demonstrates what you're
doing is also _very_ helpful.


Hi JC,

your code is not compilable. One problem is that run-away string constant -- see
that stray double quote at the end of the line writing to cout.

And please don't top-post here. Thanks

Christian

Jul 19 '05 #5
In article <Ur********************@comcast.com>, ke****@secret.com
says...
Hi Jerry,

here is the main code, I've writen so far. Let me know if you need to see
more....


The most important thing I need to see is at least some attempt at
explaining what you're really trying to accomplish.

Right now, your code is written to say that it's a queue, but you seem
to want to do things that simply aren't possible with a queue. In
particular, with a queue you really only have two operations: you can
add items one end, and you can remove items from the other end. That's
it.

Right now, your code _seems_ intended to be able to find an item with a
particular value, and remove it from wherever it is -- potentially from
the middle of the collection. If that's what you want, then a queue is
NOT what you want. There are (various) data structures that will
support that, but a queue is not among them.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ~Gee | last post by:
Hi, When I try to compile the following program, I get the following error: $ g++ anotherTest.C anotherTest.C: In function `int main()': anotherTest.C:47: void value not ignored as it ought to...
7
by: Jared Evans | last post by:
I developed a console application that will continually check a message queue to watch for any incoming data that needs to be inserted into MS SQL database. What would be a low-cost method I...
9
by: Brian Henry | last post by:
If i inherite a queue class into my class, and do an override of the enqueue member, how would i then go about actually doing an enqueue of an item? I am a little confused on this one... does over...
3
by: Kceiw | last post by:
Dear all, When I use #include "queue.h", I can't link it. The error message follows: Linking... G:\Projects\Datastructure\Queue\Debug\main.o(.text+0x136): In function `main':...
2
by: lavender | last post by:
When define a maxQueue is 10, means it able to store 10 items in circular queue,but when I key in the 10 items, it show "Queue Full" in items number 10. Where is the wrong in my code? Why it cannot...
3
by: jrpfinch | last post by:
I have a script which is based on the following code. Unfortunately, it only works on Python 2.3 and not 2.5 because there is no esema or fsema attribute in the 2.5 Queue. I am hunting through...
4
by: j_depp_99 | last post by:
Thanks to those guys who helped me out yesterday. I have one more problem; my print function for the queue program doesnt work and goes into an endless loop. Also I am unable to calculate the...
0
by: ecestd | last post by:
I did implement the copy constructor but still have a problem with it. It is not working. What could be wrong? #include "QueueP.h" #include <cassert // for assert #include <new // for...
10
by: Clamato | last post by:
Good Morning, I'm working with a form that basically add's a users windows logon ID, first name, and last name to a table. A list box on this form is then requeried once added displaying the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.