+ 1
Simple linked list, is element fumction! (m && n)
Why do you use "m && n" instead of just "n" for comparison in this case of a is element function of a simple linked list? int list_iselem(list m, int n) { while(m && n != m->element) { m = m->next; } return (m && n == m->element); }
2 Antworten
+ 2
m is your pointer. If it is null, it doesn't point to anything and is also 0/false. If it does point to something, it is non-zero or true.
+ 1
Oh thank you, that makes sense. I guess I confused the prioritys there too. != has the higher priority than && so if the left statement is unequal and the right is true, the loop gets executed.