# array

Page 1 of 1

## 1 Replies - 1088 Views - Last Post: 03 April 2009 - 01:08 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=97144&amp;s=c925718423a7a26caded64867f514d83&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Prince of Darkness

Reputation: 0
• Posts: 4
• Joined: 20-March 09

# array

Posted 03 April 2009 - 01:00 PM

```void readarray(int arr[10], int &t)
{ cout<<"enter the size of the array"<<endl;
cin>>t;
for (int i=0;i<t;i++)
{cout<<"enter the element ";
cin>>arr[i];
}
}
void printarray (int arr[10], int t)
{ for (int i=0;i<t;i++){

cout<< arr[i]<<"	   ";
}
}

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int arr[10];
int t;
printarray(arr,t);

return 0;
}

```

This is functioning completely well, i just need to add a function to it, Or modify the read function, so i can arrange the array elements while entering them, So when the array elements are printed out on the screen, they are arranged.
For example. for an array that has the size of t = 6, i might enter ( 90, 3, -1, 34, 4, 6)
but they are printed out on the screen arranged like this ( -1, 3, 4, 6, 34, 90 )

This is what i came up with so far

``` void arrangearray(int arr[10], int t,)

{
int temp;
for (int j=1;j<t;j++)
{ for (int f=1;f<t;f++)
{ if (arr[j]>arr[f])

temp = arr[j];
arr[j] = arr[f];
arr[f] = temp;
}
}
}

```

This post has been edited by Prince of Darkness: 03 April 2009 - 01:04 PM

Is This A Good Question/Topic? 0

## Replies To: array

### #2 Darkhack

Reputation: 36
• Posts: 208
• Joined: 25-November 08

## Re: array

Posted 03 April 2009 - 01:08 PM

There are lots of different sorting algorithms. Quicksort is usually the fastest for large data sets. For smaller data sets there is also insertion sort, selection sort, and bubble sort. Most people tend to stick with quicksort since its faster for the others with large data sets and performance is usual equal to the others for smaller sets.

Quicksort Tutorial: http://www.dreaminco...wtopic57199.htm
Insertion Sort: http://www.dreaminco...wtopic57287.htm
Selection Sort: http://www.dreaminco...wtopic57966.htm
Bubble Sort: http://en.wikipedia....by-step_example