排序
快速排序的两个分区方法:$Lomuto$ 单指针,$Hoare$ 双指针
归并排序在多核情境更快 —— 均分
Pointers
&:get address
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| int i = 10; printf("%d\n", i); printf("%p\n", &i);
|
1 2 3 4 5 6 7 8
| int a[3] = {0, 1, 2}; printf("%p\n", &a[0]); printf("%p\n", &a[1]); printf("%p\n", &a[2]); printf("%p\n", &a);
|
1 2 3 4 5 6 7 8 9 10
| int i = 10; int *p = &i; printf("%p\n", p); printf("%d\n", *p);
int *x, *y;
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| vp oid f(int *a){
}
void g(int a[]){
}
int main(){ int a[10]; printf("%p\n", a); printf("%p\n", &a);
int *p = a; printf("%d\n", p[0]); printf("%d\n", *a); printf("%d\n", *(p + 5)); printf("%d\n", p - a); }
|
string.h下的函数:
- strlen(char *)
- strcmp
- strcpy
while(*p++) 可以在字符串末结束
这样是可以的
1 2 3 4 5 6
| struct node{ int len; char content[]; };
node *str = (node*)malloc(sizeof(int) + 32);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| typedef struct{ ... }node;
node t;
typedef struct node{ ... node *next; }node;
typedef char line[30] line aa;p
typedef int *inp inp p;
|
1 2 3 4 5
| void f(int x){ ...; }
void (*p)() = f;
|
1 2 3 4 5 6 7
| #ifdef
#else #endif
用处:编译时 "-D xxx" 宏定义 (不需要修改源码)
|
1 2 3 4 5 6 7 8 9
| 多段注释:
#if 0 sss sss #endif
恢复: #if 1
|
1 2 3 4 5 6
| if(){ int i; if(){ int i; } }
|
1 2 3 4 5 6 7
| void f(void){ }
void g(){ }
|
Note
1.Declaring the pointer of a function within another function’s prototype declaration:
1
| int func( int x, int (*func2)(int, double) )
|
However, another way int func2(int, double) is acceptable too, for the function type can be automatically converted to function pointer type