vicuna-33b· LMSYS
Arena Human Preference 55K
Write me a bubble sort function in Powershell
- User
Write me a bubble sort function in Powershell
- Assistant
Sure! Here's a simple bubble sort function in PowerShell:
function Sort-Bubble { param ( [Parameter(Mandatory=$true)] [array]$Array ) $swapped = $true while ($swapped) { $swapped = $false for ($i = 0; $i -lt $Array.Length - 1; $i++) { if ($Array[$i] > $Array[$i + 1]) { swapped $temp = $Array[$i] $Array[$i] = $Array[$i + 1] $Array[$i + 1] = $temp $swapped = $true } } } return $Array }This function takes an input array and sorts it using the bubble sort algorithm. It iterates through the array, comparing each pair of adjacent elements. If the elements are in the wrong order (i.e., the first element is greater than the second element), the function swaps their positions and sets the variable to . The process is repeated until no more swaps are needed, indicating the array is now sorted. The sorted array is then returned by the function.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.