Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:sort

Posted by Marziyeh at 2009-03-16 16:40:04 on Problem 2388
In Reply To:Re:sort Posted by:azma at 2009-03-16 16:00:49
> #include<iostream>
> using namespace std;
> int n,i,a[9999];
> void selectionSort(int x[], int n) {
>     for (int pass=0; pass<n-1; pass++) {
>         int potentialSmallest = pass;  // assume this is smallest
> 
>         //--- Look over remaining elements to find smallest.
>         for (int i=pass+1; i<n; i++) {
>             if (x[i] < x[potentialSmallest]) {
>                 //--- Remember index for latter swap.
>                 potentialSmallest = i;
>             }
>         }
>         
>         //--- Swap smallest remaining element
>         int temp = x[pass];
>         x[pass] = x[potentialSmallest];
>         x[potentialSmallest] = temp;
>     }
> }
> 
> main(){
> 	cin>>n;
> 	for(i=n;i;)cin>>a[--i];
> 	selectionSort(a,n);
> 	cout<<a[n>>1];
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator