WorksheetsQUIZ 1 DS1E
Total questions: 10
Worksheet time: 9mins
Encapsulation combines an ADT’s data with its operations to form a(n) ______.
exception
method
object
variable
What does the following recursive algorithm display?
writeBack(in s:string)
if (s is empty)
return
else
{
Write the first character of s
writeBack(the string beginning at the second character of s)
}
nothing
the first character of s a number of times equal to the length of s
the string s
the string s backward
A stack is initially empty, then the following commands are performed:
push 5, push 7, pop, push 10, push 5, pop
which of the following is the correct stack after those commands (assume the top of the stack is on the left)?
5 10 7 5
5 10
7 5
10 5
4. If the array [6, 2, 7, 13, 5, 4] is added to a stack, in the order given, which number will be the first number to be removed from the stack?
6
2
5
4
What is the value of the following postfix expression: 5 2 – 8 4 + * ?
-9
28
35
36
What behaviour does the ADT stack exhibit?
first in, first out
first in, never out
last in, first out
last in, last out
Which of the following statements inserts a new node, pointed to by newPtr, at the end of a linear linked list?
newPtr->next = cur;
prev->next = newPtr;
newPtr->next = head;
head = newPtr;
newPtr->next = NULL;
prev->next = cur;
newPtr->next = cur;
Below is a function, countNode, to calculate the number of nodes in a list. Fill in the blank with a proper statement.
int linkedList:: countNode (linkedList *list)
{
int count = 0;
ptr = list->head;
while (FILL IN THE BLANK)
{
count++;
ptr = ptr->next;
}
return count;
}
ptr != ptr->next
ptr = ptr ->next
ptr != NULL
ptr = NULL
Which of the following operations of the ADT stack accepts a parameter?
push
isEmpty
peek
destroyStack
How many asterisks are printed by the function call quiz (5) ?
void quiz(int i)
{
if (i > 1)
{
quiz(i / 2);
quiz(i / 2);
}
cout << "*";
}
5
6
7
8
