PROGRAMMING:Jmu-java-05 set-01-arraylistintegerstack
Define the 'integerstack' interface, which describes a common method to store the stack of integers
```java
public Integer push(Integer item); // If the item is null, null will be returned without stack. Otherwise, it will be directly put on the stack and return the item.
public Integer pop(); // If the stack is empty, null is returned.
public Integer peek(); // Get the top of stack element, if the top of stack is empty, return null. Note: don't leave the stack
public boolean empty(); // If the stack is empty, return true
public int size(); // Returns the number of elements in the stack
```
Define the implementation class' arraylistintegerstack 'of integerstack, and use ArrayList storage internally. This class contains:
**Constructor:**
Create a new ArrayList or LinkedList in the nonparametric constructor as the internal storage of the stack.
**Thinking: * * query JDK documents and try to explain which list implementation class is the best.
**Methods:**
`Public string tostring() '/ / used to output the contents of a list. You can directly call the tostring() method of the list. You can use ` system. Out. Println (list)'To output.
**Tips:**
1. The top pointer is not recommended. It is better to reuse the existing methods in the list implementation class directly.
2. When pop, the corresponding elements should be removed from the list.
###Main method description
1. Create an 'arrayintegerstack' object
2. Input m values and put them on the stack. The result of stack entry is printed every time.
3. Output:'top of stack element, whether the output is empty, and then output size '
4. Output all the elements in the stack (call its tostring() method)
5. Input 'x', and then print out the stack 'x' times, and print out the stack object each time.
6. Output:'top of stack element, whether the output is empty, output size '. Note: the top element of the output stack is only output but not output.
7. Output all the elements in the stack (call its tostring() method). Note: return 'null' and output it as well.
###Thinking:
If LinkedList is used to implement integerstack, how to implement it? What changes need to be made to the test code?
###Input sample
```in
five
1 3 5 7 -1
two
```
###Output sample
```out
one
three
five
seven
-1
-1,false,5
[1, 3, 5, 7, -1]
-1
seven
5,false,3
[1, 3, 5]
```
answer:If there is no answer, please comment
```java
public Integer push(Integer item); // If the item is null, null will be returned without stack. Otherwise, it will be directly put on the stack and return the item.
public Integer pop(); // If the stack is empty, null is returned.
public Integer peek(); // Get the top of stack element, if the top of stack is empty, return null. Note: don't leave the stack
public boolean empty(); // If the stack is empty, return true
public int size(); // Returns the number of elements in the stack
```
Define the implementation class' arraylistintegerstack 'of integerstack, and use ArrayList storage internally. This class contains:
**Constructor:**
Create a new ArrayList or LinkedList in the nonparametric constructor as the internal storage of the stack.
**Thinking: * * query JDK documents and try to explain which list implementation class is the best.
**Methods:**
`Public string tostring() '/ / used to output the contents of a list. You can directly call the tostring() method of the list. You can use ` system. Out. Println (list)'To output.
**Tips:**
1. The top pointer is not recommended. It is better to reuse the existing methods in the list implementation class directly.
2. When pop, the corresponding elements should be removed from the list.
###Main method description
1. Create an 'arrayintegerstack' object
2. Input m values and put them on the stack. The result of stack entry is printed every time.
3. Output:'top of stack element, whether the output is empty, and then output size '
4. Output all the elements in the stack (call its tostring() method)
5. Input 'x', and then print out the stack 'x' times, and print out the stack object each time.
6. Output:'top of stack element, whether the output is empty, output size '. Note: the top element of the output stack is only output but not output.
7. Output all the elements in the stack (call its tostring() method). Note: return 'null' and output it as well.
###Thinking:
If LinkedList is used to implement integerstack, how to implement it? What changes need to be made to the test code?
###Input sample
```in
five
1 3 5 7 -1
two
```
###Output sample
```out
one
three
five
seven
-1
-1,false,5
[1, 3, 5, 7, -1]
-1
seven
5,false,3
[1, 3, 5]
```
answer:If there is no answer, please comment