ObjectWorksheet - end of part 4 In comments I am saying...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Worksheet on using pointers, classes, and objects Look at the handout I gave out on C vs C++. We will assume the code of the Link and LinkedList classes. Make sure you look on both sides. You may work with a partner and ask questions when you get stuck. On a separate piece of paper, draw what memory looks like as this set of instructions executes. Link *head = new Link(10); head->setNext(new Link(16)); head->ge->setNext(new Link(9)); // (end of part 1 – we’ll draw this on the board) Link *l = new Link(8); l->setNext(head); head->setNext(head) = l; // end of part 2 – draw on board l = new Link(4); l->setNext((head->getNext())->getNext()); (head->getNext())->setNext(l); // end of part 3 – draw on board LinkedList *list = new LinkedList(); list->addFriendFront(5); list->addFriendFront(7); list->addFriendBack(9);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // end of part 4 In comments, I am saying what I want each line to do. Write each line, using the handout and the code you just saw on the other side of this paper as your guide. // Declare a variable of a type that contains the address of a Link. Name it head. // assign that variable to a newly allocated array of 4 Link objects // For each Link object, set its next pointer to the previous object in the array. The first is NULL. // Point head to the 4th Link in the array now, not the first // For each Link’s value field, set its value to its position squared // use l to step through the array and make the assignments // write this as a loop Link *l; for ( l = head; l ; l = ) { } // loop through the list and print out each value for ( l = head; l ; l = ) { }...
View Full Document

This note was uploaded on 12/27/2011 for the course CMPSC 24 taught by Professor Agrawal during the Fall '09 term at UCSB.

Page1 / 2

ObjectWorksheet - end of part 4 In comments I am saying...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online