Hi. I want to solve this problem using a Stack and a LinkedList (I know it can be solved with a different approach) and I've debugged my code using Eclipse. The error I get is when the input is {1,2,3} and should return {1,3,2} -- it says my algorithm returns {1,2,3} instead.

The main idea of my algorithm is to use these data structures' methods to easily retrieve the data I store in them in the order requested. I use a double length so I can use Math.ceil() to store the data in the correct order. If length is 3, Math.ceil(3/2) = 2, thus, it stores 1 and 2 in the LinkedList and 3 in the stack.

If the length > 0, the first element would be from the LinkedList, therefor, the last part of the algorithm selects an item from the stack (if not empty) and then from the list (if not empty). This seems correct when debugged in my developing environment, but not in when submitted.

I would appreciate some feedback and comments.

Cheers.

```
import java.util.*;
public class Solution {
public void reorderList(ListNode head) {
Stack<Integer> S = new Stack<Integer>();
LinkedList<Integer> L = new LinkedList<Integer>();
double length = 0;
boolean empty = true;
ListNode temp = head;
while(temp!=null) {
length++;
temp = temp.next;
}
if(length>0) empty = false;
temp = head;
if(!empty) {
for(int i=0; i < (int) Math.ceil(length/2); i++) {
L.addLast(temp.val);
temp = temp.next;
}
for(int i= (int) Math.ceil(length/2); i < length; i++) {
S.push(temp.val);
temp = temp.next;
}
}
if(length>0) {
head = new ListNode(L.removeFirst());
length--;
}
temp = head;
while(length > 0) {
if(!S.empty()) {
temp.next = new ListNode(S.pop());
length--;
temp = temp.next;
if(!L.isEmpty()) {
temp.next = new ListNode(L.remove());
length--;
temp = temp.next;
}
}
else if(!L.isEmpty()) {
temp.next = new ListNode(L.remove());
length--;
temp = temp.next;
if(!S.empty()) {
temp.next = new ListNode(S.pop());
length--;
temp = temp.next;
}
}
}
}
}
```