#宏#
可运用在程序查错
_FUNCTION_:打印该宏所在的函数名 eg:printf("%s",_FUNCTION_);
_func_:是上面宏的小写形式 eg:printf("%s",_func_);
_LINE_:打印该宏所处的行数 eg:printf("%d",_LINE_);
_DATE_:打印该宏所在函数运行日期 eg:printf("%s",_DATE_);
_TIME_:打印该宏所在函数运行时间 eg:printf("%s",_TIME_);
_FILE_:打印该宏所在的程序文件的名字 eg:printf("%s",_LINE_);
#随机数#
伪随机数
void srand(unsigned int seed);
int rand(void);
seed由函数time_t time(time_t *t)生成,eg:time_t tm=time(NULL);
eg:srand(time(NULL)); //若要取多次则只需处理一次种子,多次rand()即可。
printf("%d ",rand()%100); //0~100-1
真随即数
以中断的中断号、键盘输入的间隔时间、鼠标的移动、出错的时间存入到一个缓冲池中,从中随机取一个值为种子,再使用随机函数得到。
中断分为:irq(普通中断)、fiq(快速中断)
内核的随机函数:Module_init(get)random_number()用于加载内核模块
#数据结构#
数据与数据的关系:树(1:N),图(N:N),线性表(1:1),集合(1属于1)
数据的处理(增删改查):算法【算法导论】
a.线性表【数组,链表】
链表:一部分为数据域,另一部分为指针域的结构为结点,多个结点链接在一起称为链表
链表的创建:
头插法
#include <stdio.h>
#incldue <stdlib.h>
struct person{
int age;
struct person* next;
};
struct person* create(struct person* phead,int age)
{
struct person* head =phead;
struct person* tmp=malloc(sizeof(sturct person ));
tmp->age=age;
tmp->next=NULL;
if(phead==NULL)
phead=tmp;
else {
while(phead->next != NULL)
head=head->next;
head->next=tmp;
}
return phead;
}
void show(struct person* phead)
{
while(phead){
printf("%d\t",phead->age);
phead = phead->next;
}
}
int main()
{
struct person* head=NULL;
head=create(head,20);
head=create(head,34);
head=create(head,32);
head=create(head,93);
head=create(head,12);
head=create(head,32);
show(head);
return 0;
}
尾插法
struct person* insert_head(struct person* phead,int pa)
{
struct person* tmp=malloc(sizeof(struct person));
tmp->age=pa;
tmp->next=phead;
retrun tmp;
}
struct person* insert(struct person* phead,int pa)
{
struct person* tmp =mallooc(sizeof(struct person));
tmp->age=pa;
tmp->next=NULL;
if(phead==NULL)
return tmp;
else{
phead->next=tmp;
return tmp;
}
}
插入结点
struct person* insert_node(struct person* phead,int pa,int key,int flag)
{
struct person* tmp=malloc(sizeof(struct person));
tmp->age=pa;
tmp->next=NULL;
struct person* find =phead;
if(phead == NULL)
return tmp;
if(flag ==0){
tmp->next=phead;
return tmp;
}
else if(flag==1){
whlie(find->age!=key&&find!=NULL)
find=find->next;
if(find==NULL){
printf("no found. \n");
}
else {
tmp->next = find->next;
find->next = tmp->next;
}
return phead;
}
}
删除一个结点
struct person* del(struct person* phead,int a)
{
struct person* tmp=phead;
struct person* bak=NULL;
if(phead == NULL);
else {if(a==phead->age){
phead=->phead->neat;
free(tmp);
}else{
while(tmp->next!=NULL){
if(tmp->next->age==a){
bak=tmp->next;
tmp->next=bak->next;
free(bak);
bak=NULL; //防止野指针的出现
return phead;
}
tmp=tmp->next;
}
}
}
printf("not found. \n");
return phead;
}
释放链表
void destory(struct person* phead)
{
struct person* tmp=phead;
while(phead){
tmp=phead;
phead=phead->next;
free(tmp);
}
}
可运用在程序查错
_FUNCTION_:打印该宏所在的函数名 eg:printf("%s",_FUNCTION_);
_func_:是上面宏的小写形式 eg:printf("%s",_func_);
_LINE_:打印该宏所处的行数 eg:printf("%d",_LINE_);
_DATE_:打印该宏所在函数运行日期 eg:printf("%s",_DATE_);
_TIME_:打印该宏所在函数运行时间 eg:printf("%s",_TIME_);
_FILE_:打印该宏所在的程序文件的名字 eg:printf("%s",_LINE_);
#随机数#
伪随机数
void srand(unsigned int seed);
int rand(void);
seed由函数time_t time(time_t *t)生成,eg:time_t tm=time(NULL);
eg:srand(time(NULL)); //若要取多次则只需处理一次种子,多次rand()即可。
printf("%d ",rand()%100); //0~100-1
真随即数
以中断的中断号、键盘输入的间隔时间、鼠标的移动、出错的时间存入到一个缓冲池中,从中随机取一个值为种子,再使用随机函数得到。
中断分为:irq(普通中断)、fiq(快速中断)
内核的随机函数:Module_init(get)random_number()用于加载内核模块
#数据结构#
数据与数据的关系:树(1:N),图(N:N),线性表(1:1),集合(1属于1)
数据的处理(增删改查):算法【算法导论】
a.线性表【数组,链表】
链表:一部分为数据域,另一部分为指针域的结构为结点,多个结点链接在一起称为链表
链表的创建:
头插法
#include <stdio.h>
#incldue <stdlib.h>
struct person{
int age;
struct person* next;
};
struct person* create(struct person* phead,int age)
{
struct person* head =phead;
struct person* tmp=malloc(sizeof(sturct person ));
tmp->age=age;
tmp->next=NULL;
if(phead==NULL)
phead=tmp;
else {
while(phead->next != NULL)
head=head->next;
head->next=tmp;
}
return phead;
}
void show(struct person* phead)
{
while(phead){
printf("%d\t",phead->age);
phead = phead->next;
}
}
int main()
{
struct person* head=NULL;
head=create(head,20);
head=create(head,34);
head=create(head,32);
head=create(head,93);
head=create(head,12);
head=create(head,32);
show(head);
return 0;
}
尾插法
struct person* insert_head(struct person* phead,int pa)
{
struct person* tmp=malloc(sizeof(struct person));
tmp->age=pa;
tmp->next=phead;
retrun tmp;
}
struct person* insert(struct person* phead,int pa)
{
struct person* tmp =mallooc(sizeof(struct person));
tmp->age=pa;
tmp->next=NULL;
if(phead==NULL)
return tmp;
else{
phead->next=tmp;
return tmp;
}
}
插入结点
struct person* insert_node(struct person* phead,int pa,int key,int flag)
{
struct person* tmp=malloc(sizeof(struct person));
tmp->age=pa;
tmp->next=NULL;
struct person* find =phead;
if(phead == NULL)
return tmp;
if(flag ==0){
tmp->next=phead;
return tmp;
}
else if(flag==1){
whlie(find->age!=key&&find!=NULL)
find=find->next;
if(find==NULL){
printf("no found. \n");
}
else {
tmp->next = find->next;
find->next = tmp->next;
}
return phead;
}
}
删除一个结点
struct person* del(struct person* phead,int a)
{
struct person* tmp=phead;
struct person* bak=NULL;
if(phead == NULL);
else {if(a==phead->age){
phead=->phead->neat;
free(tmp);
}else{
while(tmp->next!=NULL){
if(tmp->next->age==a){
bak=tmp->next;
tmp->next=bak->next;
free(bak);
bak=NULL; //防止野指针的出现
return phead;
}
tmp=tmp->next;
}
}
}
printf("not found. \n");
return phead;
}
释放链表
void destory(struct person* phead)
{
struct person* tmp=phead;
while(phead){
tmp=phead;
phead=phead->next;
free(tmp);
}
}