Delphi TQueue, need to push_front

Started by
6 comments, last by Shannon Barber 22 years, 2 months ago
Is there a way to push something onto the front of the queue, instead of the back?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
What component is that? Url? ;-)
Wouldnt that be against the idea of a queue?

Once there was a time when all people believed in God and the church ruled. This time is called the Dark Ages.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Yep, it certainly would... unless you're the kinda person who barges to the front .

Anyway, here's a sample project I knocked up in a second:
TNotAQueue (about 2Kb)

It seems to work, but be sure to test that! I did it by deriving a class from TQueue and adding in another procedure, "Barge". That adds to the front of the queue (which, strangely, means the back of the list? wtf?). Anyway, the important thing to note is the protected member "List". I used that directly, which seems safe...

Lifepower: it's in the unit "contnrs" w/ Delphi 5 or 6 (can't remember which). That's if you're not joking... I can't tell because I'm high on caffeine just now.

Alimonster

There are no stupid questions, but there are a lot of inquisitive idiots.

Edited by - Alimonster on January 30, 2002 11:44:23 AM
Also worth noting: if you only need push to front behaviour then use TStack instead of TQueue. If you need both add to front and back behaviour then you could just use a TList instead of that thing above. It''s just a case of adding and inserting to the right places.
I never knew about the TQueue and TStack objects. That''s my little bit of learning for today.

Steve ''Sly'' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
2 Alimonster: Nope, I wasn''t joking - I didn''t know this class. Actually, even though I''ve been through all versions of Delphi (starting from 1), never used many Delphi built-in classes (like TList, etc) - did all that stuff myself (and I still keep my source code . Have my own reasons for that though....
btw, as I checked out TQueque list, it seems Borland haven''t gone too far with it... (maybe that''s at first sight? )

I had a queue of stuff to process, and sometimes it''s necessary to add a step (if things don''t go right) that needs to be processed before the rest of the steps. I''m now using a stack instead, and I just push everything on in reverse order. So far, I haven''t run into a case where I need to add a step to the end... I guess if I do I''ll just write my own (array based) deque.

The TStack/TQueue/TList objects are, shall we say, less than optimal, but I didn''t need speed for this piece of code.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement