PDA

View Full Version : Insertion sort C++ help


Nblufire12
01-20-2009, 01:12 AM
hey guys,

I need to sort an array in ascending order in C++ AS the user inputs the numbers in main,

for example, in main

for (int a=0;a<10;a++) {

cout<<"Enter a Number: " << endl;
cin >> numEntered;
insertArray(array, numEntered, a);
}

can you guys gimme some examples to sort the array AS the user inputs the number after the next number?

oracleguy
01-20-2009, 02:03 AM
You would just scan the array comparing the data at the current index and the next index with the new data to find where it goes in the array. Then just insert the data at that location. So you would want to use a for loop.