Question
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);
0 0
Add a comment Improve this question Transcribed image text
Answer #1

17
8
7
11
5
4
5 (step 3) --> as 3 is divisible by 3 there stk.pop() (is value of top of the stack which is 2) + k (it's 3) = 5
2 (step 2) --> push 2 which is not divisible by 3
1 (step 1) --> push 1 which is not divisible by 3

Add a comment
Know the answer?
Add Answer to:
Help asap 24. Given a stack variable stk which provides a push operation that places an...
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
  • 4. Given a stack variable stk which provides a push operation that places an integer o...

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

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

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

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

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

  • Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The...

    Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The application will be to add large numbers. Review adding large numbers Remember that we can use stacks to safely add integer values that overflow the int data type g. in Java, the maximum possible int value Integer.MAX_VALUE is: 2147483647 so any int addition larger than this will overflow and fail Using stacks to add large numbers safely Will actually represent the large integers to...

  • NO ONE HAS PROVIDED THE CORRECT CODE TO PROVIDE THE GIVEN OUTPUT. PLEASE PROVIDE CODE THAT...

    NO ONE HAS PROVIDED THE CORRECT CODE TO PROVIDE THE GIVEN OUTPUT. PLEASE PROVIDE CODE THAT WOULD CAUSE THE HW1.java TO PRINT THE RIGHT DATA.!!! The LinkedList class implements both the List interface and the Stack interface, but several methods (listed below) are missing bodies. Write the code so it works correctly. You should submit one file, LinkedList.java. Do not change the interfaces. Do not change the public method headers. Do not rename the LinkedList class. None of your methods...

  • Java - data structures Suppose that in the array-based stack, the array doubles in size after...

    Java - data structures Suppose that in the array-based stack, the array doubles in size after multiple push operations. But later on, fewer than half of the array’s locations might actually be used by the stack due to pop operations. Revise the implementation so that its array also can shrink in size as objects are removed from the stack. Accomplishing this task will require two new private methods, as follows: The first new method checks whether we should reduce the...

  • 8. Given: struct STACK INF RC 1301 int top that the following functions have already been...

    8. Given: struct STACK INF RC 1301 int top that the following functions have already been declared in a stack tolkit and are available for create stack(s) push(s, item) pop(s, item) topls, item) empty(s) Boolean function use some or all of them to write the complete definition code for a function that passes in a stack (as an argument), removes the SECOND assume that there are at least two items in the stack). item (from the top) in the stack,...

  • There is a data structure called a drop-out stack that behaves like a stack in every...

    There is a data structure called a drop-out stack that behaves like a stack in every respect except that if the stack size is n, then when the n+1element is pushed, the bottom element is lost. Implement a drop-out stack using links, by modifying the LinkedStack code. (size, n, is provided by the constructor. Request: Please create a separate driver class, in a different file, that tests on different types of entries and show result of the tests done on...

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