Classic "bubbling" sorting method

xiaoxiao2021-03-06  27

// maopao.cpp: defines the entry point for the console application.//

#include "stdafx.h" #include "stdio.h"

INT Main (int Argc, char * argv []) {int a [] = {5, 6, 8, 3, 1, 4, 7, 9}; INT I, J, T; For (i = 0; i <7; i ) // 7 For the total number of numbers required to be arranged - 1 for (j = i 1; j <8; j ) // 8 is the total number of numbers required to be arranged (a [i ]> a [j]) {t = a [i]; a [i] = a [j]; a [j] = t;} Printf ("this queue is: / n"); for (i = 0 i <8; i ) {Printf ("% d / n", a [i]);} return 0;}

The result is from small to large alignment

转载请注明原文地址:https://www.9cbs.com/read-40243.html

New Post(0)