<s>[INST] # Given a linked list, sort it in ascending order using the bubble sort algorithm.

Here is a simple implementation of a linked list node:

```python
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None
```

Now here is a simple implementation of bubble sort for a linked list.

```python
class Solution:
    def sortList(self, head: ListNode) -> ListNode:
        if not head or not head.next:
            return head

        current = head
        swapped = True
        while swapped:
            swapped = False
            current = head
            while current and current.next:
                if current.val > current.next.val:
                    current.val, current.next.val = current.next.val, current.val
                    swapped = True
                current = current.next
        return head
```

Please review this implementation.

Here is a test case:

```python
# constructing the linked list: 4 -> 2 -> 1 -> 3
head = ListNode(4)
head.next = ListNode(2)
head.next.next = ListNode(1)
head.next.next.next = ListNode(3)

# appending the sorted linked list to the result
result = []
while head:
    result.append(head.val)
    head = head.next
print(result)
```

The final output is: `[1, 2, 4, 3]`. Which is not sorted.

Can you improve the code?[/INST]