13th Week on-machine practice Item 4--array Sorting (1)

Source: Internet
Author: User

Questions and codes

/* Copyright (c) 2014, Yantai University School of Computer * All rights reserved. * File name: Test.cpp * Author: Simbin * Completion Date: November 25, 2014 * Version number: v1.0 * * Problem Description: Write the function, complete the bubble sort, the request cannot change the following main function. * Input Description: no input. * Program output: bubble sort; */#include <iostream>using namespace std;//two functions bubble_sort and output_array declaration void Bubble_sort (int s[] , int i); void Output_array (int s[],int i); int main () {int a[20]={86,76,62,58,77,85,92,80,96,88,77,67,80,68,88,87,64,59    , 61,76};    int b[15]={27,61,49,88,4,20,28,31,42,62,64,14,88,27,73};   Bubble_sort (a,20);   Sort the element Output_array (a,20) in descending order by bubbling method;    Output sorted Array cout<<endl;   Bubble_sort (b,15);   Sort the element Output_array (b,15) in descending order by bubbling method; Output sorted array return 0;}    Please define Bubble_sort and output_array function void bubble_sort (int s[],int i) {int j,t,m below);        for (int. j=0;j<i-1;j++) for (t=0;t<i-j-1;t++) if (s[t]<s[t+1]) {m=s[t];        S[T]=S[T+1];    S[t+1]=m; }}void output_array (int s[],int i) {for (int n=0;n<i;n++) cout<<s[n]<< "";}

Operation Result:

13th Week on-machine practice Item 4--array Sorting (1)

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.