Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 18 Starting out with C++ Stacks and Queues


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


 

Chapter Eighteen

MULTIPLE CHOICE

1. 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

2. 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

3. The _______ operation allows an item to be stored on a stack.
a. append
b. add
c. pop
d. push
e. None of these

4. The Standard Template Library offers a stack template that may be implemented as a:
a. vector
b. deque
c. linked list
d. All of these
e. None of these

5. The following statement

stack< int, vector > iStack;

indicates:
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

6. The queue data structure is commonly applied in connection with:
a. managing the order of print jobs
b. communications software
c. operating systems
d. All of these
e. None of these

7. 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

8. A static queue can be implemented as a(n) ___________.
a. circular array
b. stack
c. dynamic linked list
d. dynamic vector
e. None of these

9. This is a double-ended queue.
a. two-headed stack
b. two-tailed vector
c. circular array
d. deque
e. None of these

10. A __________ stack or queue is built around the linked-list.
a. dynamic
b. static
c. deque-based
d. floating point
e. None of these

11. This is a container that provides quick access to elements at the front and the back of the list.
a. stack
b. queue
c. deque
d. All of these
e. None of these

12. ___________ queues are more intuitive and easier to understand than ______ queues.
a. Static, dynamic
b. Dynamic, static
c. Deque-like, stack-like
d. Stack-like, deque-like
e. None of these

13. Data structures that can dynamically store elements and can grow and shrink in size are:
a. stacks
b. queues
c. deques
d. All of these
e. None of these

14. 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

15. 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

16. A stack has two primary operations:
a. push and pull
b. push and pop
c. insert and delete
d. append and delete
e. None of these

17. The ___________ operation allows an item to be removed from a stack.
a. push
b. pop
c. delete
d. remove
e. None of these

18. A dynamic stack may be implemented as a(n) ___________, and expand or shrink with each push or pop operation.
a. array
b. structure
c. linked list
d. a and b
e. None of these

19. A queue is a data structure that stores and retrieves items in this manner.
a. last in, first out
b. first in, first out
c. first in, last out
d. random
e. None of these

20. A __________ is processed in a manner similar to customers standing in a grocery check-out line — the first customer in line is the first served.
a. stack
b. vector
c. queue
d. All of these
e. None of these

21. When an element is added to a queue, it is added to the rear. When an element is removed, it is removed from the
a. rear
b. middle
c. front
d. All of these
e. None of these

22. In an dequeue operation, the element at the __________ of the queue is removed.
a. middle
b. front
c. declaration
d. mid-point
e. None of these

23. 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

24. Queues that are implemented as arrays are called ____________ queues.
a. dynamic
b. stack
c. static
d. deque
e. None of these

25. 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

26. A stack can be adapted to store _________ data types.
a. all
b. only the built-in C++
c. only abstract
d. deque-like
e. None of these

27. 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. All of these
e. None of these

28. In the following code, assume the myStack object is a stack that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.)

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 in line 4, stores the number popped from the stack in the value variable.

What will the statement in line 5 display?

a. 0 c. 2
b. 1 d. None of these

29. In the following code, assume the myStack object is a stack that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.)

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 in lines 4, 5, and 6, stores the number popped from the stack in the value variable.

What will the statement in line 7 display?

a. 0 c. 2
b. 1 d. None of these

30. In the following code, assume the myStack object is a stack that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.)

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 in lines 4 and 6, stores the number popped from the stack in the value variable.

What will the statement in line 7 display?

a. 0 d. 3
b. 1 e. None of these
c. 2

31. In the following code, assume the myQueue object is a queue that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.)

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 in line 4, stores the number removed from the queue in the value variable.

What will the statement in line 5 display?

a. 0 c. 2
b. 1 d. None of the above

32. In the following code, assume the myQueue object is a queue that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.)

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 in lines 4, 5, and 6, stores the number removed from the queue in the value variable.

What will the statement in line 7 display?

a. 0 c. 2
b. 1 d. None of these

 

33. In the following code, assume the myQueue object is a queue that can hold integers, and that value is an int variable. (The lines are numbered for reference purposes.)

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 in lines 4, and 6, stores the number removed from the queue in the value variable.

What will the statement in line 7 display?

a. 0 d. 3
b. 1 e. None of these
c. 2

 

TRUE/FALSE

1. True/False: The first item placed onto a stack is always the last item removed from the stack.

2. True/False: A dynamic stack starts as an empty linked list.

3. True/False: The pop function in the stack template of the STL does not retrieve the value from the top of the stack.

4. True/False: The STL provides containers for deque and queue.

5. True/False: The pop function in the stack template does not retrieve the value from the top of the stack. It merely removes it.

6. True/False: Endeque and deque are the two most common queue operations.

7. True/False: 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.

8. True/False: In a static stack class, the constructor function can dynamically allocate memory for the stack array.

9. True/False: Stacks and queues can be implemented as arrays or linked lists.

10. True/False: The programmer must declare in advance the size of a dynamic stack or queue.

11. True/False: A stack that is implemented as a linked list is known as a deque.

12. True/False: Push and pop are the two most common queue operations.

13. True/False: 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.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!