- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
I am looking at an algorithm, that inserts an element in a sorted list:
In which case will the command [m] if (pq == NULL) then L = p; [/m] be executed?
I am looking at an algorithm, that inserts an element in a sorted list:
Code:
void llinsert(Type x, pointer L)
pointer C, ptr;
q = L;
pq = NULL;
while (q != NULL) and (q->data < x) {
pq = q;
q = q->next;
}
if (q != NULL) and (q->data == x) then return;
p = NewCell(Node);
p->data = x;
p->next = q;
if (pq == NULL) then L = p;
else pq->next = p;
In which case will the command [m] if (pq == NULL) then L = p; [/m] be executed?