Final Flashcards
You can directly access the nth node of a linked list. T or F?
False
The dereference operator * accesses the variable to which a pointer points. T or F?
True
A linked list is not fixed in size. T or F?
True
When you return a dynamic array to the heap, you must include the number of elements in the array. T or F?
False
Arcade Object Creation
Arcade myArc(“Games Ablaze”, 5);
In a queue, a dequeue operation always removes _____ element.
the front
Declare a vector [class=Student, studList]
vector<Student> studList;</Student>
Which of the following statements allocates memory in the heap?
a = new int;
Given a stack myData: Tom, Sam (top is Tom), what is the output after the following operations?
Push(myData, Hal)
Pop(myData)
Pop(myData)
print(Peek(myData))
Sam
Linear search will compare all elements if the search key is not present. T or F?
True
What is the return type for constructors?
None
include <iostream></iostream>
Which XXX condition generates the following output?Not found
#include <string>
#include <vector>
using namespace std;</vector></string>
int BinarySearch(vector<int> numberList, int element, int lowVal, int highVal) {
int midVal;
if (XXX) {
midVal = (highVal + lowVal) / 2;
if (numberList.at(midVal) == element) {
return midVal;
}
else if (numberList.at(midVal) > element) {
return BinarySearch(numberList, element, lowVal, midVal - 1);
}
else {
return BinarySearch(numberList, element, midVal + 1, highVal);
}
}
else {
return -1;
}
}</int>
int main() {
vector<int> numberList(0);
int element = 20;
int matchPos;
for (int i = 0; i <= 10; ++i) {
numberList.push_back(i);
}
matchPos = BinarySearch(numberList, element, 0, numberList.size() - 1);
if (matchPos >= 0) {
cout << "Found at position " << matchPos << "." << endl;
}
else {
cout << "Not found. " << endl;
}
return 0;
}</int>
lowVal <= highVal
Which XXX completes the binary search algorithm?
BinarySearch(numbers, numbersSize, key) {
mid = 0
low = 0
high = numbersSize - 1
XXX {
mid = (high + low) / 2
if (numbers[mid] < key) {
low = mid + 1
}
else if (numbers[mid] > key) {
high = mid - 1
}
else {
return mid
}
}
return -1
}
while (high >= low)
Which of the following is true for overloading a class constructor?
The parameter types of the constructors should be different.
Given the queue myData 12, 24, 48 (front is 12), what will be the queue contents after the following operations?
Enqueue(myData, 72)
Dequeue(myData)
24, 48, 72