{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

COS110Tutorial 11-memo - University of Pretoria COS110...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 University of Pretoria COS110 Tutorial 11 MEMO-MEMO-MEMO Date: 26 October 2011 Time: 50 minutes Marks: 35 Student Surname and Initials:____________________________________________ Student number:__________________ Employee number:___________________ Question 1 Doubly linked lists [6 marks] (Scope: Lecture 31) Study the class definition below for a doubly linked list class: class NumberList //--------------- { public: NumberList(); ~NumberList(); void appendNode(int val); void printReverse(); private: struct ListNode { int value; struct ListNode *next; struct ListNode *prev; }; ListNode *head; }; Complete the code below to print the list contents in reverse. (6 marks) void NumberList::printReverse() {
Image of page 1

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

View Full Document Right Arrow Icon
2 //start at the beginning of the list and locate //the last node in the list ________________________________________________ ________________________________________________ ________________________________________________ //now move towards beginning printing the value in each node ________________________________________________ ________________________________________________ ________________________________________________ ________________________________________________ ________________________________________________ } Solution: void NumberList::printReverse() { //start at the beginning of the list and locate //the last node in the list nodePtr = head; while (nodePtr->next != NULL) nodePtr = nodePtr->next; (3 marks) //now move towards beginning printing the value in each node while (nodePtr->prev != head) { cout << nodePtr->value << endl; nodePtr = nodePtr->prev; } (3 marks) } Question 2 Stack ADT and static stacks [16 marks] (Scope: Lectures 31, textbook sections 18.1) A class for the stack ADT to hold integer values has been defined as follows: class Stack { public: Stack(int size); ~Stack( ); void push(int newVal); int pop( ); int peek( );
Image of page 2
3 bool isFull() const; bool isEmpty() const; private: int *stackArray; // Pointer to the stack array int stackSize; // The stack size int stackTop; // index for top of the stack }; a. Study the code below and answer the questions that follow:
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern