Simple bubblesort algorithm in C++
Vector vs raw array

When dealing with arrays that have a length know at run-time, you usually use an std::vector, it is cleaner and safer w.r.t the memory allocation (for dynamicity). When the size of the array is known at compile-time, consider using an std::array, which is the C++ way of using raw arrays.

In this case, I'd use an std::vector and a .reserve(length) call

Array out of bound

Here is a concrete argument to why you should use a vector: you are actually writing/reading outside of you array, which can fail immediately (if you are lucky), or can fail way later in your code (if you're unlucky).

int count = -1;
while(count++&lt;length)
{
    unsorted[count] = rand()%max;
}


if you have length == 1 for example, here is what will happen, 'unwrapping' the while:

int count = -1;
if (count++ &lt; 1) // count == -1, so count &lt; 1 is true ; after that we increment count by 1, so count == 0 
{
    // accessint unsorted[0]
    unsorted[count] = rand()%max;
}
if (count++ &lt; 1) // count == 0, so count &lt; 1 is true ; after that we increment count by 1, so count == 1 
{
    // accessint unsorted[1], which is outside of the array
    unsorted[count] = rand()%max;
}
// after that, the condition is false


For loops vs while loops

Twice in your code, you have a while loop looking like this one:

int count = -1;
while(count++&lt;length)


When you iterate this way, you usually see a for loop instead:

for(unsigned int count = 0 ; count &lt; length ; ++count)


which does (almost) the same thing, but is more readable.

Note that the starting value is 0, leading into one less iteration than previously. However, it is actually the last iteration that is removed

Pass

In your main loop, you are using your pass macro. As jvb mentioned, you usually want to avoid to use macros (as the faq iso cpp says). Moreover, in this particular case, you may consider two alternatives:


Using the continue keyword
Reverting your condition


In this case, the second alternative is way better, as it is easy to put into place (the keyword continue shouldn't be used unless other alternatives are awkward).

if(adjacent_value &gt; current_value) { continue; }
else if(current_value &gt; adjacent_value) {
    // ...
}


would become

if(adjacent_value &lt; current_value) {
    // ...
}


because you are really doing something only if the above condition is fulfilled

Swapping values

To swap your values, you are using your custom code

int tmp = adjacent_value;
unsorted[i+1] = current_value;
unsorted[i] = tmp; 


which works well.

However, you may consider using the function std::swap, that swaps two values:

std::swap(unsorted[i], unsorted[i+1]);