650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/BA/wKioL1buuAniHjaHAAAsUDpzbQI301.png "title=" 3.png " alt= "Wkiol1buuanihjahaaasudpzbqi301.png"/>
Array method:
#include <stdio.h>
#include <stdlib.h>
bubble_sort ( int Arr [", SZ )
{
int i = 0;
int < Span style= "FONT-SIZE:9PT;" >j = 0;
for < Span style= "FONT-SIZE:9PT;" > (j = 0; J < sz < Span style= "FONT-SIZE:9PT;" >//decide how many times it takes to sort out
{
for < Span style= "FONT-SIZE:9PT;" > (i = 0; < sz -1-j; i++) //determines how many times a bubble needs to be compared
if ( arr [i "< [i + 1])
{
int tmp = arr [i];
arr [i "= Arr [i + 1] ;
arr[i + 1] = tmp;
}
}
}
}
int Main ()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int < Span style= "FONT-SIZE:9PT;" >i = 0;
bubble_sort (arr, ) Span style= "color: #0000FF; font-family: ' Times New Roman '; font-size:1px;" >sizeof < Span style= "FONT-SIZE:9PT;" > (arr)/ sizeof ( Arr[0]);
for < Span style= "FONT-SIZE:9PT;" > (i = 0; < sizeof ( ARR)/ sizeof ( Arr[0]); i++)
{
printf ( "%d", Arr[i]);
}
printf ( "\ n");
System ( "pause");
return 0;
}
Pointer method:
if (* (arr + i) < * (arr + i + 1)
{
int < Span style= "FONT-SIZE:9PT;" >tmp = * ( arr + i);
arr < Span style= "FONT-SIZE:9PT;" >+ i) = * ( arr + i + 1 );
* ( arr + i + 1) = tmp;
}
It is important to note that there are differences between arrays and pointers in understanding the differences between arrays and pointers.
The upper limit of the two-tier cycle of bubble sorting method should be mastered.
Bubble sort (Array method and pointer method)