C language study notes 10

Sorting an array of algorithms:

1, select Sorting

Sorting selection method each selection request is the maximum array sorted (ascending sort if the minimum value is selected) array elements, the value of the top element of the array is not sorted array element for the mutual change.

2, bubble sort method:

Sorting method refers to a bubble sort when, from the back to be sorted record scanning, comparing each value in an array of two adjacent array elements, a smaller number of rows in front of a large number.

3, exchange sorting

Sort exchange method is that all its digits after each number one by one, and if you find qualified data exchange data.

4, insert Sorting

Extracting a first data, find the corresponding position of the insert in the previous data until the sorting is completed.

5, binary Sorting

Sorting method is to select a binary value intermediate middle, then a value smaller than the intermediate data on the left, is larger than the intermediate data value on the right.

Description: binary dichotomy known method, the number n of the sort, only discharge log (n) times.

Problem: given a series of stock, in order from largest to smallest of the company's shares rank.

String processing functions:

Copy the string:

In the C language, string functions may be used: strcpy () function to re-set to complete the operation on the password.

Action strcpy () function is to replicate a specific length of the string to another string, is the two-character string in the array are connected, the string 2 to 1, and the result into a string.

strcpy (purpose character array name, source character array name);

note:

1, must be defined in a character array large enough to hold the string 2 being copied.

2, "a character array" must be written in the form of an array name (e.g. str1), "character string 2" may make character array name may be a string constant.

3, can not be a string constant directly to an array of characters with an assignment statement.

Problem: someone to buy things on Taobao, Alipay forgot the password, set encoding to reset your password. code show as below:

String concatenation:

A connecting string is connected to the other end of the string to the string, so that combined into a new string.

strcat (purpose character array name, source character array name);

Effect: the source character string array is connected to the rear of the array of characters is a string.

note:

1, the front end of the string has two connection '\ 0', the connection string '\ 0' cancel one behind, leaving only '\ 0' after the new string.

2、字符串 1 必须足够大,以便于容纳字符串 2。如果在定义是定义为 char str1[]="People's Republic of"; 就会出现问题,因为长度不够。

字符串比较:

字符串比较就是将一个字符串与另一个字符串从首字母开始,按照ASCII码的顺序进行逐个比较。

strcmp(字符数组名1,字符数组名2);

功能:按照ASCII码的顺序比较两个数组中的字符串,并由函数返回值返回比较结果。

注意:

1、如果全部字符相同,则认为两个字符串相同。

2、字符串1=字符串2,则函数值为0。字符串1>字符串2,则函数值为一个正整数。字符串1<字符串2,则函数值为一个负整数。

 

Guess you like

Origin www.cnblogs.com/www-bokeyuan-com/p/11183467.html