someone, show me some intelligence:

Nov 16, 2007 20:16

What is wrong with the following code?
This was from an interview.
(Now RFC 3092 compliant).

int* head = 0;
int* tail = 0;

struct foo{

int bar;
int *pNext;

}baz;

insert ( int qux ) {
baz* quux;

quux = malloc( sizeof(baz) );
quux->bar = qux;
if (head == tail ) {
head = quux;
tail = quux;
}

/* rest of insert */
}

programming

Leave a comment

Comments 3

belcantin November 17 2007, 08:08:03 UTC
I see what's wrong with it. It's full of stupid people.

Reply


tecknicaltom November 19 2007, 13:50:38 UTC
I assume that your complaint is that the proper handling of inserting the first item into the linked list will leave head == tail == the first item. After which, inserting the second will lose the first, etc. Do I win 10 internets?

Reply

palantiri November 19 2007, 19:51:37 UTC
10 internets and a cookie.

Reply


Leave a comment

Up