Int top 1 note top 1 indicates stack is empty a

This preview shows page 7 - 8 out of 8 pages.

      int top = -1;      //Note  top == -1 indicates stack is empty a method that implements a void push(String x) operation can be written as a . if (top == s.length-1)       throw new  RuntimeException("Overflow"); top ++; s[top] = x; The stack empty operation a. removes all elements from the stack b.checks to see if there is at least one item on the stack c. destroys the stack and creates a new empty one in its place d.None of the above
Image of page 7

Subscribe to view the full document.

In the implementations of the Stack operation presented in this chapter, what does the memory cell top store,  the index of the arraywhere the nextPush or the nextPop will be performed?  a. the location of the next node b.the location of the previous node c. the location of the middle node d.the location of the first node Evaluate the following arithmetic expressions written in postfixed notation: 45 3 21 + - 10 * 210 Consider a class that uses the following variables to implement an array-based stack: String [ ] s = new String[100]; int top = 0; The boolean method to check for an empty stack can be written as: If top == 0 return true else return false
Image of page 8
You've reached the end of this preview.
  • Spring '16
  • Following, Christopher Nolan

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern