← Back to Data Structures & Algorithms
Question 434
Build the Array Stack Core
Build the Array Stack Core
The two fields are declared but nothing sets them up, so a new stack is unusable. The givenisEmpty(),isFull()andtoString()show exactly how items and top are meant to behave - read them and make the rest agree. Requirements: 1. In the constructor, give items room for MAX_SIZE values and set top to the value that means empty. 2. Writepush(int)returning false when full and true otherwise,pop()andpeek()returning -1 when empty, andsize()returning how many values are stored. Do NOT write a main method.
Expected Output:
true 0 true true true Stack: 10 20 30 30 30 Stack: 10 20 2
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Data Structures & AlgorithmsStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.