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
  • 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