473,785 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5196
In article <r6************ ********@comcas t.com>, ke****@secret.c om
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(4 2);
foo.push_back(4 3);

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

foo_ptr = std::find(foo.b egin(), 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.b egin(), 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.a delphia.net...
In article <r6************ ********@comcas t.com>, ke****@secret.c om
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************ ********@comcas t.com>, ke****@secret.c om
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
4844
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 be What I am trying to do is that I have a global queue. I create an object of class "testClass" and then add it to the queue. My question
7
3436
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 could use inside this console application to make sure the MS SQL database is operational before I perform the insert?
9
2501
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 ride just add aditional code ontop of the current class or completely over ride it in vb? I am use to C++ this is the first inherited thing I've done in VB.NET... I'm a little unsure of diffrences, could someone explain this to me some? thanks!
3
5156
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': G:\Projects\Datastructure\Queue\main.cpp:16: undefined reference to `Queue<char>::Queue()' G:\Projects\Datastructure\Queue\Debug\main.o(.text+0x394): In function `Z10do_commandcR5QueueIcE':
2
2964
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 store up to 10 items? Output from my code: Enter you choice: 1 Enter ID document to print : 21 Enter you choice: 1 Enter ID document to print : 22
3
2041
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 the Queue.py code now to try to figure out how to make it work in 2.5, but as I am a beginner, I am having difficulty and would appreciate your help. Many thanks Jon
4
4599
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 length of my queue. I started getting compilation errors when I included a length function. <code> template<class ItemType> void Queue<ItemType>::MakeEmpty() {
0
2740
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 bad_alloc #include <iostream> //typedef std::queue<QueueItemTypeQueue; using namespace std; //private:{Queue::Queue(const Queue& Q)}
10
1833
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 names in this table. I'm ultimately trying to make it so the user can't add their information twice in this table. Well, you would think just making their ID the PK in the table would work, however I'm running into an issue with this. The user...
0
10350
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9957
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.