Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

noob c++

Name: Anonymous 2010-10-05 20:41

/g/ doesn't like beginners ;_;

what is the purpose of the for-loop in this program?
i had to make a program to order a couple numbers, and it works, but i'm not sure why the purpose the for-loop has (i know what a for loop is, just not why i need it here)

http://pastebin.com/8Aarr5Ni

Name: Anonymous 2010-10-05 21:26

Lets talk about whats wrong with this program.
First, don't use the sepples sort function, write your own nlog(n) sort function. eg.

void QSort(int  *arr, int l, int r)
{
      int i = l, j = r;
      int holder;
      int pt = arr[(l + r) / 2];
      while (i <= j) {
            while (arr[i] < pt)
                  i++;
            while (arr[j] > pt)
                  j--;
            if (i <= j) {
                  holder = arr[i];
                  arr[i] = arr[j];
                  arr[j] = holder;
                  i++;
                  j--;
            }
      };
 
      if (left < j)
            quickSort(arr, l, j);
      if (i < right)
            quickSort(arr, i, r);
}

Second, don't use the windows library unless you are going to be creating a GUI for windows.

Third, store the loop counter in the register, or even better don't use a loop at all if you are only printing 3 values to the console.

Finally, never use system.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List