Link to home
Start Free TrialLog in
Avatar of feldmani
feldmaniFlag for United States of America

asked on

VB.Net queue question

Maybe I am burned out, but I am having trouble figuring this out and don't have the time to play with it.  

        Dim Current_Node As New Node
        Dim Fringe As New Queue
        Fringe.Enqueue("EMPTY QUEUE")
        Dim Successors() As Node
        Current_Node.set_node(0, 0, 0, 0, False)
        Fringe.Enqueue(Current_Node)
        Current_Node.set_node(Cannibals, Humans, humans_on_top, Savages_On_Bottom, False)
        MessageBox.Show(Current_Node.string_result)
        Fringe.Enqueue(Current_Node)
        Do
            Current_Node = Fringe.Dequeue()

How come I am getting errors when I try to dequeue?
Avatar of SStory
SStory
Flag of United States of America image

hard to tell. You need to tell us what error you are getting.  If you dequeue one time before the do loop does it give you an error? If so what? If not, it doesn't like being in the loop in whatever way you are using it.

I need more info.
Avatar of feldmani

ASKER

The error happens as soon as I enter the loop.  I step through the problem.  The error I am getting differs, If I enqueue the string first, it says comparing wrong variables.  If not, it says queue is empty.  Why is it not recognizing that I am putting nodes in the queue?
How could you put in a string first, then dequeue it to a node and expect that to work?
        Fringe.Enqueue("EMPTY QUEUE")

        Current_Node = Fringe.Dequeue()

Current_Node is a Node not a string

I never see where you are creating a new Node each time before enqueing it. If it is an object, you should use New to create one, then enqueue it, then use new to create another, etc.
The problem is  I am comparing things in a queue that are two objects, nodes, and even though they are the same, it won't recognize them.  I believe this has somethign to do with the fact that it is just comparing the reference.  
I'm not sure I understand. Are you saying you need to do a CTYPE to cast them to node to do the compare?

Current_Node=CTYPE(Fringe.DEQUEUE,Node)
What do you mean?  I might need to do a CTYPE.  It seems to me my problem comes in when I try to cmopare two things that are the same but it says they aren't.  (Hence, it tries to take off the queue twice instead of once.  I am assuming the reason that is happenning is because I am comparing pointers(references) instead of values.
ASKER CERTIFIED SOLUTION
Avatar of SStory
SStory
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No, let me give it a try and I will let you know what comes up.  I don't really need the solution anymore per se, since I just used an array list instead (resulting in a huge re-write of code).  But it will be nice to know how to do this for the future.  
SOrry, I made the request before sstory replied.  He helped out, so I would like to give him the credits.