You are given a template sorting function. You use it to sort an array of ints and an array of doubles, but it wont compile when you give it an array of Jedi. Why won't it work?
Because Jedi are objects, the compiler does not know when one Jedi is greater than or less than another unless the Jedi class contains overloaded greater than and less than (comparison) operators.
(T/F) A recursive function cannot ever call any function other than itself.
(T/F) If a recursive function's base case is never met, the function will recurse infinitely.
False, the system will run out of memory causeing a stack overflow error.
A ________ variable will stay in memory even after the function that declared it is removed from the stack.
When deleting from a standard linked list, removing the ________ must be treated as a special case.
head - because without the head the entire list is inaccessible
List the 4 questions that verify that a problem can be solved recursively.
(Remember SBCR - smaller, base case, closer, reduce)
1) Can you define the problem in terms of smaller versions of itself?
2) What is/are the base case(s) - when the problem is solved?
3) Will each step (recursive call) move you closer to the solution?
4) Are you guaranteed to reach a base case?
Which linked list variant contains no null pointers (unless it's empty)?
b) Doubly linked
c) Dummy head node
Why can't a linked list directly access any of its nodes?
A linked list node can only be accessed using the pointer to it that is stored in the previous node.
What would you have to do to an array to make it work like a Stack?
You would keep track of the index of the top element (the largest index of an element in the array).
When an element is added to the stack it must be added to the top + 1 index of the array.
When an element is removed from the stack the element at the top position of the array must be deleted.
What would you have to do to a Linked List to make it work like a Queue?
You should implement a Linked list with a tail pointer because insertions in a Queue happen at the end, while deletions happen at the head.
When you add an item to this queue, you must update the tail pointer and update the previous tail's next to point to the new node.
When you delete an item from this queue, you use a pointer (curr) to point to the old head, advance head to head-> next, and delete curr.
What do you have to do when enqueueing and dequeueing an in array-based queue to "wrap-around"?
******************Look this up *************************
You have a list of numbers that is almost entirely sorted smallest to largest. Only one small-value number is out of place and it is near the end of the list amongst the large numbers. Why would insertion sort outperform bubble sort in this situation?
Bubble sort can only move items toward the beginning of the list one position for each iteration of the sort algorithm. Insertion sort will move the small-value number to its proper position in the iteration that positions the small-value number into the sorted portion of the list.
If a sequential search is performed on an array, how many items would have to be looked at to find the n-th item in the list?
n items. 1st = 1 look, 2nd = 2 looks, ...
If a binary search is performed on an array, how many items would have to be looked at to find the n-th item on the list?
It depends on the position. Since binary search splits the "list" in half each iteration, it depends on the size of the list.
If you const modify a member function in a class, what is the result?
Class definitions always end with:
If you use the static modifier on a local variable in a function, what is the result?
Select the default constructor:
Select the initializing constructor:
Select the copy constructor:
One of these sentences is false, select it.
The #pragma once and #ifndef - #define - #endif combo serve the same purpose. What is it?
They both serve to prevent redefining the class in memory.
Public inheritance is which type of class relationship?
(T/F) In C++, you can derive a class directly from more than one superclass.
(T/F) Composition is the same as protected inheritance.
In C++, what notation is used to indicate that a function is a pure virtual function?
(T/F) Any pointer can be used to create a dynamic array.
List the big three functions that you need to make when a class uses pointers to create dynamic memory.
overloaded assignment operator
When does a class's copy constructor execute?
What are friend functions?
The two overloaded operators shown below can be called using (obj + obj2). Indicate which one is a member function of class Goober and which one is not.
bool operator < (Goober g1, Goober g2);
bool operator < (Goober g1);
The first is a non-member; you can tell because it has two arguments. The second is a member because it has one argument.
To prevent a pointer from 'dangling', set its value to ________.