473,386 Members | 1,842 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,386 software developers and data experts.

Queue Implementation

Hi.

Does anyone know how to implement queue in VB6.0 ?

I just need the push function to push end of queue and pop to remove an item from top of the queue.
Sep 26 '07 #1
11 5195
Killer42
8,435 Expert 8TB
Does anyone know how to implement queue in VB6.0 ?
Sure, just write a couple of functions to add and remove things in an array.
Sep 26 '07 #2
QVeen72
1,445 Expert 1GB
Hi,

You can also use non-sorted ListBox as a Queue,

To Add :
List1.AddItem "ABCD", 0
'This Adds on Top

To PopOut Last item :
str1 = List1.List(List1.ListCount-1)
List1.RemoveItem List1.ListCount-1

Same thing you can do with array as Killer suggested.
But ease with ListBox is, you don't have to loop through all the items to Push Down, just AddItem at 0, ensures, other Listitems are pushed down.

REgards
Veena
Sep 26 '07 #3
hariharanmca
1,977 1GB
Hi, You can also use non-sorted ListBox as a Queue ...
You have to use Array or pointer for Queue operation. Controls will not be a better example (of course we can use practically). But logically, in Listbox we can remove items from the middle of list using index value and change value for next index which should not happen in queue (FIFO).
Sep 26 '07 #4
QVeen72
1,445 Expert 1GB
In List we can remove items from the middle of list using index value and change value for next index which should not happen in queue (FIFO).
Hide the ListBox. Don't allow user to control List Items,
programatically add/remove items from list like a Queue.

Regards
Veena
Sep 26 '07 #5
Killer42
8,435 Expert 8TB
While a control such as a ListBox may not match the ideal logical model of a queue, I agree that it's quite a clever and practical (not to mention convenient) way of providing this sort of functionality. An array isn't perfect either, and a control like the ListBox does a lot of the work for you.

Naturally you would keep the ListBox hidden, so the user cannot play with it.

In fact, it occurs to me that using a ListBox would have one nice advantage. Any time you do want to see the queue, during development or debugging, all you have to do is make it visible. :)
Sep 26 '07 #6
Hi,

When i try the below piece of code, I get a run-time error 91 saying object variable not set. does the listbox haveto be initialized in some way?

thanks,
deepthi

Hi,

You can also use non-sorted ListBox as a Queue,

To Add :
List1.AddItem "ABCD", 0
'This Adds on Top

To PopOut Last item :
str1 = List1.List(List1.ListCount-1)
List1.RemoveItem List1.ListCount-1

Same thing you can do with array as Killer suggested.
But ease with ListBox is, you don't have to loop through all the items to Push Down, just AddItem at 0, ensures, other Listitems are pushed down.

REgards
Veena
Oct 21 '07 #7
I don't like the idea of a listbox. It requires a form. Who knows if the application even has a form. I suggest a Collection.

Expand|Select|Wrap|Line Numbers
  1. Dim stack as New Collection
  2.  
  3. Sub push(whatever as Object)
  4.     stack.add(whatever)
  5. End Sub
  6.  
  7. Function pop()
  8.     if stack.Count = 0 then
  9.         Call MsgBox("Error stack is empty!")
  10.         Set pop = Nothing
  11.     Else
  12.         Set pop = stack.item(stack.Count)
  13.         stack.Remove(stack.Count) ' This reduces the Count
  14.     End If
  15. End Function
Oct 22 '07 #8
thanks! the Collection worked
Oct 22 '07 #9
Killer42
8,435 Expert 8TB
I don't like the idea of a listbox. It requires a form. Who knows if the application even has a form. I suggest a Collection.
Thanks Hop. :)

I agree that the Collection is probably the better method. Especially since it allows you to stack pretty much anything, rather than just strings.

However, are you sure that you have to have a form to use a listbox? I thought you could just create one in code. (Note, I'm just asking, not arguing.)
Oct 22 '07 #10
Killer42
8,435 Expert 8TB
Oh! Just thought of something.

The OP asked for a queue, which would be FIFO. What hopalongcassidy provided was a stack, or LIFO. The difference is not huge, of course, but I think it should be pointed out so people can implement whichever is appropriate.

To convert this to a queue I believe that both references to stack.Count in the pop() function should be changed to 1.
Oct 22 '07 #11
This may be a little bit stale, but for people sumbling upon this thread, I have added a few sentences to clarify the proper understanding of the destictions called Stacks and Queues.

Please remember that a Stack data structure as mentioned by others is a list where nodes (or items) are added in a last in first out fashion LIFO. This is conceptually similar to an actual stack of coins where the rules only allow you to add coins (Push) or remove (Pop) coins to and from only the top of the stack respectively.

On the other hand, the QUEUE data structure allows one to ENQUEUE an item at the beginning of the list where in this case the beginning signifies the location of the most recently added or to be added item. And, the end of the list signifies the oldest item in the list. The oldest items in a Queue are ALWAYS the first to be removed or in this case DEQUEUED. A Queue, therefore, describes a First In First Out or FIFO list.

In summary, STACKS are list datastructures where items are PUSHEDed to be added to the beginning of the list. And items are POPed to be removed from the beginning. A STACK can be said to describe a LIFO list. Queues are list datastructures where items are Enqueued at the beginning and Dequeued from the end of the list.
Dec 30 '13 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

29
by: Paul L. Du Bois | last post by:
Has anyone written a Queue.Queue replacement that avoids busy-waiting? It doesn't matter if it uses os-specific APIs (eg WaitForMultipleObjects). I did some googling around and haven't found...
4
by: Sachin Jagtap | last post by:
Hi, I am getting exception while poping item from queue, I am writing messages coming from client in a queue in one thread and then in other thread i am reading from queue and writing in file....
2
by: Hollywood | last post by:
I have a system in which I have a single thread that places data on a Queue. Then I have one worker thread that waits until data is put on the thread and dequeues the Queue and processes that...
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':...
13
by: Jonathan Amsterdam | last post by:
I think there's a slight design flaw in the Queue class that makes it hard to avoid nested monitor deadlock. The problem is that the mutex used by the Queue is not easy to change. You can then...
5
Rooro
by: Rooro | last post by:
Hello everyone i'm working on : " Familiar childhood games such as hide and Go Seek and Tag involve determining the player who is to be "It". One method has the players stand in a circle...
2
by: tikcireviva | last post by:
Hi Guys, I've done a mulithread queue implementation on stl<queue>, my developement environment is on VC6 as well as FC3. Let's talks about the win32 side. The suspected memory leak is find...
1
by: VanKha | last post by:
I write a queue program but it doesn't work properly:I enqueue an element and dequeue just after that, but the output is the first value and then many times of "Empty queue.."!Why ?Please help me. ...
2
by: ecestd | last post by:
how do you implement a copy constructor for this pointer-based ADT queue #include <cassert // for assert #include <new // for bad_alloc using namespace std; //private:{Queue::Queue(const...
14
by: AlarV | last post by:
Hello everyone, here is my problem. I have to make a dynamic priority queue,which is a heap, and my book isn't helpful at all, so I have no clues on how to create it.. I read something like a static...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.