Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   learning alogrithms (http://www.go4expert.com/forums/learning-alogrithms-t23381/)

 compscichick 22Sep2010 07:01

learning alogrithms

So the problem is to illustrate how the selection sort algorithm behaves on two inputs:
A={1,2,3,4,5} and A={5,4,3,2,1}. I need to state the output generated and then write a function for Big Oh notation.

The algorithm is:
Code:

```#include <iostream> using namespace std; void printout (int A [], int n) {     for (int i=0; i<n; ++i)         cout << A[i] << " ";     cout<< '\n'; } void selectionSort (int A[], int n) {     for (int k=0; k<n-1; ++k) {         int tmp, index = k;         for (int i=k+1; i < n; ++i)             if (A[i] < A[index]) index=i;         tmp= A[k]; // swap         A[k] = A[index];         A [index] = tmp;         printout (A,n);     } } int main () {     system("pause");     return 0; }```
I thought i would need to insert a 5 in int A[5] for there being 5 vectors slots. I can get it to run and compile, but then nothing is outputted. What am I doing wrong?

 jimblumberg 24Sep2010 19:17

Re: learning alogrithms

In
Code:

```int main () {     system("pause");     return 0; }```
You are not doing anything but pausing. Maybe you need to set up variables, call a function or two?

Jim

 All times are GMT +5.5. The time now is 00:31.