Thread: help with sorting program

  1. #1
    Registered User
    Join Date
    Jan 2008

    help with sorting program

    i need to write a program that will generate 50000 random number from 1-10000 and then sort them using three different functions. Bubble Sort, Insertion Sort, and Selective Sort

    here is the code i have right now. i pretty much have the foundation layed out .. i think at least. i just need to tweak it to get it to work properly

    #include <iostream>
    #include <ctime>
    using namespace std;
    void bubblesort (int temp, int size);
    int main (){
    const int size = 50000;
    int temp[size];
    for(int i =0; i<size; i++){
    cout << temp[i] << endl;
    bubblesort (temp, size);
    cout << temp[i];
    return 0;
    void bubblesort (int a[], int n) {
       for (int i=1; i<n; i++)
          for (int j=0; j<n-1; j++)
             if (a[j]>a[j+1]);
    void insertionsort (double list[], int arraysize){
        for (int i=1; i<array size; i++) {
            double currentelement = list[i];
            int k;
            for (k=i - 1; k>=0 && list[k]> currentelement; k--){
            list [k + 1] = currentelement;
    void selectionsort(int list[], int arraysize){
        for(int i=0; i<arraysize; i++){
            int min=list[i], index=i;
            for(int j =i; j<arraysize; j++){
            swap(&list[i], &list[index];

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    How does it not work? Or are you just looking for improvement suggestions for code that works?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    if (a[j]>a[j+1]);
    Take a closer look of what this statement do... or does not do...

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    Jan 2008
    well the code doens't work, and i figured that all of my funcitons weren't fully correctly written. also i don't know how to implement them into my program to have them run

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM