Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global IntNode head
- // Correct solution
- public void reverse() {
- if (head == null)
- return;
- head = reverseOrder(head);
- }
- static IntNode reverseOrder(IntNode start) {
- IntNode nextNode = start.getLink();
- if (nextNode == null)
- return start;
- IntNode newHead = reverseOrder(nextNode);
- nextNode.setLink(start);
- start.setLink(null);
- return newHead;
- }
- // incorrect solution
- public void reverse() {
- if (head == null)
- return;
- IntNode tail = reverseOrder(head);
- tail.setLink(null);
- }
- IntNode reverseOrder(IntNode start) {
- if (start.getLink() != null) {
- IntNode newHead = reverseOrder(start.getLink());
- newHead.setLink(start);
- return start;
- }
- System.out.println("e");
- head = start;
- return start;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement