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)