HW-4

.docx

School

The City College of New York, CUNY *

*We aren’t endorsed by this school

Course

103

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

4

Uploaded by BaronPuppyPerson1126

Report
HW-4 “Linked Lists”, “Stacks and Queues”, “Recursion” 1. Suppose cursor points to a node in a linked list (using the node definition with member functions called data and link). What statement changes cursor so that it points to the next node? A. cursor++; B. cursor = link( ); C. cursor += link( ); D . cursor = cursor->link( ); 2. Suppose that f is a function with a prototype like this: void f(________ head_ptr); // Precondition: head_ptr is a head pointer for a linked list. // Postcondition: The function f has done some manipulation of // the linked list, and the list might now have a new head node. What is the best data type for head_ptr in this function? A. node B. node& C . node*& D. node* 3. We need an expression that will give a random integer between -10 and 10. Select one. A. ( rand() % 20) – 11; // [-11, 8] B. ( rand() % 21) – 11; // [-11, 9] C. ( rand() % 10) – 10; // [-10, -1] D. ( rand() % 10) – 21; // [-21, -12] E . ( rand() % 21) – 10; // (rand() % n) + k; returns in range [k, k+(n-1)]; => [-10, 10] 4. Which of the following stack operations could result in stack underflow? A. is_empty B . pop C. push D. Two or more of the above answers 5. Consider the following pseudocode: declare a stack of characters while ( there are more characters in the word to read ) { read a character push the character on the stack } while ( the stack is not empty ) { write the stack's top character to the screen pop a character off the stack } What is written to the screen for the input "hamburger"? A. ham
B. hamburger C . regrubmah D. hhaammbbuurrggeerr 6. In the linked list implementation of the stack class, where does the push member function place the new entry on the linked list? A . At the head B. At the tail C. After all other entries that are greater than the new entry. D. After all other entries that are smaller than the new entry. 7. One difference between a queue and a stack is: A. Queues require dynamic memory, but stacks do not. B. Stacks require dynamic memory, but queues do not. C . Queues use two ends of the structure; stacks use only one. D. Stacks use two ends of the structure, queues use only one. 8. If the characters 'H', 'G', 'F', 'E' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed? A. EFGH B. EFHG C. FEGH D . HGFE 9. Suppose we have a circular array implementation of the queue class, with ten items in the queue stored at data[2] through data[11] (including). The CAPACITY is 42. Where does the push member function place the new entry in the array? A. data[11] B . data[12] C. data[1] D. data[2] 10. What is the maximum depth of recursive calls a function may make? A. 1 B. 2 C. n (where n is the argument) D . There is no fixed maximum
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help