#include "stdlib.h"
#include "string.h"
#include "stdio.h"
//排序
void main01()
{
int i = 0,j = 0;
int tmp = 0;
int a[] = {33,654,4,455,6,33,4};
printf ( "Before sorting \ n-");
for (I = 0; I <. 7; I ++)
{
printf ( "% D", A [I]);
}
// Sort
// When the outer loop when i = 0, j so that the change from the N ===. 1
// When the outer loop when i = 1, so that changes from j === N 2
// when i = 2 when, let j vary from === N 3
// Conclusion: According to a constant variable i, j let another variable changes; next in sequence
for(i=0; i<7; i++)
{
for (j=i+1; j<7; j++) //内层循环: a[i] 和 a[j]比较
{
if (a[i] > a[j])
{
tmp = a[i];
a[i]= a[j];
a[j] = tmp;
}
}
}
printf ( "After sorting \ n");
for (i=0; i<7; i++)
{
printf("%d ", a[i]);
}
printf("hello...\n");
system("pause");
}
//void printArray(int a[7], int num)
//void printArray(int a[], int num)
void printArray(int *a, int num)
{
int i = 0;
for (i=0; i<num; i++)
{
printf("%d ", a[i]);
}
}
void sortArray(int a[7], int num)
//void sortArray(int a[], int num)
//void sortArray(int *a, int num)
{
int i , j , tmp ;
int num2 = 0;
= the sizeof num2 (a) / the sizeof (a [0]);
the printf ( "NUM:% D \ n-", num2);
// argument and a parameter data type of a different nature
// parameter in the array, the compiler will recognize this as the C language pointer processing which is characteristic
for (I = 0; I <NUM; I ++)
{
for (J = I +. 1; J <NUM; J ++) // inner loop : a [i] and a [j] Comparative
{
IF (A [I]> a [j])
{
tmp = A [I];
A [I] = a [j];
a [j] = tmp;
}
}
}
}
// array of function parameters are returned as a return pointer problems,
// 1 right approach: the effective length of the array and to pass the first address memory array called function
// 2 // argument and a parameter of a the data type is not the same nature
// array parameter is, the compiler will recognize this as the pointer processing which is a feature of the C language
// Sort the nature also analyzed
@ 3 written in the function parameter, and is written in the function the same, but it is an external property.
void main22 ()
{
int I = 0, J = 0;
int tmp = 0;
int NUM = 0;
int a [] = {33,654,4,455,6,33, } 4,3333;
NUM =. 7;
num = sizeof(a)/sizeof(a[0]);
printf("num:%d \n", num);
printf ( "Before sorting \ n-");
printArray (A, NUM);
// Sort
// When the outer loop when i = 0, j so that the change from the N ===. 1
// When the outer loop when i = 1, so that changes from j === N 2
// when i = 2 when, let j vary from === N 3
// Conclusion: According to a constant variable i, j let another variable changes; next in sequence
sortArray (a, a);
printf ( "after sorting \ n-");
printArray (A, NUM);
printf("hello...\n");
system("pause");
}