SML : Dequeue a list of tuples

353 views Asked by At

I have a datatype of the form :

datatype 'a mlqueue = N | Q of (int * int * 'a) list;

I have to write a dequeue function such that

val dequeue : 'a mlqueue -> 'a * 'a mlqueue*

So if my queue is :

val q = Q [(0,0,3),(1,0,4),(1,1,2),(2,0,5),(2,1,6),(2,2,1)];
- dequeue q;
val it = (4,Q [(1,1,2),(2,0,5),(2,1,6),(2,2,1)]) : int * int mlqueue

Here is my problem:

fun dequeue (Q []) = raise Empty | dequeue (Q((l,p,v)::xs)) = (v, Q xs);

The function in this form won't modify the original queue and when I call dequeue for the second time, it gives the same output as it did for the first time.

Can anyone please help and tell me how to write this function?

0

There are 0 answers