Java provides an inbuilt object type called Stack. It is a collection that is based on the last in first out (LIFO) principle. On Creation, a stack is empty. Try this problem using Stack.
Given n elements of a stack , delete the middle element of the stack without using any additional data structure.
Input: First line of input contains a single integer T which denotes the number of test cases. T test cases follows, first line of each test case contains a integer n. Second line consists of n spaced integers.
Output: Print the elements of the stack after deleting the middle element.
1<= n <=103
1 2 3 4 5
1 4 9 2 6 5
5 4 2 1
5 6 2 4 1
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.