Brent Dax (brentdax) wrote,
Brent Dax
brentdax

  • Mood:
I got my computer science test back ("Midterm 1", which seems like an oxymoron), and it was good. 100% good. Wai.

The only thing he even suggested was wrong was actually right. The code below was to compute the intersection of two linked lists, a and b, returning the result in dest:

void join(List *a, List * b, List * dest) {
    ListNode *pA=a->header(), *pB=b->header();
    
    while(pA && pB) {
        if(pA->x == pB->x) {
            dest->append(pA->x);
        }
        if(pA->x <= pB->x) {
            pA = pA->next;
        }
        if(pB->x <= pA->x) {
            pB = pB->next;
        }
    }
}
He thought that the use of "<=" was incorrect--his exact comment was "cannot be equal anymore". But if you look at it, that isn't true (I didn't use "else if"), and in fact that's central to the program's structure.

The cool thing was, I did not study for this test. I did not read the textbook, or pay attention in class. Moreover, one of the questions involved implementing a queue, something I've never actually done before, but I had no trouble with it. I also pulled my answers on the final questions (some stuff about hashing--English answers, not code) out of my ass, but apparently my ass knows a lot about hashes, because they were all correct.
Subscribe

  • Paging madlori (and anyone who knows her)

    An interesting thing just happened on Facebook chat. Lori Summers [2:29:44] Got my message ? Brent Royal-Gordon [2:33:45] I did. Lori Summers…

  • guest post

    kate is the best better than the rest the best the best haikus about kate: kate's my favourite i want to lick her ballsack it would taste so…

  • Practice

    This December, I will have been practicing programming seriously for ten years. That will mark the tenth anniversary of me starting to learn Perl. I…

  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments