Random Sort

This is a discussion on Random Sort within the C++ Programming forums, part of the General Programming Boards category; I have this program that generates random numbers which works but now I need to add a program that will ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    7

    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?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    > #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.

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21