Friday, July 31, 2009

C++ program to accept 10 numbers from the user and print in ascending order?

c++ program to accept 10 numbers from the user and print in ascending order

C++ program to accept 10 numbers from the user and print in ascending order?
instead of bubble sort you can use the already available quick sort function which is even more efficient and faster than bubble sort.Wont make much of difference for 10 munbers but yet worth a try on the lib function.Dont re-invent the wheel ;)
Reply:use this function just pass array of 10 nos %26amp; n=10





void bubbleSort1(int x[], int n) {


for (int pass=1; pass %26lt; n; pass++) { // count how many times


// This next loop becomes shorter and shorter


for (int i=0; i %26lt; n-pass; i++) {


if (x[i] %26gt; x[i+1]) {


// exchange elements


int temp = x[i]; x[i] = x[i+1]; x[i+1] = temp;


}


}


}


}

flowers on line

No comments:

Post a Comment