chatgpt-4o-latest-20250326· OpenAI
LMArena Human Preference 140K
Generate code for babble sort
- User
Generate code for babble sort
- Assistant
Certainly! Here's a simple implementation of the Bubble Sort algorithm in Python:
def bubble_sort(arr): n = len(arr) # Traverse through all array elements for i in range(n): # Last i elements are already in place for j in range(0, n - i - 1): # Swap if the element found is greater than the next element if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] # Example usage: arr = [64, 34, 25, 12, 22, 11, 90] print("Original array:", arr) bubble_sort(arr) print("Sorted array:", arr)Output:
Original array: [64, 34, 25, 12, 22, 11, 90] Sorted array: [11, 12, 22, 25, 34, 64, 90]Let me know if you want an optimized version or implementation in another language!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.