Only outputs half of my code on linux

Hi everyone,

I'm new to using linux. For my college project I have to use three different sorts and I'm working on my bubblesort first. My code runs perfectly fine on codeblocks but when I compiled it on linux it only outputs the "unsorted data" and doesn't output anything for the "sorted data". Can anyone point to what I'm doing wrong? Thanks in advance!

My code:


#include <iostream>

using namespace std;

void bubble(int arr[], int n)
{
int swaps = 1;

while(swaps)
{
swaps = 0;
for (int i = 0; i < n - 1; i++)
{
if (arr[i] > arr[i+1])
{
swap(arr[i], arr[i+1]);
swaps = 1;
}
}
}
}

#if __INCLUDE_LEVEL__ < 1
int main()
{

int arr[] = {4, 3, 12, 54, 32, 10};
int n = 6;
cout << "Unsorted data: "<< endl;

for (int i = 0; i < n; i++)
cout << arr[i] << endl;
cout << endl;

bubble(arr[], n); // This is the part that doesn't show any output on Linux

cout << "Sorted data: " << endl;
for (int i = 0; i < n; i++)
cout << arr[i] << endl;

return 0;
}
#endif
Last edited on
What's the point of your use of the language extension __INCLUDE_LEVEL__?

Once it is removed, your code is compliant.
On both G++ and Clang (where that macro is supported), the program produces the expected output anyways:
http://coliru.stacked-crooked.com/a/68df14f01cb8d207
On VC++, commenting the #if yields the expected output:
http://rextester.com/TAE97153
Thanks for the reply mbozzi. I guess there must be something wrong with my putty because it doesn't compile the expected output.

As for the extension, this bubble sort is only a part of my project and I have to make two other sorts and then add them as a header to a main function and use all three of the sorts there. We were asked to create a test main to try out our sorts before we add them to the final main function, so in order to avoid all 4 main function our teacher asked us to include that extension before the test main functions.
Sorting was my first project in high school, so long ago that 1000 items took a significant amount of time with the N*N sorts. I really liked shell sort; it has an interesting O() complexity and does a lot with a fairly simple and short piece of code.
Topic archived. No new replies allowed.