Deck 19: Stacks and Queues
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/47
Play
Full screen (f)
Deck 19: Stacks and Queues
1
Computer systems use stacks. For example, when a function is called, they create local variables on a stack which are removed from the stack when the function terminates.
True
2
In a static stack class, the constructor function can dynamically allocate memory for the stack array.
True
3
A dynamic stack has a __________ size and is implemented as a(n) __________.
A) variable, linked list
B) fixed, linked list
C) variable, array
D) fixed, array
E) None of these
A) variable, linked list
B) fixed, linked list
C) variable, array
D) fixed, array
E) None of these
A
4
A real-world example of the queue data structure can be seen in a stack of cafeteria trays where the last tray pushed onto the stack is the first tray removed.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
5
A dynamic stack starts as an empty linked list.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
6
The programmer must declare in advance the size of a dynamic stack or queue.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
7
The pop function in the stack template of the STL does not retrieve the value from the top of the stack; it merely removes it.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
8
Stacks and queues can be implemented as arrays or linked lists.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
9
A(n) __________ is an abstract data type that stores and retrieves items in a last-in-first-out manner.
A) array
B) queue
C) stack
D) vector
E) None of these
A) array
B) queue
C) stack
D) vector
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
10
The two most common queue operations are push and pop.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
11
The two most common queue operations are endeque and deque.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
12
For a compiler that is older than C++11 it is necessary to put spaces between the angled brackets that appear next to each other when defining a stack.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
13
The first item placed onto a stack is always the last item removed from the stack.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
14
A stack that is implemented as a linked list is known as a deque.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
15
The STL provides containers for deque and queue.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
16
What does the following statement indicate?
Stack< int, vector > iStack;
A) a new stack of integers, implemented as a vector
B) a new stack of integers, implemented as a deque
C) a new stack named vector, implemented as integers
D) a new vector named stack, implemented with integers
E) None of these
Stack< int, vector
A) a new stack of integers, implemented as a vector
B) a new stack of integers, implemented as a deque
C) a new stack named vector, implemented as integers
D) a new vector named stack, implemented with integers
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
17
Two primary queue operations are
A) push and pop
B) enqueue and dequeue
C) insert and delete
D) onqueue and offqueue
E) None of these
A) push and pop
B) enqueue and dequeue
C) insert and delete
D) onqueue and offqueue
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
18
When the program knows the exact contents of a list and can access any element on demand, the data structure is known as a stacked deque.
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
19
The two primary stack operations are
A) push and pull
B) push and pop
C) insert and delete
D) append and delete
E) None of these
A) push and pull
B) push and pop
C) insert and delete
D) append and delete
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
20
The __________ operation allows an item to be stored on a stack.
A) append
B) add
C) pop
D) push
E) None of these
A) append
B) add
C) pop
D) push
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
21
Stacks are useful data structures for algorithms that work __________ with the __________ saved element in the series.
A) last, first
B) first, last
C) efficiently, first
D) efficiently, last
E) None of these
A) last, first
B) first, last
C) efficiently, first
D) efficiently, last
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
22
A __________ queue is more intuitive and easier to understand than a __________ queue.
A) static, dynamic
B) dynamic, static
C) deque-like, stack-like
D) stack-like, deque-like
E) None of these
A) static, dynamic
B) dynamic, static
C) deque-like, stack-like
D) stack-like, deque-like
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
23
Given the following code, assume the myStack object is a stack that can hold integers and that value is an int variable. 1 myStack.push(0);
2 myStack.push(1);
3 myStack.push(2);
4 myStack.pop(value);
5 cout << value << endl;
Assume that the pop function, called on line 4, stores the number popped from the stack in the value variable. What will the statement on line 5 display?
A) 0
B) 1
C) 2
D) None of these
2 myStack.push(1);
3 myStack.push(2);
4 myStack.pop(value);
5 cout << value << endl;
Assume that the pop function, called on line 4, stores the number popped from the stack in the value variable. What will the statement on line 5 display?
A) 0
B) 1
C) 2
D) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
24
A __________ stack or queue is built around the linked list.
A) dynamic
B) static
C) deque-based
D) floating-point
E) None of these
A) dynamic
B) static
C) deque-based
D) floating-point
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
25
A dynamic stack may be implemented as a(n) __________ and can expand or shrink with each push or pop operation.
A) array
B) structure
C) linked list
D) Either A or B
E) None of these
A) array
B) structure
C) linked list
D) Either A or B
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
26
Given the following code, assume the myStack object is a stack that can hold integers and that value is an int variable. 1 myStack.push(0);
2 myStack.push(1);
3 myStack.push(2);
4 myStack.pop(value);
5 myStack.pop(value);
6 myStack.pop(value);
7 cout << value << endl;
Assume that the pop function, called on lines 4, 5, and 6, stores the number popped from the stack in the value variable. What will the statement on line 7 display?
A) 0
B) 1
C) 2
D) None of these
2 myStack.push(1);
3 myStack.push(2);
4 myStack.pop(value);
5 myStack.pop(value);
6 myStack.pop(value);
7 cout << value << endl;
Assume that the pop function, called on lines 4, 5, and 6, stores the number popped from the stack in the value variable. What will the statement on line 7 display?
A) 0
B) 1
C) 2
D) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
27
In a dequeue operation, the element at the __________ of the queue is removed.
A) middle
B) front
C) declaration
D) rear
E) None of these
A) middle
B) front
C) declaration
D) rear
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
28
Queues that are implemented as arrays are called __________ queues.
A) dynamic
B) stack
C) static
D) deque
E) None of these
A) dynamic
B) stack
C) static
D) deque
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
29
If data is transmitted faster than it can be processed, it can be held in a __________ for processing.
A) stack
B) queue
C) static array
D) static deque
E) None of these
A) stack
B) queue
C) static array
D) static deque
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
30
A queue is a data structure that stores and retrieves item in the __________ manner.
A) last in, first out
B) first in, last out
C) first in, first out
D) random
E) None of these
A) last in, first out
B) first in, last out
C) first in, first out
D) random
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
31
The __________ operation allows an item to be removed from the stack.
A) push
B) pop
C) delete
D) remove
E) None of these
A) push
B) pop
C) delete
D) remove
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
32
When an element is added to a queue, it is added to the rear. When an element is removed from the queue, it is removed from the
A) rear
B) middle
C) front
D) depends on how the programmer writes the code
E) None of these
A) rear
B) middle
C) front
D) depends on how the programmer writes the code
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
33
A stack queue can be implemented as a
A) circular array
B) stack
C) dynamic linked list
D) dynamic vector
E) None of these
A) circular array
B) stack
C) dynamic linked list
D) dynamic vector
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
34
A __________ is processed in a manner similar to customers standing in a grocery store check-out line where the first customer in line is the first to be served.
A) stack
B) vector
C) queue
D) All of these
E) None of these
A) stack
B) vector
C) queue
D) All of these
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
35
Static stacks have a __________ size and are implemented as __________.
A) fixed, linked lists
B) variable, arrays
C) fixed, arrays
D) variable, linked lists
E) None of these
A) fixed, linked lists
B) variable, arrays
C) fixed, arrays
D) variable, linked lists
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
36
A container that provides quick access to elements at the front and the back of the list is a
A) stack
B) queue
C) deque
D) All of these
E) None of these
A) stack
B) queue
C) deque
D) All of these
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
37
Given the following code, assume the myStack object is a stack that can hold integers and that value is an int variable. 1 myStack.push(0);
2 myStack.push(1);
3 myStack.push(2);
4 myStack.pop(value);
5 myStack.push(3);
6 myStack.pop(value);
7 cout << value << endl;
Assume that the pop function, called on lines 4 and 6, stores the number popped from the stack in the value variable. What will the statement on line 7 display?
A) 0
B) 1
C) 2
D) 3
E) None of these
2 myStack.push(1);
3 myStack.push(2);
4 myStack.pop(value);
5 myStack.push(3);
6 myStack.pop(value);
7 cout << value << endl;
Assume that the pop function, called on lines 4 and 6, stores the number popped from the stack in the value variable. What will the statement on line 7 display?
A) 0
B) 1
C) 2
D) 3
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
38
A dynamic queue can be implemented as a
A) dynamic linked list
B) fixed-length array
C) fixed-length circular array
D) All of these
E) None of these
A) dynamic linked list
B) fixed-length array
C) fixed-length circular array
D) All of these
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
39
A stack can be adapted to store __________ data types.
A) all
B) only built-in C++
C) only abstract
D) deque-like
E) None of these
A) all
B) only built-in C++
C) only abstract
D) deque-like
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following is a double-ended queue?
A) two-headed stack
B) two-tailed vector
C) circular array
D) deque
E) None of these
A) two-headed stack
B) two-tailed vector
C) circular array
D) deque
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
41
Given the following code, assume the myQueue object is a queue that can hold integers and that value is an int variable. 1 myQueue.enqueue(0);
2 myQueue.enqueue(1);
3 myQueue.enqueue(2);
4 myQueue.dequeue(value);
5 myQueue.dequeue(value);
6 myQueue.dequeue(value);
7 cout << value << endl;
Assume that the dequeue function, called on lines 4, 5, and 6, stores the number removed from the queue in the value variable. What will the statement on line 7 display?
A) 0
B) 1
C) 2
D) None of these
2 myQueue.enqueue(1);
3 myQueue.enqueue(2);
4 myQueue.dequeue(value);
5 myQueue.dequeue(value);
6 myQueue.dequeue(value);
7 cout << value << endl;
Assume that the dequeue function, called on lines 4, 5, and 6, stores the number removed from the queue in the value variable. What will the statement on line 7 display?
A) 0
B) 1
C) 2
D) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
42
Select all that apply. The queue data structure is commonly applied in connection with
A) managing the order of print jobs
B) communications software
C) operating systems
D) None of these
A) managing the order of print jobs
B) communications software
C) operating systems
D) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
43
Select all that apply. A practical application of the stack data type in a computer system is
A) storage of local variables
B) tracking nested loops
C) tracking nested function calls
D) None of these
A) storage of local variables
B) tracking nested loops
C) tracking nested function calls
D) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
44
Given the following code, assume the myQueue object is a queue that can hold integers and that value is an int variable. 1 myQueue.enqueue(0);
2 myQueue.enqueue(1);
3 myQueue.enqueue(2);
4 myQueue.dequeue(value);
5 cout << value << endl;
Assume that the dequeue function, called on line 4, stores the number removed from the queue in the value variable. What will the statement on line 5 display?
A) 0
B) 1
C) 2
D) None of these
2 myQueue.enqueue(1);
3 myQueue.enqueue(2);
4 myQueue.dequeue(value);
5 cout << value << endl;
Assume that the dequeue function, called on line 4, stores the number removed from the queue in the value variable. What will the statement on line 5 display?
A) 0
B) 1
C) 2
D) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
45
Given the following code, assume the myQueue object is a queue that can hold integers and that value is an int variable. 1 myQueue.enqueue(0);
2 myQueue.enqueue(1);
3 myQueue.enqueue(2);
4 myQueue.dequeue(value);
5 myQueue.enqueue(3);
6 myQueue.dequeue(value);
7 cout << value << endl;
Assume that the dequeue function, called on lines 4 and 6, stores the number removed from the queue in the value variable. What will the statement on line 7 display?
A) 0
B) 1
C) 2
D) 3
E) None of these
2 myQueue.enqueue(1);
3 myQueue.enqueue(2);
4 myQueue.dequeue(value);
5 myQueue.enqueue(3);
6 myQueue.dequeue(value);
7 cout << value << endl;
Assume that the dequeue function, called on lines 4 and 6, stores the number removed from the queue in the value variable. What will the statement on line 7 display?
A) 0
B) 1
C) 2
D) 3
E) None of these
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
46
Select all that apply. The Standard Template Library offers a stack template that may be implemented as a(n)
A) vector
B) primary type
C) linked list
D) deque
A) vector
B) primary type
C) linked list
D) deque
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck
47
Select all that apply. Data structures that can dynamically store elements and can grow and shrink in size are
A) stacks
B) arrays
C) queues
D) deques
A) stacks
B) arrays
C) queues
D) deques
Unlock Deck
Unlock for access to all 47 flashcards in this deck.
Unlock Deck
k this deck