Content deleted Content added
WikiProject Systems Assessment |
No edit summary |
||
Line 32:
I don't know, but I wanted to ask the same question. I'm not so familiar how to handle that, or mark it, so that this could checked by someone who has the knowledge and delete it. <small>—Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/194.39.218.10|194.39.218.10]] ([[User talk:194.39.218.10|talk]]) 07:55, 10 January 2008 (UTC)</small><!-- Template:UnsignedIP --> <!--Autosigned by SineBot-->
== The code fragment is buggy ==
Try a simple thought experiment: <source lang=cpp>queue(1);
item = dequeue();</source>
The front and back pointers are not connected by the queue and dequeue functions, so the sequence won't work as expected.
A possible fixed version of the functions:
<source lang=cpp>
fifo_node *dequeue(void)
{
fifo_node *tmp = front;
if (front == back) {
front = back = NULL;
} else {
front = front->next;
}
return tmp;
}
queue(value)
{
fifo_node *tempNode = new fifo_node;
tempNode->value = value;
if (back) {
back->next = tempNode;
back = tempNode;
} else {
front = back = tempNode;
}
}
</source>
Note that this code is twice as long! The whole class would cover a full screen. I'm not sure such a queue implementation would fit into the article...
Ideas?
|