Stack
7 questions · Fundamental Engineering
From the answer group below, select the correct answer to be inserted into blank in the description.
When the procedure proc1 is called, the output is “blank” in turn.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program. Here, the array index starts at 0.
The program implements a queue that has a fixed capacity and only accepts integers. If the queue is not full, the function enqueue appends the specified value to its end and returns true. Otherwise, it returns false. If the queue is not empty, the function dequeue removes an element from the queue and returns its value. Otherwise, it returns undefined. The figure illustrates the working of a queue with capacity to hold up to seven integers. Initially, the queue contains five integers, with front, rear, and count set to 3, 1, and 5, respectively. Then, enqueue( and dequeue( are called in that order.
enqueue( is called.
dequeue( is called.
Figure Queue with capacity of seven
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program. Here, the array index starts at 1.
Stack stores data using first-in, last-out ordering. Here, the items stored in the stack are integer values, and the stack is controlled by the procedure push and the function pop. The procedure push adds an item given as an argument to the top of the stack, and the function pop removes the top item from the stack and returns it. The global variable stck is an array of 10 integers that stores the stack items, and the global variable tos is the pointer that points to the topmost item of the stack.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A and B in the program. Here, the array index starts at 1.
The function reverse takes a string inputStr as a parameter and returns the reversed string. Here, the length of the string given to inputStr is 100 or less. In the program, areas outside of the arrays must not be referenced and the undefined value must not be appended to a string.
Answer group
From the answer group below, select the correct answer to be inserted into blank in the description.
This program performs operations on a priority queue.
A priority queue is a queue where the handled elements have a priority assigned to them, and the elements are extracted with the order of the highest priority first. The class PrioQueue represents a priority queue. The Figure shows an explanation of the class PrioQueue. Here, the priority is the integer value 1, 2, or 3, and the smaller the value the higher the priority.
When the procedure prioSched is called, the order of the output is blank.
Figure Explanation of the class PrioQueue
Answer group
From the answer group below, select the correct combination of answers to be inserted into A through C in the program. Here, the array index starts at 1.
The program implements a stack. The stack implementation only accepts positive integers. The function empty checks whether the stack is empty. The function full checks whether the stack is full. If the stack is not full, the function push pushes an element with a specified value onto the stack. If the stack is not empty, the function pop removes an element from the stack and returns its value. In the program, areas outside of the array must not be referenced.
Answer group
From the answer group below, select the correct combination of answers to be inserted into A through C in the program. Here, the array index starts at 1.
The function are_brackets_balanced checks for balanced brackets. It parses the given array of characters and when an opening bracket (“(”, “[”, “{”) is encountered, this is pushed onto the stack. When a closing bracket (“)”, “]”, “}”) is encountered, an element is popped from the stack and tested if it corresponds to the opening bracket. If the closing bracket matches its corresponding opening bracket, the process continues. Otherwise, it fails and the function returns false. After all characters have been processed, it returns false if any characters remain on the stack, otherwise it returns true. For simplicity, only brackets are considered as arguments to the function. The table shows examples of arguments provided to are_brackets_balanced and the return values.
Table Examples of arguments provided to the function are_brackets_balanced and the return values
The function are_brackets_balanced uses class Stack. The figure describes class Stack.
Figure Class Stack
Answer group