Question

4. Given a stack variable stk which provides a push operation that places an integer o top of the stack, and a pop operation which removes and returns the integer from t top of the stack, what would the stack look like, after the following code executed? for(int k 1; k < 10; k++) if(k % 3 :0) stk.push( k+ stk.pop()); else stk.push( k); 25. Given a queue variable que which provides an add operation which places an integer at the back of the queue, and a get operation which removes and returns the integer from the front of the queue, what would the queue look like after the following code executed? for(int k = 1; k < 10; k++) :0) que.enqueue( k+ que.dequeue() ); if(k % 3 else que.enqueuel k);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

push( 1) sh) USわ(A k-373 トヤ2. 312 chCs) sh C5 015 epo s 413 0 pepo s41/2 Fnal Reseulh ヲ リ , 灸, k k

Add a comment
Know the answer?
Add Answer to:
4. Given a stack variable stk which provides a push operation that places an integer o...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Help asap 24. Given a stack variable stk which provides a push operation that places an...

    Help asap 24. Given a stack variable stk which provides a push operation that places an integer on he stack, and a pop operation which removes and returns the integer from t top of the stack, what would the stack look like, after the following code executed? top of t for(int k 1; k < 10; k++) if(k % 3 :0) stk.push( k+ stk.pop()); else stk.push( k);

  • 2. Stacks and Queues Reinernber: Consider the following function: void systery( int num) { int current:...

    2. Stacks and Queues Reinernber: Consider the following function: void systery( int num) { int current: /* create Stack stk and Queue que / Stacks: the function push places the given parameter on the top of the stack, the function pop removes and returns the top of the stack, and the function empty returns true (i.c., 1) if the stack is empty or false (i.e., 0) otherwise. Queues: the function insert places the given parameter on the end of the...

  • 1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show...

    1)Given a Stack implemented with a Linked List, and an O(1) implementation of push and pop,show the Linked List after the following commands are executed: Stack myStack = new Stack(); myStack.push(20); myStack.push(40); myStack.pop(); myStack.push(60); myStack.push(80); 2)If the same commands were used but the Stack was implemented with an Array with maximum size of 10, show what the array would look like after all these commands are executed. Assume O(1) implementation of push and pop here as well. 3)Given a Queue...

  • Suppose we decide to add a new operation to our Stack ADT called sizeIs, which returns...

    Suppose we decide to add a new operation to our Stack ADT called sizeIs, which returns a value of primitive type int equal to the number of items on the stack. The method signature for sizeIS is public int sizeIs() a.) Write the code for sizeIs for the ArrayStack class b.) Write the code for sizeIs for the LinkedStack class (do not add any instance variables to the class; each time sizeIs is called you must "walk" through the stack...

  • Which of the following terms is NOT associated with a stack? push top get bottom Flag...

    Which of the following terms is NOT associated with a stack? push top get bottom Flag this Question Question 21 pts Which of the following terms is NOT associated with a queue? add front FIFO enqueue pop Flag this Question Question 31 pts A stack exhibits what kind of behavior? Last In, First Out (LIFO) First In, First Out (FIFO) Last In, Last Out (LILO) Read-Only Write-Only Flag this Question Question 41 pts What are the final contents of myQueue...

  • I need to implement a stack array but the top of the stack has to be...

    I need to implement a stack array but the top of the stack has to be Initialize as the index of the last location in the array.    //Array implementation of stacks.    import java.util.Arrays;       public class ArrayStack implements Stack {        //Declare a class constant called DEFAULT_STACK_SIZE with the value 10.           private static final int DEFAULT_STACK_SIZE = 10;           /* Declare two instance variables:            1. An integer called...

  • Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the...

    Given a singly linked list contains 5 nodes, which simply shows as 5->4->3->2->1, what is the value that you can find in the second node of the remaining list if the following statements are applied? Assume head reference refers the first node of the list. Node prev = head; Node curr = head. next; while(curr.next!=null) { if(prev.element > 3) { prev = curr; curr = curr.next; } else break; } head = prev.next; Question 3 options: 3 2 4 1...

  • ) Consider Java's Stack class, and its five standard stack operations: push, pop, peek, isEmpty, and...

    ) Consider Java's Stack class, and its five standard stack operations: push, pop, peek, isEmpty, and clear. Complete the two unfinished methods. Do not modify any other parts of the class.               // Looks at the top two elements of the stack, and removes and returns the larger        // of the two elements from the stack, returning the other element to the stack.        // For example, if the stack, from the top, is 8 10 7 2...

  • template <class T> class Stack { public: /** clear * Method to clear out or empty any items on stack, * put stack back to empty state. * Postcondition: Stack is empty. */ virtual void clear() =...

    template <class T> class Stack { public: /** clear * Method to clear out or empty any items on stack, * put stack back to empty state. * Postcondition: Stack is empty. */ virtual void clear() = 0; /** isEmpty * Function to determine whether the stack is empty. Needed * because it is undefined to pop from empty stack. This * function will not change the state of the stack (const). * * @returns bool true if stack is...

  • Implement the stack queue data structure with a linked list implementation to get the given test...

    Implement the stack queue data structure with a linked list implementation to get the given test code in driver.cpp to work properly: driver.cpp code: #include <iostream> #include "stackLL.h" using namespace std; int main() { /////////////Test code for stack /////////////// stackLL stk; stk.push(5); stk.push(13); stk.push(7); stk.push(3); stk.push(2); stk.push(11); cout << "Popping: " << stk.pop() << endl; cout << "Popping: " << stk.pop() << endl; stk.push(17); stk.push(19); stk.push(23); while( ! stk.empty() ) { cout << "Popping: " << stk.pop() << endl; }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT