Is there a nondestructive way to check whether two queues or stacks contain identical values? For example:
foo=ds_queue_create(); ds_queue_enqueue(foo, 1); ds_queue_enqueue(foo, 2); bar=ds_queue_create(); ds_queue_enqueue(bar, 3); ds_queue_enqueue(bar, 1); ds_queue_enqueue(bar, 2); ds_queue_dequeue(bar); return(equality_test(foo, bar));
Options I know of:
foo == barreturns
false, presumably because it's checking whether they point to the same queue as opposed to having the same values.
ds_queue_write(foo) == ds_queue_write(bar)seems to be sensitive to the queues' histories. If I just enqueue
[1,2]on each queue, it gives
true. But because I added and then dequeued an irrelevant value on
bar, the serialized strings differ even though the current values are identical.
- Iterating through the items one at a time and checking equality works for arrays, but doing this using
ds_queue_dequeuedestroys the queues. Is there a nondestructive way to read elements of a queue, other than the head and tail?
- Per liggiorgio's comment below, I could duplicate the queues with
ds_queue_copyand destructively iterate over the duplicates -- is this the best way?
As far as I know the same issues apply to stacks.