一、插入排序
思想:
(在有序数列中)找一个适合的位置,插入
举例: 军训排队
另一种:不开空间b,在空间a上实现插数 len=n//数组长度
二、字符型数组
字符数据:
unsigned char s[10]; //
unsigned char s[10] = {'h','e','l','l','o'}; //数组考虑
最主要:
"tom"
"english" //字符串 常量
//本质存储时候,是按照 字符数组的形式存储
字符数组: 主要作用,想处理字符串数据
unsigned char s[10] = {'h','e','l','l','o'};//数组考虑
"hello" --> unsigned char s[10] = {'h','e','l','l','o','\0'};
'\0' 对于字符串来说,叫结束标志
unsigned char s[10] = "hello";
unsigned char s[10] = {'h','e','l','l','o','\0'};
unsigned char s[10] = {'h','e','l','l','o'};
unsigned char s[] = {'h','e','l','l','o','\0'};
unsigned char s[] = {'h','e','l','l','o'};
注意:
1.字符串 -- 更关注的是字符串整体,而不是单个字符
2.字符串的结束标志 比较重要 ,表示字符串结束
3.处理字符串时,常常使用结束标志作为判断
int puts(const char *s);
功能:
输出字符串
参数:
@s 字符串所在空间的首地址
返回值:
int 成功 >0
失败 -1
"hello" // '\0'
特点:
输出时,自动换行
char *gets(char *s);
功能:
输入字符串
参数:
@s 存放字符串一块内存空间
返回值:
表示的是 存储字符串那块空间首地址
-------------------------------------------
char s[10];
// h e l l o '\0' x x x x
puts(s); //hello
puts(s); //hello *
"hello" //字符串长度
//指的是 '\0' 前面有效字符的 个数
//h e l l o'\0 ' //5就是字符串的长度