2388 who& #39; s in the middle (simple sort)

Source: Internet
Author: User

The first question of the training plan begins with the water problem: the sorted array, the middle number is output.

http://poj.org/problem?id=2388

Bubble Sort:

#include <iostream>using namespace Std;int main () {    int i, J, N,t;    int a[10000];    cin>>n;    for (i=0; i<n; i++)    {        cin>>a[i];    } Bubble sort for    (i=0; i<n-1; i++) for        (j=0; j<n-i-1; j + +)            if (a[j]<a[j+1])            {                t=a[j];                A[J]=A[J+1];                a[j+1]=t;            }    cout<<a[n/2]<<endl;    return 0;}


High-speed sequencing:

#include <iostream>using namespace std;//high-speed sort void qsort (int a[], int l, int r) {    int x=a[l], i=l, j=r;    if (l>=r) return;    while (i<j)    {        while (i<j && a[j]>=x) j--;        A[I]=A[J];        while (i<j && a[i]<=x) i++;        A[j]=a[i];    }    a[i]=x;    Qsort (a,l,i-1);    Qsort (a,i+1,r);} int main () {    int i, n;    int a[10000];    cin>>n;    for (i=0; i<n; i++)    {        cin>>a[i];    }    Qsort (a,0,n-1);    cout<<a[n/2]<<endl;    return 0;}



Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

2388 who& #39; s in the middle (simple sort)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.