C + + uses pointers to implement a bubble sort algorithm for an array.
Bubble sort
Bubble sort (Bubble sort) is a simpler sort algorithm in the field of computer science.
Code:
1 /*2 Name: Bubble sort Algorithm3 Copyright:null4 Author: Small x5 date:06-10-14 10:346 description:c++ Bubble ordering of one-dimensional arrays via pointers7 */8 9#include <iostream>Ten One /*Run this program using the console Pauser or add your own getch, System ("pause") or input loop*/ A#include <stdio.h> -#include <stdlib.h> - the /*Run this program using the console Pauser or add your own getch, System ("pause") or input loop*/ - voidSortintBintlen) - { - inti,j,t; + for(i=0; i<len-1; i++) - { + for(j=0; j<len-1-i;j++) A { at if(a[j]>a[j+1]) - { -t=A[j]; -a[j]=a[j+1]; -a[j+1]=T; - } in } - } to } + - intMainintargcChar**argv) the { * inta[6]={1563,454, About, +,48456,455}; $Sort (A,6);Panax Notoginseng inti; - for(i=0;i<6; i++) the { +printf"number%d is%d\n". II1, A[i]); A } the return 0; +}
Operation Result:
Code Explanation:
The array name of a one-dimensional array represents the address of the first element of the array, and we need two parameters when passing parameters, one for the first address and the other for the number of elements in the array.
At least these two parameters are required to determine the one-dimensional array.
end!
Welcome to Exchange, sharing the programmer inspirational story. QQ Group of Happy programmers:
Data structure------C + + pointer bubble sorting algorithm