Reverses the passed list without creating a new list by prepending front nodes to the end.
(head *ListNode)
| 32 | // Reverses the passed list without creating a new list by |
| 33 | // prepending front nodes to the end. |
| 34 | func reverseList1(head *ListNode) *ListNode { |
| 35 | if head == nil { |
| 36 | return nil |
| 37 | } |
| 38 | |
| 39 | // find the end of the list |
| 40 | end := head |
| 41 | for end.Next != nil { |
| 42 | end = end.Next |
| 43 | } |
| 44 | |
| 45 | // prepend every front node to the end |
| 46 | // 1,2,3 |
| 47 | // 2,3,1 |
| 48 | // 3,2,1 |
| 49 | for end != head { |
| 50 | hold := head |
| 51 | head = head.Next |
| 52 | hold.Next = end.Next |
| 53 | end.Next = hold |
| 54 | } |
| 55 | |
| 56 | return head |
| 57 | } |
nothing calls this directly
no outgoing calls
no test coverage detected