For one thing, your swap variable is always true, it's initialized to true, and nothing in your code ever makes it false, so the way you use it as a loop control variable means that you're going to get an infinite loop.
Also, even though you pass the length of the array to the sort function you never actually use it. length should be the loop control variable, the swap variable isn't necessary.
Finally, a bubble sort requires a nested pair of loops, in other words a loop inside a loop. It should look something like this:
-
void BubbleSort(int arr[], int length)
-
{
-
for(int i = 0; i < length; i++)
-
{
-
for(int j = i; j < length; j++)
-
{
-
if(arr[j] > arr[i])
-
{
-
int temp = arr[i];
-
arr[i] = arr[j];
-
arr[j] = temp;
-
}
-
}
-
}
-
}
-
The outer loop keeps track of how much of the list is sorted (in other words i is the index of the first unsorted element). The inner loop passes over the unsorted part of the list looking for the largest element in the unsorted part of the list and swaps it to the front of the unsorted portion. Once the inner loop finishes, the first element of the unsorted portion is now sorted and the outer loop moves ahead to the next unsorted element and repeats the process.