Thread: Random Sort

  1. #1
    Registered User
    Join Date
    Jun 2002

    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])

    Why will it not work?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > #include "iostream.h"
    This should be in <>
    #include <iostream.h>
    #include <iostream>

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

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

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  2. Random number + guessing game trouble
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-08-2007, 03:33 AM
  3. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  4. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  5. Help with Bi-Directional Bubble Sort in C
    By cunninglinguist in forum C Programming
    Replies: 0
    Last Post: 04-19-2002, 02:32 PM