Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Inserting into a queue

Reply
Thread Tools

Inserting into a queue

 
 
JC
Guest
Posts: n/a
 
      10-26-2003
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


 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      10-26-2003
In article <(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed)
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.
 
Reply With Quote
 
 
 
 
Simon Elliott
Guest
Posts: n/a
 
      10-27-2003
JC <(E-Mail Removed)> 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/






 
Reply With Quote
 
JC
Guest
Posts: n/a
 
      10-28-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ia.net...
> In article <(E-Mail Removed)>, (E-Mail Removed)
> 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.



 
Reply With Quote
 
=?ISO-8859-1?Q?Christian_Brechb=FChler?=
Guest
Posts: n/a
 
      10-28-2003
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" <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Program blocked in Queue.Queue.get and Queue.Queue.put Kris Python 0 01-04-2012 03:46 PM
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
Is Queue.Queue.queue.clear() thread-safe? Russell Warren Python 4 06-27-2006 03:03 PM
what's the difference between #include "queue.h" and #include "queue.cpp" Kceiw C++ 3 03-14-2006 03:01 AM
Queue.Queue-like class without the busy-wait Paul L. Du Bois Python 29 04-04-2005 01:28 PM



Advertisments