3/4/2021
The pointer in OCaml is different from what it is in C-like languagues, which made it harder to understand when comes to labs or projects.
This example, which is a simple enqueue function, has a few things to care about:
1. Turns out that "left", "right" are just pointers to the variable, or pointers to the node, instead of node itself. In a C-like language like java, I can simply say ptr is the pointer, but also the node itself, as I can call node function on ptr. But in OCaml, pointer is pointer, and node is node, represented as !left in this example.
2. In line 27, left := newNode is not re-assigning the node to left, as I was thinking, but to set the left pointing to the newNode. It may seems hard/easy to understand, but consider left now is still not the newNode, but the pointer to that node, thus would change the node in q as the left is now pointing to some other node.
After that it's just normal easy stuff, I'll put the code up for this queue, just incase sometime I may want to check it out.
Until next time;;