# GML: check ds_queue or ds_stack for equality (identical contents)

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));


should return true

Options I know of:

• foo == bar returns 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_dequeue destroys 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_copy and destructively iterate over the duplicates -- is this the best way?

As far as I know the same issues apply to stacks.

• Your third approach is fine, you could create a copy of each data structure you need and then check their respective values: the original data is fine since you're working on clones. – liggiorgio Feb 5 '19 at 0:10

You may want to use simple ds_lists and take advantage of the function ds_list_find_value() to search for L1's values in L2's.
• Then you can keep a copy of a ds_queue to dequeue the next value from, and copy & convert the other data in a ds_list to exploit its function ds_list_find_value and avoid implementing a search feature yourself. – liggiorgio Feb 5 '19 at 0:20