# Random Sort

• 06-14-2002
Trebor
Random Sort
I have this program that generates random numbers which works but now I need to add a program that will perform a buble sort and I can't get the two programs to be compatible.

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "iostream.h"

#define size 100

void main( void )
{
int i;
int numarray[size];

/* This portion of the program seeds the random-number generator
* with the time, then puts 100 random integers into numarray[].
* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 100 numbers. */
for( i = 0; i < size;i++ )
{
numarray[i]=rand(); /* the “rand()” is the function that random generates numbers. I have it set to do 100 for test purposes. Once I am sure my sort routines routines works, I will set it to something like 100,000. I got this code from the help library of the C++ application I am using.*/
cout << numarray[i] << "\t";
}
}

The above program works and here is what I am trying to add to do a bubble sort:

void bubble
{
int a;
int b;

for (a = 1; a < numarray[size]; a++)
for (b = numarray[size] - 1; b >= a; B--)
if (Vektor[b-1] > Vektor[b])
Swapnumbers9b-1,b);
}

Why will it not work?
:(
• 06-14-2002
Salem
> #include "iostream.h"
This should be in <>
Either
#include <iostream.h>
or
#include <iostream>

> void main( void )
main returns an int
See past posts, and the FAQ

> for (a = 1; a < numarray[size]; a++)
Perhaps
for (a = 1; a < size; a++)

Some research on how bubble sorts are implemented would be time well spent.