I got it figured out guys. Thanks for not handing me an answer, but pointing me in the right direction. I sat down and really thought about the logic involved in the problem and had quite a few "duh" moments. It seems to be working properly now. I'll post the source code and you guys can pick it apart and tell me how to make it better.
Code:
#include <stdlib.h>
#include <stdio.h>
int bubble_Sort(int sort_Array[], int array_Size);
void output_Array(int a[], int array_Size);
int main()
{
printf ("This program will ask the user to pick a size for an array. It will then\n");
printf ("auto-populate the array with numbers between 0-50. Finally it will sort the\n");
printf ("array in increasing order and state the number of passes the sorting algorithm\n");
printf ("took.\n");
printf ("\n");
printf ("To manually input array numbers simply uncomment lines 30 & 31 and\n");
printf ("comment line 32 of the source code.\n");
printf ("\n");
system ("pause");
system ("cls");
int i=0;
int n;
printf ("Input the size of the array: ");
scanf ("%d", &n); //user defines size of array
int a[n];
while (i<n)
{
//printf ("Input value for a[%d]: ", i);
//scanf ("%d", &a[i]); // user inputs n variables
a[i]=rand()%50; //auto-populates array for ease of program use
i++;
}
printf ("\n");
printf ("\n");
system("pause");
system ("cls");
printf ("User input array: ");
output_Array(a, n); //outputs unsorted list
bubble_Sort(a, n); //sorts the array
printf ("\n");
printf ("\n");
system("pause");
return 0;
}
int bubble_Sort(int sort_Array[], int array_Size)
{
bool swap_Flag = true;
int pass = 0;
while (pass<array_Size && swap_Flag)
{
printf ("\n");
if (pass > 0 )
{
printf ("Pass number %d rendered ", pass);
for (int i=0;i<array_Size;i++)
{
printf ("|%d| ", sort_Array[i]);
}
}
swap_Flag = false;
pass++;
for (int i=0;i<array_Size-pass;i++)
{
if (sort_Array[i] > sort_Array[i + 1])
{
int temp = sort_Array[i];
sort_Array[i] = sort_Array[i + 1];
sort_Array[i + 1] = temp;
swap_Flag = true;
}
}
}
if (pass-1==0)
{
printf ("The array is already sorted!");
}
else
{
printf ("\n");
printf ("\n");
system ("pause");
system ("cls");
printf ("Sorted array: ");
output_Array(sort_Array, array_Size);
printf ("\n");
printf ("\nTotal passes: %d", pass-1);
}
}
void output_Array(int array[], int array_Size) //function outputs the unsorted and sorted array
{
for (int i=0;i<array_Size;i++)
{
printf ("|%d| ", array[i]);
}
}
All that's left to do is comment it...hopefully. Thanks again everyone.