├── .github ├── FUNDING.yml └── workflows │ └── docs.yml ├── .gitignore ├── .nojekyll ├── README.md ├── _navbar.md ├── _sidebar.md ├── algorithm ├── _sidebar.md ├── imgs │ ├── bubble_sort.gif │ ├── insertion_sort.gif │ ├── quick_sort.gif │ ├── selection_sort.gif │ └── sort_complexity.png ├── sort.md └── sort │ ├── bubble_sort.md │ ├── bucket_sort.md │ ├── counting_sort.md │ ├── heap_sort.md │ ├── intro.md │ ├── merge_sort.md │ ├── quick_sort.md │ ├── radix_sort.md │ ├── reference.md │ ├── shell_sort.md │ ├── simple_selection_sort.md │ └── straight_insertion_sort.md ├── c++ ├── _sidebar.md ├── comment.md ├── enum.md ├── exception.md ├── expression.md ├── func.md ├── intro.md ├── namespace.md ├── new_delete.md ├── objects.md ├── pointer.md ├── reference.md ├── refers.md ├── string.md ├── struct.md ├── template.md ├── types.md └── var_const.md ├── c ├── _sidebar.md ├── array.md ├── bit_operation.md ├── comment.md ├── const.md ├── enum.md ├── flow_control.md ├── func.md ├── intro.md ├── operator.md ├── pointer.md ├── reference.md ├── string.md ├── struct.md ├── type.md └── var.md ├── css ├── Reference.md ├── css3学习笔记 │ ├── 2D转换.md │ ├── 3D转换.md │ ├── 动画.md │ ├── 图片.md │ ├── 多列.md │ ├── 字体.md │ ├── 按钮.md │ ├── 文本效果.md │ ├── 渐变.md │ ├── 用户界面.md │ ├── 盒阴影.md │ ├── 背景.md │ ├── 边框图片.md │ ├── 边框圆角.md │ └── 过渡.md └── css学习笔记 │ ├── 伪类.md │ ├── 内边距.md │ ├── 分组选择器.md │ ├── 列表样式.md │ ├── 响应式设计.md │ ├── 外边距.md │ ├── 媒体查询.md │ ├── 字体.md │ ├── 定位.md │ ├── 尺寸.md │ ├── 嵌套选择器.md │ ├── 文本.md │ ├── 显示和可见性.md │ ├── 样式表.md │ ├── 注释.md │ ├── 浮动.md │ ├── 盒子模型.md │ ├── 简介.md │ ├── 组合选择器.md │ ├── 网格视图.md │ ├── 背景.md │ ├── 表格.md │ ├── 语法.md │ ├── 轮廓.md │ ├── 边框.md │ ├── 选择器.md │ ├── 链接.md │ └── 颜色的写法.md ├── data_structure ├── _sidebar.md ├── array.md ├── graph.md ├── hash_table.md ├── heap.md ├── intro.md ├── list.md ├── queue.md ├── reference.md ├── stack.md ├── string.md └── tree.md ├── design_pattern ├── _sidebar.md ├── abstract_factory.md ├── adapter.md ├── bridge.md ├── builder.md ├── chain_of_responsibility.md ├── command.md ├── composite.md ├── decorator.md ├── facade.md ├── factory.md ├── filter.md ├── flyweight.md ├── interpreter.md ├── intro.md ├── iterator.md ├── mediator.md ├── memento.md ├── null_object.md ├── observer.md ├── principle.md ├── prototype.md ├── proxy.md ├── reference.md ├── singleton.md ├── state.md ├── strategy.md ├── template.md ├── type.md └── visitor.md ├── docker └── learn.md ├── english ├── imgs │ └── img_1.jpg └── learn.md ├── git └── query.md ├── go └── learn_go.md ├── groovy └── learn.md ├── html ├── _sidebar.md ├── learn_html.md └── learn_html5.md ├── index.html ├── index.md ├── javascript └── learn.md ├── learn_list.md ├── libs ├── docsify-copy-code.min.js ├── docsify.min.js ├── prism.min.js ├── vue.css └── zoom-image.min.js ├── materials └── ref.md ├── mkdocs.yml ├── mysql └── learn.md ├── network ├── imgs │ ├── OSI七层模型.png │ └── TCP-OS对应关系.png ├── learn.md └── reference.md ├── nojekyll ├── postgraduate.md ├── python ├── _sidebar.md ├── class.md ├── comment.md ├── data_type.md ├── dict.md ├── error.md ├── flow_control.md ├── fun.md ├── intro.md ├── learn.md ├── list.md ├── module.md ├── reference.md ├── set.md ├── string.md ├── tuple.md └── variable.md ├── rust ├── _sidebar.md ├── array.md ├── cargo.md ├── closure.md ├── comments.md ├── concurrency.md ├── const.md ├── control_flow.md ├── data_types.md ├── enum.md ├── error_handling.md ├── functions.md ├── generics.md ├── intro.md ├── iterator.md ├── lifetime.md ├── macros.md ├── match.md ├── ownership.md ├── referencs.md ├── refers.md ├── slice.md ├── smart_pointer.md ├── structs.md ├── traits.md ├── tuple.md └── varialbles.md └── shell ├── _sidebar.md ├── arguments.md ├── array.md ├── comment.md ├── expression.md ├── func.md ├── include_file.md ├── intro.md ├── io.md ├── operator.md ├── reference.md ├── string.md ├── tools.md └── var.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: https://simplepeng.github.io/merge_pay_code/ 13 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [mkdocs] 6 | 7 | workflow_dispatch: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v3 15 | with: 16 | fetch-depth: 0 17 | 18 | - uses: actions/setup-python@v3.1.2 19 | - run: pip install --upgrade pip && pip install mkdocs mkdocs-gen-files 20 | - run: git config user.name 'github-actions[bot]' && git config user.email 'github-actions[bot]@users.noreply.github.com' 21 | 22 | - name: publish docs 23 | run: mkdocs gh-deploy 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | *.out 4 | .vscode 5 | 6 | 7 | -------------------------------------------------------------------------------- /.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/.nojekyll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 一个大专🐶的学习笔记 2 | 3 | - [C语言](c/intro.md) 4 | - [C++](c++/intro.md) 5 | - [Shell](shell/intro.md) 6 | - [数据结构](data_structure/intro.md) 7 | - [算法](algorithm/sort.md) 8 | - [设计模式](design_pattern/intro.md) 9 | - [计算机网络](network/learn.md) 10 | - [Rust](rust/intro.md) 11 | - [Go](go/learn_go.md) 12 | - [Git](git/query.md) 13 | - [Docker](docker/learn.md) 14 | - [Groovy](groovy/learn.md) 15 | - [Python](python/learn.md) 16 | - [MySQL](mysql/learn.md) 17 | - [HTML](html/learn_html.md) 18 | - [JavaScript](javascript/learn.md) 19 | - [CSS]() 20 | - [英语](english/learn.md) 21 | 22 | ## 友情赞赏 23 | 24 | **[扶贫方式👍👍👍](https://simplepeng.github.io/merge_pay_code/)** -------------------------------------------------------------------------------- /_navbar.md: -------------------------------------------------------------------------------- 1 | * [Github](https://www.github.com/simplepeng) 2 | * [个人主页](https://simplepeng.github.io) 3 | * [博客](https://simplepeng.github.io/blog) 4 | * [掘金](https://juejin.cn/user/641770519265832) -------------------------------------------------------------------------------- /_sidebar.md: -------------------------------------------------------------------------------- 1 | - [C语言](c/intro.md) 2 | - [C++](c++/intro.md) 3 | - [数据结构](data_structure/intro.md) 4 | - [排序算法](algorithm/sort/intro.md) 5 | - [设计模式](design_pattern/intro.md) 6 | - [计算机网络](network/learn.md) 7 | - [Shell](shell/intro.md) 8 | - [Go](go/learn_go.md) 9 | - [Rust](rust/intro.md) 10 | - [Git](git/query.md) 11 | - [Docker](docker/learn.md) 12 | - [Groovy](groovy/learn.md) 13 | - [Python](python/intro.md) 14 | - [MySQL](mysql/learn.md) 15 | - [HTML](html/_sidebar.md) 16 | - [JavaScript](javascript/learn.md) 17 | - [英语](english/learn.md) 18 | - [学习资料汇总](materials/ref.md) 19 | - [学习记录](learn_list.md) -------------------------------------------------------------------------------- /algorithm/_sidebar.md: -------------------------------------------------------------------------------- 1 | - 排序算法 2 | - [简介](algorithm/sort/intro.md) 3 | - [冒泡排序](algorithm/sort/bubble_sort.md) 4 | - [选择排序](algorithm/sort/simple_selection_sort.md) 5 | - [插入排序](algorithm/sort/straight_insertion_sort.md) 6 | - [希尔排序](algorithm/sort/shell_sort.md) 7 | - [堆排序](algorithm/sort/heap_sort.md) 8 | - [归并排序](algorithm/sort/merge_sort.md) 9 | - [快速排序](algorithm/sort/quick_sort.md) 10 | - [基数排序](algorithm/sort/radix_sort.md) 11 | - [计数排序](algorithm/sort/counting_sort.md) 12 | - [桶排序](algorithm/sort/bucket_sort.md) 13 | - [参考](algorithm/sort/reference.md) -------------------------------------------------------------------------------- /algorithm/imgs/bubble_sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/algorithm/imgs/bubble_sort.gif -------------------------------------------------------------------------------- /algorithm/imgs/insertion_sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/algorithm/imgs/insertion_sort.gif -------------------------------------------------------------------------------- /algorithm/imgs/quick_sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/algorithm/imgs/quick_sort.gif -------------------------------------------------------------------------------- /algorithm/imgs/selection_sort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/algorithm/imgs/selection_sort.gif -------------------------------------------------------------------------------- /algorithm/imgs/sort_complexity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/algorithm/imgs/sort_complexity.png -------------------------------------------------------------------------------- /algorithm/sort.md: -------------------------------------------------------------------------------- 1 | # 十大经典排序算法 2 | 3 | ## 时间/空间复杂度 4 | 5 | ![](imgs/sort_complexity.png) 6 | 7 | ## 分类 8 | 9 | ### 交换排序 10 | * 冒泡排序 11 | * 快速排序 12 | ### 插入排序 13 | * 直接插入排序 14 | * 希尔排序 15 | ### 选择排序 16 | * 简单选择排序 17 | * 堆排序排序 18 | ### 归并排序 19 | ### 基数排序 20 | 21 | ## 排序动画 22 | 23 | * https://visualgo.net/zh/sorting 24 | * https://www.webhek.com/post/comparison-sort.html 25 | 26 | ## 交换数组元素 27 | 28 | ```java 29 | public class Utils { 30 | public static void swap(int[] arr, int a, int b) { 31 | int temp = arr[a]; 32 | arr[a] = arr[b]; 33 | arr[b] = temp; 34 | } 35 | } 36 | ``` 37 | 38 | ## 1.冒泡排序 39 | 40 | 两两比较,比较相邻两个元素,如果第一个比第二个大,就交互位置。 41 | 42 | 双层for循环,内层循环用来交互位置,外层循环用来控制循环次数。 43 | 44 | 每次循环后,最大的那个元素就会移动至末尾,所以内存循环次数可以为数组length减去外层循环的当前index。 45 | 46 | ![冒泡排序](imgs/bubble_sort.gif) 47 | 48 | ```java 49 | public static void bubbleSort(int[] arr) { 50 | int len = arr.length; 51 | // 循环次数为数组容量 52 | for (int i = 0; i < len; i++) { 53 | // 循环len-i次,因为完成一次循环,最大的元素就会被移动至末尾 54 | for (int j = 0; j < len - i; j++) { 55 | // 比较当前位置和下一位谁大 56 | if (j < len - 1 && arr[j] > arr[j + 1]) { 57 | // 交互位置 58 | swap(arr, j, j + 1); 59 | } 60 | } 61 | } 62 | } 63 | ``` 64 | 65 | ## 2.快速排序 66 | 67 | 分治和递归 68 | 69 | 1. 从数组或队列中选出一个元素,称之为`基准(pivot)`。 70 | 2. 开始排序,比基准小的就放到基准的前面,比基准大得就放在基准的后面,相同的可以放在任意一边。一次分区完成后,基准就位于数列的中间。所以这个也称之为`分区(parttion)`操作。 71 | 3. `递归的`把小于基准和大于基准的子数列排序,也就是进行上一步的操作。 72 | 73 | ![](imgs/quick_sort.gif) 74 | 75 | ```java 76 | 77 | ``` 78 | 79 | [百度百科]([https://baike.baidu.com/item/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/369842?fromtitle=%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F&fromid=2084344](https://baike.baidu.com/item/快速排序算法/369842?fromtitle=快速排序&fromid=2084344)) 80 | 81 | ## 3.插入排序 82 | 83 | 1. 将未排序数列的第一个元素看做一个有序序列,从第二个元素到最后一个元素看成未排序序列。 84 | 2. 从头至尾遍历未排序序列,将扫描到的每个元素插入`有序序列`适当的位置。 85 | 86 | ![](imgs/insertion_sort.gif) 87 | 88 | ```java 89 | private static void insertionSort(int[] arr) { 90 | int length = arr.length; 91 | 92 | // 下标从1开始,因为0下标已经被当成有序序列 93 | for (int i = 1; i < length; i++) { 94 | int current = arr[i];//当前要插入的元素 95 | int preIndex = i - 1;//未排序序列的index 96 | 97 | // 如果未排序的元素大于当前要插入的元素,继续执行循环 98 | // 并且preIndex的下标要不小于0 99 | while (preIndex >= 0 && arr[preIndex] > current) { 100 | arr[preIndex + 1] = arr[preIndex];// preIndex的元素后移一位 101 | preIndex--;// 已排序序列下标减一,继续比较 102 | } 103 | 104 | // 当preIndex下标的元素不大于current时,就插入在preIndex后面 105 | arr[preIndex + 1] = current; 106 | } 107 | } 108 | ``` 109 | 110 | 111 | 112 | ## 4.希尔排序 113 | 114 | ## 5.选择排序 115 | 116 | 1. 从数列中选择最大或最小的那个元素,放到首位或末尾。 117 | 118 | 2. 重复上一步骤,但是这里的首位或末尾是指不包含上一步已经占坑了的首位或末尾。 119 | 120 | ![](imgs/selection_sort.gif) 121 | 122 | ```java 123 | private static void selectionSort(int[] arr) { 124 | int length = arr.length; 125 | int minIndex = 0; 126 | 127 | for (int i = 0; i < length; i++) { 128 | minIndex = i; 129 | for (int j = i + 1; j < length; j++) { 130 | if (arr[minIndex] > arr[j]) { 131 | minIndex = j; 132 | } 133 | } 134 | swap(arr, i, minIndex); 135 | } 136 | } 137 | ``` 138 | 139 | 内层for循环遍历一次数列找出最小或最大的那个元素,外层for控制循环次数,保证每个元素都被比较到。 140 | 141 | ## 6.堆排序 142 | 143 | ## 7.归并排序 144 | 145 | ## 8.基数排序 146 | 147 | ## 9.计数排序 148 | 149 | ## 10. 桶排序 150 | 151 | ## 参考 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /algorithm/sort/bubble_sort.md: -------------------------------------------------------------------------------- 1 | ## 冒泡排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/冒泡排序) 4 | 5 | 冒泡排序是一种交换排序,它的基本思想是:两两比较相邻记录的元素,如果反序则交换,直到没有反序为止。 6 | 7 | ```java 8 | public static void bubbleSort(int[] arr) { 9 | int len = arr.length; 10 | // 循环次数为数组容量 11 | for (int i = 0; i < len; i++) { 12 | // 循环len-i次,因为完成一次循环,最大的元素就会被移动至末尾 13 | for (int j = 0; j < len - i; j++) { 14 | // 比较当前位置和下一位谁大 15 | if (j < len - 1 && arr[j] > arr[j + 1]) { 16 | // 交互位置 17 | swap(arr, j, j + 1); 18 | } 19 | } 20 | } 21 | } 22 | ``` 23 | 24 | 双层for循环,内层循环用来交互位置,外层循环用来控制循环次数。 25 | 26 | 每次循环后,最大的那个元素就会移动至末尾,所以内存循环次数可以为数组length减去外层循环的当前index。 27 | 28 | ![](../imgs/bubble_sort.gif) -------------------------------------------------------------------------------- /algorithm/sort/bucket_sort.md: -------------------------------------------------------------------------------- 1 | ## 桶排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/桶排序) 4 | 5 | -------------------------------------------------------------------------------- /algorithm/sort/counting_sort.md: -------------------------------------------------------------------------------- 1 | ## 计数排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/计数排序) -------------------------------------------------------------------------------- /algorithm/sort/heap_sort.md: -------------------------------------------------------------------------------- 1 | ## 堆排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/堆排序) 4 | 5 | 堆排序算法是Floyd和Williams在1964年共同发明的,同时,他们发明了`堆`这样的数据结构。 -------------------------------------------------------------------------------- /algorithm/sort/intro.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/排序算法) 4 | 5 | 排序分为`内排序`和`外排序` 6 | 7 | 内排序是在排序整个过程中,待排序的所有记录全部放置在内存中。 8 | 9 | 外排序是由于排序的记录个数太多,不能同时放置在内存,整个排序过程需要在内外存之间多次交换数据才能进行。 10 | 11 | 在内排序中,主要进行两种操作:比较和移动。 12 | 13 | - 插入排序 14 | - 直接插入排序 15 | - 希尔排序 16 | - 交换排序 17 | - 冒泡排序 18 | - 快速排序 19 | - 选择排序 20 | - 简单选择排序 21 | - 堆排序 22 | - 归并排序 23 | - 基数排序 24 | 25 | 从算法的简单性来看,我们可以将算法分为两类: 26 | 27 | - 简单算法:冒泡,简单选择,直接插入。 28 | - 改进算法:希尔,堆,归并,快速。 29 | 30 | ## 排序动画演示 31 | 32 | - https://visualgo.net/zh/sorting 33 | - https://www.webhek.com/post/comparison-sort.html 34 | 35 | ## 算法复杂度 36 | 37 | ![复杂度](../imgs/sort_complexity.png) 38 | -------------------------------------------------------------------------------- /algorithm/sort/merge_sort.md: -------------------------------------------------------------------------------- 1 | ## 归并排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/归并排序) -------------------------------------------------------------------------------- /algorithm/sort/quick_sort.md: -------------------------------------------------------------------------------- 1 | ## 快速排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/快速排序) 4 | 5 | 快速排序的核心思想就是:`分治和递归`。 6 | 7 | ```java 8 | /** 9 | * 入口函数(递归方法),算法的调用从这里开始。 10 | */ 11 | public void quickSort(int[] arr, int startIndex, int endIndex) { 12 | if (startIndex >= endIndex) { 13 | return; 14 | } 15 | 16 | // 核心算法部分:分别介绍 双边指针(交换法),双边指针(挖坑法),单边指针 17 | int pivotIndex = doublePointerSwap(arr, startIndex, endIndex); 18 | // int pivotIndex = doublePointerHole(arr, startIndex, endIndex); 19 | // int pivotIndex = singlePointer(arr, startIndex, endIndex); 20 | 21 | // 用分界值下标区分出左右区间,进行递归调用 22 | quickSort(arr, startIndex, pivotIndex - 1); 23 | quickSort(arr, pivotIndex + 1, endIndex); 24 | } 25 | 26 | /** 27 | * 双边指针(交换法) 28 | * 思路: 29 | * 记录分界值 pivot,创建左右指针(记录下标)。 30 | * (分界值选择方式有:首元素,随机选取,三数取中法) 31 | * 32 | * 首先从右向左找出比pivot小的数据, 33 | * 然后从左向右找出比pivot大的数据, 34 | * 左右指针数据交换,进入下次循环。 35 | * 36 | * 结束循环后将当前指针数据与分界值互换, 37 | * 返回当前指针下标(即分界值下标) 38 | */ 39 | private int doublePointerSwap(int[] arr, int startIndex, int endIndex) { 40 | int pivot = arr[startIndex]; 41 | int leftPoint = startIndex; 42 | int rightPoint = endIndex; 43 | 44 | while (leftPoint < rightPoint) { 45 | // 从右向左找出比pivot小的数据 46 | while (leftPoint < rightPoint 47 | && arr[rightPoint] > pivot) { 48 | rightPoint--; 49 | } 50 | // 从左向右找出比pivot大的数据 51 | while (leftPoint < rightPoint 52 | && arr[leftPoint] <= pivot) { 53 | leftPoint++; 54 | } 55 | // 没有过界则交换 56 | if (leftPoint < rightPoint) { 57 | int temp = arr[leftPoint]; 58 | arr[leftPoint] = arr[rightPoint]; 59 | arr[rightPoint] = temp; 60 | } 61 | } 62 | // 最终将分界值与当前指针数据交换 63 | arr[startIndex] = arr[rightPoint]; 64 | arr[rightPoint] = pivot; 65 | // 返回分界值所在下标 66 | return rightPoint; 67 | } 68 | 69 | /** 70 | * 双边指针(挖坑法) 71 | * 思路: 72 | * 创建左右指针。 73 | * 记录左指针数据为分界值 pivot, 74 | * 此时左指针视为"坑",里面的数据可以被覆盖。 75 | * 76 | * 首先从右向左找出比pivot小的数据, 77 | * 找到后立即放入左边坑中,当前位置变为新的"坑", 78 | * 然后从左向右找出比pivot大的数据, 79 | * 找到后立即放入右边坑中,当前位置变为新的"坑", 80 | * 81 | * 结束循环后将最开始存储的分界值放入当前的"坑"中, 82 | * 返回当前"坑"下标(即分界值下标) 83 | */ 84 | private int doublePointerHole(int[] arr, int startIndex, int endIndex) { 85 | int pivot = arr[startIndex]; 86 | int leftPoint = startIndex; 87 | int rightPoint = endIndex; 88 | 89 | while (leftPoint < rightPoint) { 90 | // 从右向左找出比pivot小的数据, 91 | while (leftPoint < rightPoint 92 | && arr[rightPoint] > pivot) { 93 | rightPoint--; 94 | } 95 | // 找到后立即放入左边坑中,当前位置变为新的"坑" 96 | if (leftPoint < rightPoint) { 97 | arr[leftPoint] = arr[rightPoint]; 98 | leftPoint++; 99 | } 100 | // 从左向右找出比pivot大的数据 101 | while (leftPoint < rightPoint 102 | && arr[leftPoint] <= pivot) { 103 | leftPoint++; 104 | } 105 | // 找到后立即放入右边坑中,当前位置变为新的"坑" 106 | if (leftPoint < rightPoint) { 107 | arr[rightPoint] = arr[leftPoint]; 108 | rightPoint--; 109 | } 110 | } 111 | // 将最开始存储的分界值放入当前的"坑"中 112 | arr[rightPoint] = pivot; 113 | return rightPoint; 114 | } 115 | 116 | /** 117 | * 单边指针 118 | * 思路: 119 | * 记录首元素为分界值 pivot, 创建标记 mark 指针。 120 | * 循环遍历与分界值对比。 121 | * 比分界值小,则 mark++ 后与之互换。 122 | * 结束循环后,将首元素分界值与当前mark互换。 123 | * 返回 mark 下标为分界值下标。 124 | */ 125 | private int singlePointer(int[] arr, int startIndex, int endIndex) { 126 | int pivot = arr[startIndex]; 127 | int markPoint = startIndex; 128 | 129 | for (int i = startIndex + 1; i <= endIndex; i++) { 130 | // 如果比分界值小,则 mark++ 后互换。 131 | if (arr[i] < pivot) { 132 | markPoint++; 133 | int temp = arr[markPoint]; 134 | arr[markPoint] = arr[i]; 135 | arr[i] = temp; 136 | } 137 | } 138 | // 将首元素分界值与当前mark互换 139 | arr[startIndex] = arr[markPoint]; 140 | arr[markPoint] = pivot; 141 | return markPoint; 142 | } 143 | ``` 144 | 145 | 1. 从数组或队列中选出一个元素,称之为`基准(pivot)`。 146 | 2. 开始排序,比基准小的就放到基准的前面,比基准大得就放在基准的后面,相同的可以放在任意一边。一次分区完成后,基准就位于数列的中间。所以这个也称之为`分区(partition)`操作。 147 | 3. `递归的`把小于基准和大于基准的子数列排序,也就是进行上一步的操作。 148 | 149 | ![](../imgs/quick_sort.gif) 150 | 151 | [百度百科](https://baike.baidu.com/item/%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/369842?fromtitle=%E5%BF%AB%E9%80%9F%E6%8E%92%E5%BA%8F&fromid=2084344) 152 | 153 | ## 时间复杂度分析 154 | 155 | * 在最优的情况下,`分区操作(partition)`每次都划分得很均匀,时间复杂度为`O(nlogn)` 156 | * 在最坏情况下,待排序的数据为`正序`或`反序`,其时间复杂度为`O(n²)` 157 | * 平均的情况,时间复杂度为O(nlogn)` 158 | 159 | ## 快速排序的优化 160 | 161 | 1. 优化选取枢轴(pivot) 162 | * 随机选取枢轴法 163 | * 三数取中法(median-of-three) 164 | * 九数取中法(median-of-nine) 165 | 2. 优化不必要的交换 166 | 3. 优化数组元素小的排序方案 167 | 4. 优化递归操作(尾递归) 168 | 169 | 在现实中,待排序的序列极有可能是基本有序的,此时,总是`固定选取`某个数作为`枢轴`,就变成了极为不合理的方法。 170 | 171 | 于是就有人提出了`随机枢轴法`:随机获得一个low与high之间的数rnd,让它的关键字L.r[rnd]与L.r[low]交换。 172 | 173 | `三数取中法`:即取三个关键字先进行排序,将中间数作为枢轴,一般是取左端,右端和中间的三个数,也可以是随机抽取。 174 | 175 | `九数取中法`:先从数组中分三次取样,每次取三个数,三个样品各取出中数,然后从这三个中数当中再取出一个中数作为枢轴。 176 | 177 | 如果数组非常小,其实快速排序反而不如直接插入排序来得更好(直接插入排序是简单排序中性能最好的)。 178 | 179 | -------------------------------------------------------------------------------- /algorithm/sort/radix_sort.md: -------------------------------------------------------------------------------- 1 | ## 基数排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/基数排序) -------------------------------------------------------------------------------- /algorithm/sort/reference.md: -------------------------------------------------------------------------------- 1 | ## 参考 2 | 3 | * [菜鸟教程](https://www.runoob.com/w3cnote/ten-sorting-algorithm.html) 4 | * 《大话数据结构》 -------------------------------------------------------------------------------- /algorithm/sort/shell_sort.md: -------------------------------------------------------------------------------- 1 | ## 希尔排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/希尔排序) 4 | 5 | -------------------------------------------------------------------------------- /algorithm/sort/simple_selection_sort.md: -------------------------------------------------------------------------------- 1 | ## 选择排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/选择排序) 4 | 5 | 1. 从数列中选择最大或最小的那个元素,放到首位或末尾。 6 | 7 | 2. 重复上一步骤,但是这里的首位或末尾是指不包含上一步已经占坑了的首位或末尾。 8 | 9 | ```java 10 | private static void selectionSort(int[] arr) { 11 | int length = arr.length; 12 | int minIndex = 0; 13 | 14 | for (int i = 0; i < length; i++) { 15 | minIndex = i; 16 | for (int j = i + 1; j < length; j++) { 17 | if (arr[minIndex] > arr[j]) { 18 | minIndex = j; 19 | } 20 | } 21 | swap(arr, i, minIndex); 22 | } 23 | } 24 | ``` 25 | 26 | 内层for循环遍历一次数列找出最小或最大的那个元素,外层for控制循环次数,保证每个元素都被比较到。 27 | 28 | 从简单选择排序的过程来看,它最大的特点就是交换移动数据次数相当少,这样就节约了相应的时间。 29 | 30 | 平均时间复杂度为O(n²),尽管与冒泡排序同为O(n²),但简单排序的性能还是要优于冒泡算法。 31 | 32 | ![](../imgs/selection_sort.gif) 33 | 34 | -------------------------------------------------------------------------------- /algorithm/sort/straight_insertion_sort.md: -------------------------------------------------------------------------------- 1 | ## 插入排序 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/插入排序) 4 | 5 | 直接插入排序的基本操作是将一个记录插入到已经排好序的有序表中,从而得到一个新的,记录数增1的有序表。 6 | 7 | 1. 将未排序数列的第一个元素看做一个有序序列,从第二个元素到最后一个元素看成未排序序列。 8 | 2. 从头至尾遍历未排序序列,将扫描到的每个元素插入`有序序列`适当的位置。 9 | 10 | ```java 11 | private static void insertionSort(int[] arr) { 12 | int length = arr.length; 13 | 14 | // 下标从1开始,因为0下标已经被当成有序序列 15 | for (int i = 1; i < length; i++) { 16 | int current = arr[i];//当前要插入的元素 17 | int preIndex = i - 1;//未排序序列的index 18 | 19 | // 如果未排序的元素大于当前要插入的元素,继续执行循环 20 | // 并且preIndex的下标要不小于0 21 | while (preIndex >= 0 && arr[preIndex] > current) { 22 | arr[preIndex + 1] = arr[preIndex];// preIndex的元素后移一位 23 | preIndex--;// 已排序序列下标减一,继续比较 24 | } 25 | 26 | // 当preIndex下标的元素不大于current时,就插入在preIndex后面 27 | arr[preIndex + 1] = current; 28 | } 29 | } 30 | ``` 31 | 32 | ![](../imgs/insertion_sort.gif) 33 | 34 | 同样的O(n²)时间复杂度,直接插入排序比冒泡和简单选择排序的性能要好一些。 35 | 36 | -------------------------------------------------------------------------------- /c++/_sidebar.md: -------------------------------------------------------------------------------- 1 | - C++ 2 | - [简介](c++/intro.md) 3 | - [注释](c++/comment.md) 4 | - [变量和常量](c++/var_const.md) 5 | - [类型](c++/types.md) 6 | - [逻辑控制](c++/expression.md) 7 | - [指针](c++/pointer.md) 8 | - [引用](c++/refers.md) 9 | - [结构体](c++/struct.md) 10 | - [枚举](c++/enum.md) 11 | - [字符串](c++/string.md) 12 | - [动态内存](c++/new_delete.md) 13 | - [面向对象](c++/objects.md) 14 | - [模板](c++/template.md) 15 | - [命名空间](c++/namespace.md) 16 | - [异常处理](c++/exception.md) 17 | - [参考](c++/reference.md) -------------------------------------------------------------------------------- /c++/comment.md: -------------------------------------------------------------------------------- 1 | ## 注释 2 | 3 | ```c++ 4 | /* 这是注释 */ 5 | 6 | /* C++ 注释也可以 7 | * 跨行 8 | */ 9 | 10 | //这也是注释 11 | ``` -------------------------------------------------------------------------------- /c++/enum.md: -------------------------------------------------------------------------------- 1 | ## 枚举 2 | 3 | 枚举类型(enumeration)是C++中的一种派生数据类型,它是由用户定义的若干枚举常量的集合。 4 | 5 | 创建枚举,需要使用关键字 `enum` 6 | 7 | ```c++ 8 | enum 枚举名{ 9 | 标识符[=整型常数], 10 | 标识符[=整型常数], 11 | ... 12 | 标识符[=整型常数] 13 | } 枚举变量; 14 | ``` 15 | 16 | ```c++ 17 | enum color { red, green, blue } c; 18 | c = blue; 19 | //red = 0 20 | //greem = 1 21 | ``` 22 | 23 | 默认情况下,第一个名称的值为 0,后续值依次`+1` 24 | 25 | 但是,也可以给名称赋予一个特殊的值,只需要添加一个初始值即可 26 | 27 | ```c++ 28 | enum color { red, green=5, blue }; 29 | //green = 5 30 | //blue = 6 31 | ``` 32 | 33 | -------------------------------------------------------------------------------- /c++/exception.md: -------------------------------------------------------------------------------- 1 | ## 异常处理 2 | 3 | c++异常处理主要使用三个关键字`try`,`catch`和`throw` 4 | 5 | ```c++ 6 | try 7 | { 8 | // 保护代码 9 | }catch( ExceptionName e1 ) 10 | { 11 | // catch 块 12 | }catch( ExceptionName e2 ) 13 | { 14 | // catch 块 15 | }catch( ExceptionName eN ) 16 | { 17 | // catch 块 18 | } 19 | ``` 20 | 21 | ### 定义新的异常 22 | 23 | 通过继承`std::exception`来新建异常类,通过重写`what`函数来返回异常原因。 24 | 25 | ```c++ 26 | #include 27 | #include 28 | 29 | using namespace std; 30 | 31 | class CustomException : public exception 32 | { 33 | public: 34 | const char *what() const throw() 35 | { 36 | return "This is CustomException"; 37 | } 38 | }; 39 | 40 | int main(int argc, char const *argv[]) 41 | { 42 | try 43 | { 44 | throw CustomException(); 45 | } 46 | catch (CustomException &e) 47 | { 48 | cout << e.what() << endl; 49 | } 50 | return 0; 51 | } 52 | ``` -------------------------------------------------------------------------------- /c++/expression.md: -------------------------------------------------------------------------------- 1 | ## 逻辑控制 2 | 3 | ```c++ 4 | if(boolean_expression) 5 | { 6 | // 如果布尔表达式为真将执行的语句 7 | } 8 | else 9 | { 10 | // 如果布尔表达式为假将执行的语句 11 | } 12 | ``` 13 | 14 | ```c++ 15 | switch(expression){ 16 | case constant-expression : 17 | statement(s); 18 | break; // 可选的 19 | case constant-expression : 20 | statement(s); 21 | break; // 可选的 22 | 23 | // 您可以有任意数量的 case 语句 24 | default : // 可选的 25 | statement(s); 26 | } 27 | ``` 28 | 29 | ## 遍历 30 | 31 | ```c++ 32 | while(condition) 33 | { 34 | statement(s); 35 | } 36 | ``` 37 | 38 | ```c++ 39 | for( int a = 10; a < 20; a = a + 1 ) 40 | { 41 | cout << "a 的值:" << a << endl; 42 | } 43 | ``` 44 | 45 | ```c++ 46 | do 47 | { 48 | cout << "a 的值:" << a << endl; 49 | a = a + 1; 50 | }while( a < 20 ); 51 | ``` 52 | 53 | | 控制语句 | 描述 | 54 | | :----------------------------------------------------------- | :----------------------------------------------------------- | 55 | | break 语句 | 终止 **loop** 或 **switch** 语句,程序流将继续执行紧接着 loop 或 switch 的下一条语句。 | 56 | | continue 语句 | 引起循环跳过主体的剩余部分,立即重新开始测试条件。 | 57 | | goto 语句 | 将控制转移到被标记的语句。但是不建议在程序中使用 goto 语句。 | -------------------------------------------------------------------------------- /c++/func.md: -------------------------------------------------------------------------------- 1 | ## 函数 2 | 3 | `函数声明`告诉编译器函数的名称、返回类型和参数。`函数定义`提供了函数的实际主体。 4 | 5 | `函数声明`一般放在`头文件`里面,`函数定义`实现在`cpp`中,这样编译链接后,其他文件导入`函数定义`的头文件就可以直接使用该函数。 6 | 7 | ```c++ 8 | return_type function_name( parameter list ) 9 | { 10 | body of the function 11 | } 12 | ``` 13 | 14 | ```c++ 15 | int max(int num1, int num2) 16 | { 17 | // 局部变量声明 18 | int result; 19 | 20 | if (num1 > num2) 21 | result = num1; 22 | else 23 | result = num2; 24 | 25 | return result; 26 | } 27 | ``` 28 | 29 | * 参数默认值 30 | 31 | 定义一个函数时可以给形参指定一个匹配类型的默认值 32 | 33 | 当调用函数时,如果实参的值留空,则使用这个默认值 34 | 35 | ```c++ 36 | int sum(int a, int b = 20) 37 | { 38 | int result; 39 | 40 | result = a + b; 41 | 42 | return (result); 43 | } 44 | ``` 45 | 46 | * Lambda函数 47 | 48 | C++11 提供了对匿名函数的支持,称为 `Lambda 函数`(也叫 `Lambda 表达式`) 49 | 50 | Lambda 表达式把函数看作对象 51 | 52 | ```c++ 53 | //有返回值得lambda 54 | [capture](parameters)->return-type{body} 55 | // 56 | [](int x, int y){ return x < y ; } 57 | ``` 58 | 59 | ```c++ 60 | //无返回值的lambda 61 | [capture](parameters){body} 62 | // 63 | []{ ++global_x; } 64 | ``` -------------------------------------------------------------------------------- /c++/intro.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 3 | C++ 是一种静态类型的、编译式的、通用的、大小写敏感的、不规则的编程语言,支持过程化编程、面向对象编程和泛型编程。 4 | 5 | C++ 被认为是一种中级语言,它综合了高级语言和低级语言的特点。 6 | 7 | C++ 是由 Bjarne Stroustrup 于 1979 年在新泽西州美利山贝尔实验室开始设计开发的。C++ 进一步扩充和完善了 C 语言,最初命名为带类的C,后来在 1983 年更名为 C++。 8 | 9 | C++ 是 C 的一个超集,事实上,任何合法的 C 程序都是合法的 C++ 程序。 10 | 11 | 注意:使用静态类型的编程语言是在编译时执行类型检查,而不是在运行时执行类型检查。 12 | 13 | ## HelloWorld 14 | 15 | ```c++ 16 | //导入库里面头文件 17 | #include 18 | //使用std的命名空间 19 | using namespace std; 20 | 21 | //main主函数 22 | int main(int argc, char const *argv[]) 23 | { 24 | //在标准输入流输入 字符串, endl标志结尾 25 | cout << "hello c++" << endl; 26 | return 0; 27 | } 28 | ``` 29 | 30 | c++同样要以`;`标志每行语句结束 -------------------------------------------------------------------------------- /c++/namespace.md: -------------------------------------------------------------------------------- 1 | ## 命名空间 2 | 3 | 命名空间使用`namespace`关键字定义 4 | 5 | ```c++ 6 | namespace namespace_name { 7 | // 代码声明 8 | } 9 | 10 | name::code; // code 可以是变量或函数 11 | // 12 | std::cout; 13 | std::endl; 14 | ``` 15 | 16 | 可以使用`using`指令告诉后续代码使用指定的命名空间,简化调用 17 | 18 | ```c++ 19 | #include 20 | 21 | using namespace std; 22 | // 第一个命名空间 23 | namespace first_space{ 24 | void func(){ 25 | cout << "Inside first_space" << endl; 26 | } 27 | } 28 | // 第二个命名空间 29 | namespace second_space{ 30 | void func(){ 31 | cout << "Inside second_space" << endl; 32 | } 33 | } 34 | //使用第一个命名空间 35 | using namespace first_space; 36 | 37 | int main () 38 | { 39 | 40 | // 调用第一个命名空间中的函数 41 | func(); 42 | 43 | return 0; 44 | } 45 | ``` 46 | 47 | 命名空间可以定义在几个不同的部分中,下面的命名空间定义可以是定义一个新的命名空间,也可以是为已有的命名空间增加新的元素: 48 | 49 | ```c++ 50 | namespace namespace_name { 51 | // 代码声明 52 | } 53 | ``` 54 | 55 | 命名空间可以嵌套,可以在一个命名空间中定义另一个命名空间 56 | 57 | ```c++ 58 | namespace namespace_name1 { 59 | // 代码声明 60 | namespace namespace_name2 { 61 | // 代码声明 62 | } 63 | } 64 | ``` -------------------------------------------------------------------------------- /c++/new_delete.md: -------------------------------------------------------------------------------- 1 | ## 动态内存 2 | 3 | C++ 程序中的内存分为两个部分: 4 | 5 | * `栈`:在函数内部声明的所有变量都将占用栈内存 6 | * `堆`:在程序运行时可动态申请的内存空间 7 | 8 | 在c++中使用`new`关键字动态分配内存,使用`delete`关键字删除之前分配的内存,这两个关键字一般都是`成对出现`的。 9 | 10 | ```c++ 11 | #include 12 | using namespace std; 13 | 14 | int main () 15 | { 16 | double* pvalue = NULL; // 初始化为 null 的指针 17 | pvalue = new double; // 为变量请求内存 18 | 19 | *pvalue = 29494.99; // 在分配的地址存储值 20 | cout << "Value of pvalue : " << *pvalue << endl; 21 | 22 | delete pvalue; // 释放内存 23 | 24 | return 0; 25 | } 26 | ``` 27 | 28 | 数组的动态内存分配 29 | 30 | ```c++ 31 | char* pvalue = NULL; // 初始化为 null 的指针 32 | pvalue = new char[20]; // 为变量请求内存 33 | 34 | delete [] pvalue; // 删除 pvalue 所指向的数组 35 | ``` 36 | 37 | c语言中的`malloc`函数在c++依然适用,但是在c++中还是使用c++的特性比较好,就像能用`class`的地方就最好不用`struct`。 -------------------------------------------------------------------------------- /c++/pointer.md: -------------------------------------------------------------------------------- 1 | ## 指针 2 | 3 | `指针`就是存储另一个变量的`内存地址`的`变量` 4 | 5 | ```c++ 6 | type *var-name; 7 | 8 | int *ip; /* 一个整型的指针 */ 9 | double *dp; /* 一个 double 型的指针 */ 10 | float *fp; /* 一个浮点型的指针 */ 11 | char *ch; /* 一个字符型的指针 */ 12 | ``` 13 | 14 | ```c++ 15 | #include 16 | 17 | using namespace std; 18 | 19 | int main () 20 | { 21 | int var = 20; // 实际变量的声明 22 | int *ip; // 指针变量的声明 23 | 24 | ip = &var; // 在指针变量中存储 var 的地址 25 | 26 | cout << "Value of var variable: "; 27 | cout << var << endl; 28 | 29 | // 输出在指针变量中存储的地址 30 | cout << "Address stored in ip variable: "; 31 | cout << ip << endl; 32 | 33 | // 访问指针中地址的值 34 | cout << "Value of *ip variable: "; 35 | cout << *ip << endl; 36 | 37 | return 0; 38 | } 39 | ``` -------------------------------------------------------------------------------- /c++/reference.md: -------------------------------------------------------------------------------- 1 | ## Reference 2 | 3 | * https://www.runoob.com/cplusplus/cpp-intro.html 4 | * http://c.biancheng.net/cplus/ 5 | * <> -------------------------------------------------------------------------------- /c++/refers.md: -------------------------------------------------------------------------------- 1 | ## 引用 2 | 3 | `引用`是一个别名,也就是说,它是某个`已存在变量`的另一个名字。 4 | 5 | 一旦把引用初始化为某个变量,就可以使用`该引用名称`或`变量名称`来指向这个变量。 6 | 7 | ## 引用和指针区别 8 | 9 | * 不存在空引用。引用必须连接到一块合法的内存。 10 | 11 | * 一旦引用被初始化为一个对象,就不能被指向到另一个对象。指针可以在任何时候指向到另一个对象。 12 | * 引用必须在创建时被初始化。指针可以在任何时间被初始化。 13 | 14 | ```c++ 15 | #include 16 | 17 | using namespace std; 18 | 19 | int main () 20 | { 21 | // 声明简单的变量 22 | int i; 23 | double d; 24 | 25 | // 声明引用变量 26 | int& r = i; 27 | double& s = d; 28 | 29 | i = 5; 30 | cout << "Value of i : " << i << endl; 31 | cout << "Value of i reference : " << r << endl; 32 | 33 | d = 11.7; 34 | cout << "Value of d : " << d << endl; 35 | cout << "Value of d reference : " << s << endl; 36 | 37 | return 0; 38 | } 39 | ``` 40 | 41 | `引用`通常用于`函数形参`和`函数返回值`。 -------------------------------------------------------------------------------- /c++/string.md: -------------------------------------------------------------------------------- 1 | ## 字符串 2 | 3 | * c-style字符串 4 | * string类字符串 5 | 6 | ```c++ 7 | char * str = "abcd"; 8 | char str1[6] = {'H', 'e', 'l', 'l', 'o', '\0'}; 9 | ``` 10 | 11 | ```c++ 12 | #include 13 | #include 14 | 15 | int main(int argc, char const *argv[]) 16 | { 17 | std::string a = "hello string"; 18 | std::cout << a << std::endl; 19 | 20 | const char * c_str = a.c_str(); 21 | printf("c_str == %s",c_str); 22 | 23 | return 0; 24 | } 25 | ``` -------------------------------------------------------------------------------- /c++/struct.md: -------------------------------------------------------------------------------- 1 | ## 结构体 2 | 3 | 和c语言的中的结构相似,但是c++中的结构可以直接在结构体中添加函数。 4 | 5 | ```c++ 6 | struct Books 7 | { 8 | char title[50]; 9 | char author[50]; 10 | char subject[100]; 11 | int book_id; 12 | } book; 13 | ``` -------------------------------------------------------------------------------- /c++/template.md: -------------------------------------------------------------------------------- 1 | ## 模板(泛型) 2 | 3 | 模板是泛型编程的基础,我们可以使用模板来定义函数和类。所以c++中有两种模板 4 | 5 | * `模板类` 6 | * `模板函数` 7 | 8 | ```c++ 9 | #include 10 | 11 | using namespace std; 12 | 13 | template void Swap(T &a, T &b){ 14 | T temp = a; 15 | a = b; 16 | b = temp; 17 | } 18 | 19 | int main(){ 20 | //交换 int 变量的值 21 | int n1 = 100, n2 = 200; 22 | Swap(n1, n2); 23 | cout< 36 | using namespace std; 37 | 38 | template //这里不能有分号 39 | class Point{ 40 | public: 41 | Point(T1 x, T2 y): m_x(x), m_y(y){ } 42 | public: 43 | T1 getX() const; //获取x坐标 44 | void setX(T1 x); //设置x坐标 45 | T2 getY() const; //获取y坐标 46 | void setY(T2 y); //设置y坐标 47 | private: 48 | T1 m_x; //x坐标 49 | T2 m_y; //y坐标 50 | }; 51 | 52 | template //模板头 53 | T1 Point::getX() const /*函数头*/ { 54 | return m_x; 55 | } 56 | 57 | template 58 | void Point::setX(T1 x){ 59 | m_x = x; 60 | } 61 | 62 | template 63 | T2 Point::getY() const{ 64 | return m_y; 65 | } 66 | 67 | template 68 | void Point::setY(T2 y){ 69 | m_y = y; 70 | } 71 | 72 | int main(){ 73 | Point p1(10, 20); 74 | cout<<"x="< 38 | 39 | int main(int argc, char const *argv[]) 40 | { 41 | int arr[5] = {1, 2, 3, 4, 5}; 42 | int size = sizeof(arr) / sizeof(int); 43 | printf("arr size == %d\n", size);//arr size == 5 44 | return 0; 45 | } 46 | ``` 47 | 48 | ## 只读数组 49 | 50 | * 有时需要把数组设置成只读,这样,程序只能在数组中检索元素,不能将新值写入数组。 51 | * 要创建只读数组,应该使用`const`声明和初始化数组。 52 | 53 | ```c 54 | const int days[] = {1,2,3,4,5,6,7}; 55 | ``` 56 | 57 | ## 指定初始化器(C99) 58 | 59 | * C99增加了一个新特性:指定初始化器(designnated initializer),利用该特性可以初始化指定的数组元素。 60 | 61 | ```c 62 | int arr[3] = {1,2,3}; //传统的语句 63 | int arr[3] = {[2] = 3} //把arr[2]初始化为3 64 | ``` 65 | 66 | 在初始化一个元素后,未初始化的元素都会被设置为0。 67 | 68 | ## 多维数组 69 | 70 | ```c 71 | const int days[12][31] = 72 | { 73 | {1,2,3,...,31}, 74 | {1,2,3,4,...,28} 75 | .... 76 | } 77 | ``` 78 | 79 | ## 指针和数组 80 | 81 | * 数组名是数组元素的地址。例如`arr = &arr[0]`。 82 | * 在C语言中,`arr[i]`和`*(arr+i)`这两个表达式是等价的。 -------------------------------------------------------------------------------- /c/bit_operation.md: -------------------------------------------------------------------------------- 1 | # 位运算 2 | 3 | * 计算机最基本的存储单元。 4 | * 位是数据存储的最小的单元,且只可能有两个值:`0`和`1`。 5 | * 位运算只能用于整形:char,int和long。 6 | 7 | ### 移位运算符 8 | 9 | | 运算符 | 描述 | 10 | | ------ | ---------- | 11 | | `<<` | 左移运算符 | 12 | | `>>` | 右移运算符 | 13 | 14 | 在某事情况下,使用移位运算符可以将整数变量乘以和除以2的n次方。 15 | 16 | 整数左移n位相当于将该整数乘以2的n次方。 17 | 18 | 整数右移n位相当于将该整数除以2的n次方。 19 | 20 | ```c 21 | #include 22 | 23 | int main(int argc, char const *argv[]) 24 | { 25 | int a = 8; 26 | a = a << 1; //8*2的一次方 27 | printf("%d\n", a); //16 28 | a = a << 2; //8*2的二次方 29 | printf("%d\n", a); //32 30 | 31 | int b = 8; 32 | b = b >> 1; //8 / 2的一次方 33 | printf("%d\n", b); //4 34 | b = b >> 2; //8 / 2的一次方 35 | printf("%d\n", b); //1 36 | return 0; 37 | } 38 | ``` 39 | 40 | ### 按位逻辑运算符 41 | 42 | 按位逻辑运算符也属于二元运算符,根据两个运算对象对应的位,将结果的位设置为0或1。 43 | 44 | | 运算符 | 操作 | 描述 | 45 | | ------ | ---------- | ------------------------------------------------------------ | 46 | | `&` | 按位`与` | 只有当两个运算对象对应位都为1时,才将位结果设置为1;否则为0。**按位与**运算符用于关闭和清除值中的一个或多个位。 | 47 | | `|` | 按位`或` | 只有当两个运算对象对应位都为0时,才将位结果设置为0;否则为1。**按位或**运算符用于打开和设置值中的一个或多个位。 | 48 | | `^` | 按位`异或` | 只有当两个运算对象相应的位不同时(即,一个是1,一个是0),**按位异或**才将位的结果设置为1;否则为0。 | 49 | 50 | ### 求反运算符 51 | 52 | 求反运算符也是一元运算符,求反运算符用于把运算对象的每一位反转,即所有的0变成1,所有的1变成0。 53 | 54 | ```c 55 | 254 -> 二进制是1111110 56 | ~254 //对254求反等于1 57 | 1 -> 0000001 58 | ``` -------------------------------------------------------------------------------- /c/comment.md: -------------------------------------------------------------------------------- 1 | # 注释 2 | 3 | ```c 4 | //注释,这是C99新增的 5 | 6 | /* 单行注释 */ 7 | 8 | /* 9 | 多行注释 10 | 多行注释 11 | 多行注释 12 | */ 13 | ``` -------------------------------------------------------------------------------- /c/const.md: -------------------------------------------------------------------------------- 1 | # 常量 2 | 3 | `常量(constant)`与`变量(variable)`不同,存储在常量中的值在程序执行期间不可改变。这些固定的值,又叫做`字面量`。 4 | 5 | 在C中有两种方式定义常量 6 | 7 | 1. 使用 `#define` 预处理器 8 | 2. 使用 `const` 关键字,C90新增的,用于限定一个变量为只读。 9 | 10 | * 使用`#defind`定义的常量会在编译时全部替换成实际值,这个过程被称为`编译时替换(compile-time substitution)`。 11 | * 这样定义的常量也被称为`明示常量(manifest constant)` 12 | 13 | ```c 14 | #include 15 | 16 | #define PI 3.14 17 | 18 | int main(int argc, char const *argv[]) 19 | { 20 | printf("PI == %f\n", PI); 21 | //PI = 3.15; error: expression is not assignable 22 | return 0; 23 | } 24 | ``` 25 | 26 | ```c 27 | #include 28 | 29 | const double PI = 3.14; 30 | 31 | int main(int argc, char const *argv[]) 32 | { 33 | printf("PI == %f\n",PI); 34 | //PI = 3.15; error: cannot assign to variable 'PI' with const-qualified type 'const double' 35 | return 0; 36 | } 37 | ``` 38 | 39 | 注:把常量定义为大写字母形式,是一种很好的编程习惯 -------------------------------------------------------------------------------- /c/enum.md: -------------------------------------------------------------------------------- 1 | # 枚举 2 | 3 | 枚举是 C 语言中的一种基本数据类型,它可以让数据更简洁,更易读。 4 | 5 | ## 定义枚举 6 | 7 | ```c 8 | enum 枚举名 9 | { 10 | 枚举元素, 11 | 枚举元素, 12 | 枚举元素, 13 | ... 14 | } 15 | ``` 16 | 17 | 第一个枚举成员的默认值为整型的 0,后续枚举成员的值在前一个成员上加 1。 18 | 19 | ```c 20 | #include 21 | 22 | enum Color 23 | { 24 | red, 25 | blue 26 | }; 27 | 28 | int main(int argc, char const *argv[]) 29 | { 30 | enum Color color; 31 | color = red; 32 | printf("corlor == %d\n", color);//corlor == 0 33 | color = blue; 34 | printf("corlor == %d\n", color);//corlor == 1 35 | return 0; 36 | } 37 | ``` 38 | 39 | 在C 语言中,枚举类型是被当做 int 或者 unsigned int 类型来处理的。 40 | 41 | ## 自定义枚举元素的值 42 | 43 | ```c 44 | #include 45 | 46 | enum Color 47 | { 48 | red = 10, 49 | blue = 22 50 | }; 51 | 52 | int main(int argc, char const *argv[]) 53 | { 54 | enum Color color; 55 | color = red; 56 | printf("corlor == %d\n", color); //corlor == 10 57 | color = blue; 58 | printf("corlor == %d\n", color); //corlor == 22 59 | return 0; 60 | } 61 | ``` -------------------------------------------------------------------------------- /c/flow_control.md: -------------------------------------------------------------------------------- 1 | # 流程控制 2 | 3 | * 花括号`{}`以及被花括号括起来的部分被称为`快(block)` 4 | 5 | ## if语句 6 | 7 | * if语句被称为`分支语句(branching statement)`或`选择语句(selection statement)` 8 | 9 | ```c 10 | int main() 11 | { 12 | int a = 5; 13 | if(a < 3) 14 | { 15 | //... 16 | }else if(a < 4) 17 | { 18 | //... 19 | }else 20 | { 21 | 22 | } 23 | } 24 | ``` 25 | 26 | ## switch-case多重选择 27 | 28 | ```c 29 | int age = 20; 30 | switch(age) 31 | { 32 | case 1: 33 | break; 34 | case 10: 35 | case 11://多重标签写法 36 | break; 37 | default: 38 | 39 | } 40 | ``` 41 | 42 | ## while循环 43 | 44 | * while语句是一种迭代语句,有时也被称为结构化语句,因为它的结构比简单的赋值表达式语句复杂。 45 | * 使用`break`关键字退出循环。 46 | * 使用`continue`关键字执行下一次循环。 47 | 48 | ```c 49 | int a = 1; 50 | while(a < 5) 51 | { 52 | a++; 53 | printf("a = %d", a); 54 | if(a > 3) 55 | break; 56 | else 57 | continue; 58 | } 59 | printf("while end"); 60 | ``` 61 | 62 | * `a < 5`是while表达式的`入口条件(entry condition)` 63 | 64 | ## do-while语句 65 | 66 | * do-while语句至少必须先执行一次循环。 67 | 68 | ```c 69 | do { 70 | //提示用户输入密码 71 | //读取用户输入的密码 72 | }while(用户输入的密码不等于密码) 73 | ``` 74 | 75 | ## for循环 76 | 77 | ```c 78 | int count; 79 | for(count = 1; count <= 22; count++) 80 | { 81 | printf("count = %d", count); 82 | } 83 | ``` 84 | 85 | ## 嵌套循环 86 | 87 | * `嵌套循环(nested loop)`指在一个循环内包含另一个循环。 88 | * 算法里经常用到嵌套循环 89 | 90 | ## goto语句 91 | 92 | * `K&R`建议`谨慎使用,或者根本不用`goto语句,因为不使用goto语句也能实现同样的代码逻辑。 -------------------------------------------------------------------------------- /c/func.md: -------------------------------------------------------------------------------- 1 | # 函数 2 | 3 | - `函数(function)`是完成特定任务的独立程序代码单元。 4 | - 函数是一组一起执行一个任务的语句。每个 C 程序都至少有一个函数,即主函数 `main()`。 5 | - 没有返回值的函数,函数返回值类型用关键字`void`标明。 6 | - 把函数原型和已定义的字符常量放在头文件是一个良好的编程习惯。 7 | 8 | ```c 9 | #include //导入系统的头文件 10 | #include "custom.h" //导入自定义的头文件 11 | ``` 12 | 13 | ```c 14 | 返回类型 函数名(参数列表) 15 | { 16 | //一系列执行语句 17 | } 18 | ``` 19 | 20 | ```c 21 | int max(int num1, int num2) 22 | { 23 | int result; 24 | if(num1 > num2) 25 | { 26 | result = num1; 27 | }else 28 | { 29 | result = num2; 30 | } 31 | return result; 32 | } 33 | ``` 34 | 35 | - `形式参数(形参)`是函数中存储值得变量,`实际参数(实参)`是传递给函数的特定值。 36 | - 形参(formal argument 或 formal parameter),实参(actual argument 或 actual parameter) 37 | 38 | ## 函数声明 39 | 40 | ```c 41 | //sum.h 42 | int sum(int a, int b); 43 | ``` 44 | 45 | - 函数声明(function declaration)也叫函数原型,函数原型指明了函数的属性。 46 | - 函数声明一般定义在头文件中 47 | 48 | ## 函数实现 49 | 50 | ```c 51 | //sum.c 52 | #include "sum.h" //导入函数原型的头文件 53 | 54 | int sum(int a, int b){ 55 | return a + b; 56 | } 57 | ``` 58 | 59 | ## 递归 60 | 61 | - C 语言允许函数调用自己,这种调用过程称为`递归(recursion)`。 62 | - 递归函数必须有一个`终止递归的条件`,不然救护变成无限递归。 63 | - 循环通常都可以用递归代替,递归方案更简洁,但效率大多都没循环高。 64 | 65 | ```c 66 | int main(void) 67 | { 68 | recurstion(1); 69 | } 70 | 71 | void recurstion(int n) 72 | { 73 | if(n < 4) 74 | { 75 | recurstion(n + 1) 76 | } 77 | } 78 | ``` 79 | 80 | ## 尾递归 81 | 82 | - 最简单的递归形式是把递归调用置于函数的末尾,即正好在 return 语句之前,这种形式的递归称为`尾递归(tail recustion)`,因为递归调用在函数的末尾。 83 | - 尾递归是最简单的递归形式,因为它相当于循环。 84 | 85 | ```c 86 | long rfact(int n) 87 | { 88 | long ans; 89 | 90 | if(n > 0) 91 | ans = n * rfact(n - 1); 92 | else 93 | ans = 1; 94 | 95 | return ans; 96 | } 97 | ``` 98 | 99 | - 能用循环就少用递归,但是递归更容易阅读。 100 | - 每次递归都会创建一组变量,所以递归使用的内存更多。 101 | - 递归每次调用都会吧创建的一组新变量放在栈中,递归调用的次数受限于内存空间。 102 | -------------------------------------------------------------------------------- /c/intro.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | 3 | * C 语言是一种通用的、面向过程式的计算机程序设计语言。 4 | * 1972 年,为了移植与开发 UNIX 操作系统,丹尼斯·里奇在贝尔电话实验室设计开发了 C 语言。 5 | * C 语言是一种广泛使用的计算机语言,它与 Java 编程语言一样普及,二者在现代软件程序员之间都得到广泛使用。 6 | 7 | 8 | ## HelloWorld 9 | 10 | ```c 11 | #include // 预处理指令,包含另一个文件 12 | 13 | int main() //入口方法,第一个被调用的函数 14 | { 15 | printf("Hello, World! \n"); //输出语句 16 | 17 | return 0; //函数返回值 18 | } 19 | ``` 20 | 21 | * `#incluce`是一条C预处理指令(preprocessor directive)。 22 | * 通常,C编译器在编译前会对源代码做一些准备工作,即`预处理(preprocessing)` 23 | * 这种在C程序顶部的信息结合被称为`头文件(header)`,通常以`.h`结尾 -------------------------------------------------------------------------------- /c/operator.md: -------------------------------------------------------------------------------- 1 | # 运算符 2 | 3 | * C语言用`运算符(operator)`表示算术运算。 4 | * 只需要一个运算对象的运算符(如负号和sizeof)称为`一元运算符(unary operator)`。 5 | * 需要两个运算对象的运算符(如加法和乘法运算符)称为`二元运算符()`。 6 | * `sizeof`也属于运算符。 7 | 8 | 9 | * 一元运算符 10 | * 赋值运算符 `=` 11 | * 符号运算符 `-`和`+`,这里表示的是负数和正数 12 | * 二元运算符 13 | * 加法运算符 `+` 14 | * 减法运算符 `-` 15 | * 乘法运算符 `*` 16 | * 除法运算符 `/` 17 | * 求模运算符 `%s` 18 | * 递增运算符 `++` 19 | * 递减运算符 `--` 20 | * 相等运算符(equality operator) `==` 21 | 22 | 23 | ## 运算符优先级 24 | 25 | 运算符优先级和数学中的中的类似,先括号,再乘除,最后加减。 26 | 27 | ## 逻辑运算符 28 | 29 | * `&&` - `与`(and) 30 | * `||` - `或`(or) 31 | * `!` - `非`(not) 32 | 33 | 假设`exp1`和`exp2`是两个简单的表达式(如car > rat或debt = 1000),那么: 34 | 35 | * 当且仅当`exp1和exp2`都为真是,`exp1 && exp2`才为真 。 36 | * 如`exp1或exp2`为真,`exp1 || exp2`为真。 37 | * 如果exp1为真,则`!exp1`为真,如果exp1为真,则`!exp1`为假。 38 | 39 | ## 条件运算符(?:) 40 | 41 | * `条件运算符(conditional expression)`又称为`三元运算符`,因为它是C语言中唯一的带三个运算对象的表达式。 42 | 43 | ```c 44 | // exp1 ? exp2 : exp3; 45 | x = (y < 0) ? -y : y; 46 | ``` 47 | 48 | 49 | -------------------------------------------------------------------------------- /c/pointer.md: -------------------------------------------------------------------------------- 1 | # 指针 2 | 3 | * `指针(pointer)`是存储其他变量`地址`的变量。 4 | 5 | ## 声明指针 6 | 7 | ```c 8 | 类型名 *指针名; 9 | ``` 10 | 11 | * `星号(*)`是`间接运算符(indirection operator)`,表明指针名是一个指向类型名类型的指针,不是类型名类型的变量。 12 | * 该运算符有时也被称为`解引用运算符(dereferencing operator)`。 13 | * 在指针前面使用`*运算符`可以得到该指针所指对象的值。 14 | 15 | ```c 16 | int *a; 17 | ``` 18 | 19 | ## 初始化指针 20 | 21 | ```c 22 | 指针 = &变量; 23 | ``` 24 | 25 | ```c 26 | int b = 10; 27 | a = &b; 28 | ``` 29 | 30 | * `取址运算符(&)`获取变量的内存地址,并将其放入指针变量中。 31 | * 通过变量名访问变量的内容,称之为`直接访问(direct access)` 32 | * 通过指向变量的指针访问变量的内容,称为`间接访问(indirect)`或`间接取值(indirecion)` 33 | * `指针名`输出的是指向变量的内存地址,`*指针名`输出的指向变量存储的值。 34 | * 内存中每个字节都有唯一的地址,因此,多字节变量实际占用了多个地址,变量的地址是它占用字节的首地址(最低位的地址) 35 | 36 | ## 函数指针 37 | 38 | * 函数指针是指向函数的指针变量。 39 | 40 | ```c 41 | #include 42 | 43 | void (*add)(int, int); 44 | 45 | void addImp(int x, int y) 46 | { 47 | printf("sum == %d\n", x + y); 48 | } 49 | 50 | int main(int argc, char const *argv[]) 51 | { 52 | add = &addImp; 53 | add(2, 3); 54 | return 0; 55 | } 56 | ``` 57 | 58 | 输出: 59 | 60 | ```c 61 | sum == 5 62 | ``` 63 | 64 | ## 空指针 65 | 66 | 在变量声明的时候,如果没有确切的地址可以赋值,为指针变量赋一个 NULL 值是一个良好的编程习惯。 67 | 68 | 赋为 NULL 值的指针被称为**空**指针。 69 | 70 | NULL 指针是一个定义在标准库中的值为零的常量。 71 | 72 | ```c 73 | #include 74 | 75 | int main(int argc, char const *argv[]) 76 | { 77 | int *pointNull = NULL; 78 | printf("pointNull 的地址是 %p\n", pointNull);//pointNull 的地址是 0x0 79 | return 0; 80 | } 81 | ``` 82 | 83 | ## void指针 84 | 85 | void指针泛指为通用指针(generic pointer),也可以称为泛型指针,即指向任意数据对象类型的指针。 86 | 87 | ```c 88 | void *指针名; 89 | ``` 90 | 91 | void指针最常见的用途就是声明函数的参数。如果希望一个函数能处理不同类型的参数,便可将void指针作为函数的参数。 92 | 93 | 要使用void指针必须使用**强制类型转换** 94 | 95 | ```c 96 | (type *)指针名; 97 | ``` 98 | 99 | ```c 100 | #include 101 | 102 | void printVoid(void *value, int position) 103 | { 104 | switch (position) 105 | { 106 | case 1: 107 | printf("value == %d\n", *((int *)value)); 108 | break; 109 | case 2: 110 | printf("value == %ld\n", *((long *)value)); 111 | break; 112 | case 3: 113 | printf("value == %f\n", *((float *)value)); 114 | break; 115 | } 116 | } 117 | 118 | int main(int argc, char const *argv[]) 119 | { 120 | int a = 10; 121 | printVoid(&a, 1); 122 | long b = 110; 123 | printVoid(&b, 2); 124 | float c = 3.14; 125 | printVoid(&c, 3); 126 | return 0; 127 | } 128 | ``` 129 | 130 | 输出结果: 131 | 132 | > value == 10 133 | > value == 110 134 | > value == 3.140000 -------------------------------------------------------------------------------- /c/reference.md: -------------------------------------------------------------------------------- 1 | # 参考 2 | 3 | * [菜鸟教程](https://www.runoob.com/cprogramming/c-tutorial.html) 4 | * 《21天学会C语言程序设计-第7版》 5 | * 《C程序设计语言》 6 | * 《C Primer Plus-第6版》 7 | 8 | -------------------------------------------------------------------------------- /c/string.md: -------------------------------------------------------------------------------- 1 | # 字符串 2 | 3 | * `字符串(character string)`是一个或多个字符的序列。 4 | * 在 C 语言中,字符串实际上是使用`空字符(null character)`,也就是`\0`终止的一维字符数组。 5 | * 空字符不是数字0,它是非打印字符。 6 | 7 | ```c 8 | char hello[6] = {'h','e','l','l','o','\0'}; 9 | ``` 10 | 11 | 其实,不需要把`null`字符放在字符串常量的末尾。C 编译器会在初始化数组时,自动把`\0`放在字符串的末尾。 12 | 13 | ```c 14 | char hello[] = "hello"; 15 | ``` 16 | 17 | 还可以使用指针来初始化字符串 18 | 19 | ```c 20 | char *hello = "hello"; 21 | ``` 22 | 23 | C语言中有大量操作字符串的函数,都放在`string.h`头文件中 24 | 25 | | 函数 | 描述 | 26 | | :------------------ | ------------------------------------------------------------ | 27 | | strcpy(s1, s2); | 复制字符串 s2 到字符串 s1 | 28 | | strcat(s1, s2); | 连接字符串 s2 到字符串 s1 的末尾 | 29 | | strlen(s1); | 返回字符串 s1 的长度 | 30 | | strcmp(s1, s2); | 如果 s1 和 s2 是相同的,则返回 0;如果 s1s2 则返回大于 0 | 31 | | strchr(s1, ch); | 返回一个指针,指向字符串 s1 中字符 ch 的第一次出现的位置 | 32 | | strstr(s1, s2); | 返回一个指针,指向字符串 s1 中字符串 s2 的第一次出现的位置 | 33 | 34 | ```c 35 | #include 36 | #include 37 | 38 | int main(int argc, char const *argv[]) 39 | { 40 | char str1[12] = "hello"; 41 | char str2[12] = "world"; 42 | 43 | //复制字符串 44 | char str3[12]; 45 | strcpy(str3, str1); 46 | printf("%s\n", str3); //hello 47 | //连接字符串 48 | strcat(str1, str2); 49 | printf("%s\n", str1); //helloworld 50 | return 0; 51 | } 52 | ``` 53 | 54 | ```c 55 | #include 56 | #include 57 | 58 | int main(int argc, char const *argv[]) 59 | { 60 | char hello[] = "hello"; 61 | printf("%s\n", hello);//hello 62 | 63 | printf("str len == %lu\n",strlen(hello));//str len == 5 64 | 65 | int realLen = sizeof(hello) / sizeof(char); 66 | printf("realLen == %d\n",realLen);//realLen == 6 67 | return 0; 68 | } 69 | ``` 70 | 71 | ```c 72 | #include 73 | 74 | int main(int argc, char const *argv[]) 75 | { 76 | char *str = "hello"; 77 | printf("str == %s\n", str);//hello 78 | 79 | //用指针表示的字符串不能修改,但是用字符数组的可以修改 80 | //str[0] = 'w';//bus error 81 | //printf("str == %s\n", str); 82 | char strArr[] = "hello"; 83 | strArr[0] = 'w'; 84 | printf("&strArr == %s\n",strArr);//wello 85 | 86 | char *str1 = "hello"; 87 | printf("&str == %p\n",&str);//0x7ffee88f4a08 88 | printf("&str1 == %p\n",&str1);//0x7ffee88f4a00 89 | return 0; 90 | } 91 | ``` -------------------------------------------------------------------------------- /c/struct.md: -------------------------------------------------------------------------------- 1 | # 结构体 2 | 3 | ```c 4 | struct Preson{ 5 | char* name; 6 | int age; 7 | }; 8 | 9 | int main() 10 | { 11 | struct Person person; 12 | person.age = 25; 13 | printf("%d\n", person.age);//25 14 | } 15 | ``` 16 | 17 | * 结构体括号结尾要带上分号`;` 18 | 19 | ## typedef简写结构体 20 | 21 | ```c 22 | typedef struct 23 | { 24 | char* name; 25 | int age; 26 | } Person; 27 | 28 | //或 29 | typedef struct _Person 30 | { 31 | char* name; 32 | int age; 33 | } Person; 34 | 35 | int main() 36 | { 37 | Person person; 38 | person.age = 25; 39 | printf("%d\n", person.age);//25 40 | } 41 | ``` 42 | 43 | ## 结构体指针 44 | 45 | ```c 46 | #include 47 | 48 | typedef struct _Person 49 | { 50 | char *name; 51 | } Person; 52 | 53 | int main(int argc, char const *argv[]) 54 | { 55 | Person *p; 56 | Person person; 57 | person.name = "zhang san"; 58 | printf("%s\n", person.name); 59 | p = &person; 60 | //两种方式访问结构指针的值 61 | p->name = "li si"; 62 | printf("%s\n", (*p).name); 63 | return 0; 64 | } 65 | ``` 66 | 67 | 结构体作为函数参数 68 | 69 | 1. 直接传递结构体给函数 70 | 71 | ```c 72 | typedef struct _Person 73 | { 74 | char *name; 75 | } Person; 76 | 77 | void fun1(Person person); 78 | 79 | int main(int argc, char const *argv[]) 80 | { 81 | Person p; 82 | p.name = "zhang san"; 83 | printf("start -- %s\n", p.name); 84 | fun1(p); 85 | printf("end --%s\n", p.name); 86 | return 0; 87 | } 88 | 89 | void fun1(Person p) 90 | { 91 | p.name = "li si"; 92 | } 93 | ``` 94 | 95 | > start -- zhang san 96 | > end --zhang san 97 | 98 | 2. 传递结构体指针给函数 99 | 100 | ```c 101 | #include 102 | 103 | typedef struct _Person 104 | { 105 | char *name; 106 | } Person; 107 | 108 | void fun2(Person *person); 109 | 110 | int main(int argc, char const *argv[]) 111 | { 112 | Person p; 113 | p.name = "zhang san"; 114 | printf("start -- %s\n", p.name); 115 | fun2(&p); 116 | printf("end --%s\n", p.name); 117 | return 0; 118 | } 119 | 120 | void fun2(Person *p) 121 | { 122 | p->name = "li si"; 123 | } 124 | ``` 125 | 126 | > start -- zhang san 127 | > end --li si 128 | 129 | ## 结构体长度 130 | 131 | 结构体的长度一般为结构中字段长度的总和。 132 | 133 | ```c 134 | #include 135 | 136 | typedef struct _Person 137 | { 138 | int age; 139 | } Person; 140 | 141 | int main(int argc, char const *argv[]) 142 | { 143 | Person p; 144 | p.age = 18; 145 | printf("%lu\n", sizeof(p)); 146 | return 0; 147 | } 148 | ``` 149 | 150 | ## const的结构指针 151 | 152 | const后的指针不能修改所指向地址的值,结构指针也是一样。但是可以重新指向其他的地址。 153 | 154 | ```c 155 | #include 156 | 157 | int main(int argc, char const *argv[]) 158 | { 159 | const int *p; 160 | int a = 10; 161 | p = &a; 162 | printf("%d\n", *p);//10 163 | 164 | *p = 11;//编译报错 error: read-only variable is not assignable 165 | 166 | int b = 12; 167 | p = &b; 168 | printf("%d\n", *p);//12 169 | 170 | return 0; 171 | } 172 | ``` 173 | 174 | ## 结构体增加函数 175 | 176 | ```c 177 | #include 178 | 179 | typedef struct 180 | { 181 | void (*eat)(); 182 | } Person; 183 | 184 | void eat() 185 | { 186 | printf("%s\n", "每次多吃一粒米"); 187 | } 188 | 189 | int main(int argc, char const *argv[]) 190 | { 191 | Person p; 192 | p.eat = &eat; 193 | p.eat(); 194 | 195 | //指针方式 196 | // Person *p1; 197 | // p1 = &p; 198 | // p1->eat = &eat; 199 | // p1->eat(); 200 | return 0; 201 | } 202 | ``` -------------------------------------------------------------------------------- /c/type.md: -------------------------------------------------------------------------------- 1 | # 数据类型 2 | 3 | * 计算机中最小的储存单元是`位(bit)`,可以存储0或1. 4 | * `字节(byte)`是常用的计算机储存单位,对于几乎所有的机器,`1字节均为8位`。 5 | 6 | | 类型 | 描述 | 7 | | :--------- | ------------------------------------------------------------ | 8 | | 基本类型 | 整数类型和浮点数类型,它们是算术类型。 | 9 | | 枚举类型 | 被用来定义在程序中只能赋予其一定的离散整数值的变量。它也是算术类型。 | 10 | | voide 类型 | 类型说明符 *void* 表明没有可用的值 | 11 | | 派生类型 | 指针类型、数组类型、结构类型、共用体类型和函数类型 | 12 | 13 | * C语言的算术类型都有`有符号(signed)`和`无符号(unsigned)`两种表达形式。 14 | * 有符号的变量定义的时候signed关键字可以省略。 15 | 16 | ## 整数类型 17 | 18 | `整数`是没有小数部分的数,`正整数`,`负整数`都是整数。 19 | 20 | 1. char 21 | 2. short 22 | 3. int 23 | 4. long 24 | 25 | * 在C语言中,用`单引号`括起来的单个字符被称为`字符常量(character constant)` 26 | 27 | ```c 28 | char grade = 'A'; //ASCII码=65 29 | ``` 30 | 31 | ## 浮点数类型 32 | 33 | `浮点数`与数学中`实数`的概念差不多。 34 | 35 | 1. float 36 | 2. double 37 | 3. long double 38 | 39 | | 类型 | 存储大小 | 值范围 | 精度 | 40 | | ----------- | -------- | ---------------------- | --------- | 41 | | float | 4 字节 | 1.2E-38 到 3.4E+38 | 6 位小数 | 42 | | double | 8 字节 | 2.3E-308 到 1.7E+308 | 15 位小数 | 43 | | long double | 16 字节 | 3.4E-4932 到 1.1E+4932 | 19 位小数 | 44 | 45 | ## 布尔类型(_Bool) 46 | 47 | * C99之前一直用int类型的变量表示真/假值,C99才开始有了`布尔类型(bool)`。 48 | * 布尔类型是以英国数学家`George Boole`的名字命名的,他开发了用代数表示逻辑和解决逻辑问题。 49 | * 在编程中,表示真或假的变量被称为`布尔变量(boolean variable)` 50 | * 该类型变量只能存储`1`或`0`,1表示真,0表示假。 51 | 52 | ## void类型 53 | 54 | void类型指定没用可用的值。 55 | 56 | | 类型 | 描述 | 57 | | ------------ | ------------------------------------------------------------ | 58 | | 函数返回为空 | 不返回值的函数的返回类型为void。例如void main(); | 59 | | 函数参数为空 | 不带参数的函数可以接受一个 void。也可以不写了。 | 60 | | 指针指向void | 类型为 **void *** 的指针代表对象的地址,而不是类型。例如,内存分配函数 **void \*malloc( size_t size );** 返回指向 void 的指针,可以转换为任何数据类型。 | 61 | 62 | ## sizeof函数 63 | 64 | * `sizeof函数`是C语言的内置运算符,以字节为单位的给出指定类型的大小。 65 | * C99和C11提供`%zd`转换说明匹配sizeof的返回类型,一些不支持C99和C11的编译器可用`%u`或`%lu`代替`%zd`。 66 | 67 | ```c 68 | #include 69 | 70 | int main(int argc, char const *argv[]) 71 | { 72 | 73 | printf("type char size == %lu\n", sizeof(char)); 74 | printf("type short size == %lu\n", sizeof(short)); 75 | printf("type int size == %lu\n", sizeof(int)); 76 | printf("type float size == %lu\n", sizeof(float)); 77 | printf("type long size == %lu\n", sizeof(long)); 78 | printf("type double size == %lu\n", sizeof(double)); 79 | printf("type long double size == %lu\n", sizeof(long double)); 80 | 81 | return 0; 82 | } 83 | ``` 84 | 85 | ## 强制类型转换 86 | 87 | * `强制类型转换(cast)`是把变量从一种类型转换为另一种数据类型。 88 | * 圆括号和它括起来的类型名构成了`强制类型转换运算符(cast operator)` 89 | 90 | ```c 91 | 类型 变量 = (类型)变量; 92 | ``` 93 | 94 | ```c 95 | double b = 1.1; 96 | int a = (int)b; 97 | ``` -------------------------------------------------------------------------------- /c/var.md: -------------------------------------------------------------------------------- 1 | # 变量 2 | 3 | 变量是一个数据存储位置,其值在程序执行期间可以改变 4 | 5 | ```c 6 | //声明变量 7 | 变量类型 变量名; 8 | //变量赋值 9 | 变量名 = 值; 10 | ``` 11 | 12 | * 变量的名称可以由`字母`、`数字`和`下划线`字符组成 13 | * 数字不能作为变量名开始 14 | * C是大小写敏感的,所以变量`Person`和`person`是两个变量 15 | * 尽量遵循`驼峰命名法` 16 | * 关键字不能作为变量名 17 | * `=`是赋值运算符 18 | 19 | ```c 20 | #include 21 | 22 | int main(int argc, char const *argv[]) 23 | { 24 | int a; 25 | a = 1; 26 | printf("a == %d\n", a); 27 | char b = 'c'; 28 | printf("a == %d\n", b); 29 | return 0; 30 | } 31 | ``` 32 | 33 | ## 变量作用域 34 | 35 | * 局部变量:在函数内定义的参数 36 | * 全局变量:在所有函数外定义的参数 -------------------------------------------------------------------------------- /css/Reference.md: -------------------------------------------------------------------------------- 1 | ## Reference 2 | 3 | * [https://www.w3cschool.cn/](https://www.w3cschool.cn/) 4 | 5 | -------------------------------------------------------------------------------- /css/css3学习笔记/2D转换.md: -------------------------------------------------------------------------------- 1 | ## 2D转换 2 | 3 | CSS3转换,我们可以移动,比例化,反过来,旋转,和拉伸元素 4 | 5 | 变换的效果,让某个元素改变形状,大小和位置 6 | 7 | ### 方法 8 | 9 | - translate() 10 | - rotate() 11 | - scale() 12 | - skew() 13 | - matrix() 14 | 15 | ### translate 平移 16 | 17 | translate()方法,根据左(X轴)和顶部(Y轴)位置给定的参数,从当前元素位置移动。 18 | 19 | ```css 20 | div 21 | { 22 | transform: translate(50px,100px); 23 | -ms-transform: translate(50px,100px); /* IE 9 */ 24 | -webkit-transform: translate(50px,100px); /* Safari and Chrome */ 25 | } 26 | ``` 27 | 28 | ### rotate 旋转 29 | 30 | rotate()方法,在一个给定度数顺时针旋转的元素。负值是允许的,这样是元素逆时针旋转。 31 | 32 | ```css 33 | div 34 | { 35 | transform: rotate(30deg); 36 | -ms-transform: rotate(30deg); /* IE 9 */ 37 | -webkit-transform: rotate(30deg); /* Safari and Chrome */ 38 | } 39 | ``` 40 | 41 | ### scale 缩放 42 | 43 | scale()方法,该元素增加或减少的大小,取决于宽度(X轴)和高度(Y轴)的参数 44 | 45 | ```css 46 | div 47 | { 48 | transform: scale(2,4); 49 | -ms-transform: scale(2,4); /* IE 9 */ 50 | -webkit-transform: scale(2,4); /* Safari and Chrome */ 51 | } 52 | ``` 53 | 54 | ### skew 错切 55 | 56 | skew()方法,该元素会根据横向(X轴)和垂直(Y轴)线参数给定角度 57 | 58 | ```css 59 | div 60 | { 61 | transform: skew(30deg,20deg); 62 | -ms-transform: skew(30deg,20deg); /* IE 9 */ 63 | -webkit-transform: skew(30deg,20deg); /* Safari and Chrome */ 64 | } 65 | ``` 66 | 67 | ### matrix 矩阵 68 | 69 | matrix()方法和2D变换方法合并成一个 70 | 71 | matrix 方法有六个参数,包含旋转,缩放,移动(平移)和倾斜功能 72 | 73 | ```css 74 | div 75 | { 76 | transform:matrix(0.866,0.5,-0.5,0.866,0,0); 77 | -ms-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* IE 9 */ 78 | -webkit-transform:matrix(0.866,0.5,-0.5,0.866,0,0); /* Safari and Chrome */ 79 | } 80 | ``` 81 | 82 | ### 转换方法 83 | 84 | | 函数 | 描述 | 85 | | ------------------------------- | ---------------------------------------- | 86 | | matrix(*n*,*n*,*n*,*n*,*n*,*n*) | 定义 2D 转换,使用六个值的矩阵。 | 87 | | translate(*x*,*y*) | 定义 2D 转换,沿着 X 和 Y 轴移动元素。 | 88 | | translateX(*n*) | 定义 2D 转换,沿着 X 轴移动元素。 | 89 | | translateY(*n*) | 定义 2D 转换,沿着 Y 轴移动元素。 | 90 | | scale(*x*,*y*) | 定义 2D 缩放转换,改变元素的宽度和高度。 | 91 | | scaleX(*n*) | 定义 2D 缩放转换,改变元素的宽度。 | 92 | | scaleY(*n*) | 定义 2D 缩放转换,改变元素的高度。 | 93 | | rotate(*angle*) | 定义 2D 旋转,在参数中规定角度。 | 94 | | skew(*x-angle*,*y-angle*) | 定义 2D 倾斜转换,沿着 X 和 Y 轴。 | 95 | | skewX(*angle*) | 定义 2D 倾斜转换,沿着 X 轴。 | 96 | | skewY(*angle*) | 定义 2D 倾斜转换,沿着 Y 轴。 | -------------------------------------------------------------------------------- /css/css3学习笔记/3D转换.md: -------------------------------------------------------------------------------- 1 | ## 3D转换 2 | 3 | ### 属性 4 | 5 | | 属性 | 描述 | **CSS** | 6 | | ------------------------------------------------------------ | ------------------------------------ | ------- | 7 | | [transform](https://www.w3cschool.cn/cssref/css3-pr-transform.html) | 向元素应用 2D 或 3D 转换。 | 3 | 8 | | [transform-origin](https://www.w3cschool.cn/cssref/css3-pr-transform-origin.html) | 允许你改变被转换元素的位置。 | 3 | 9 | | [transform-style](https://www.w3cschool.cn/cssref/css3-pr-transform-style.html) | 规定被嵌套元素如何在 3D 空间中显示。 | 3 | 10 | | [perspective](https://www.w3cschool.cn/cssref/css3-pr-perspective.html) | 规定 3D 元素的透视效果。 | 3 | 11 | | [perspective-origin](https://www.w3cschool.cn/cssref/css3-pr-perspective-origin.html) | 规定 3D 元素的底部位置。 | 3 | 12 | | [backface-visibility](https://www.w3cschool.cn/cssref/css3-pr-backface-visibility.html) | 定义元素在不面对屏幕时是否可见。 | 3 | 13 | 14 | ### 方法 15 | 16 | | 函数 | 描述 | 17 | | ------------------------------------------------------------ | --------------------------------------------- | 18 | | matrix3d(*n***,***n***,** *n***,***n***,***n***,***n* **,***n***,***n***,***n* **,***n***,***n***,***n***,** *n***,***n***,***n***,***n* ) | 定义 3D 转换**,**使用 16 个值的 4x4 矩阵。 | 19 | | translate3d(*x***,***y***,***z*) | 定义 3D 转化。 | 20 | | translateX(*x*) | 定义 3D 转化**,**仅使用用于 X 轴的值。 | 21 | | translateY(*y*) | 定义 3D 转化**,**仅使用用于 Y 轴的值。 | 22 | | translateZ(*z*) | 定义 3D 转化**,**仅使用用于 Z 轴的值。 | 23 | | scale3d(*x***,***y***,***z*) | 定义 3D 缩放转换。 | 24 | | scaleX(*x*) | 定义 3D 缩放转换**,**通过给定一个 X 轴的值。 | 25 | | scaleY(*y*) | 定义 3D 缩放转换**,**通过给定一个 Y 轴的值。 | 26 | | scaleZ(*z*) | 定义 3D 缩放转换**,**通过给定一个 Z 轴的值。 | 27 | | rotate3d(*x***,***y***,***z***,***angle*) | 定义 3D 旋转。 | 28 | | rotateX(*angle*) | 定义沿 X 轴的 3D 旋转。 | 29 | | rotateY(*angle*) | 定义沿 Y 轴的 3D 旋转。 | 30 | | rotateZ(*angle*) | 定义沿 Z 轴的 3D 旋转。 | 31 | | perspective(*n*) | 定义 3D 转换元素的透视视图。 | -------------------------------------------------------------------------------- /css/css3学习笔记/动画.md: -------------------------------------------------------------------------------- 1 | ## 动画 2 | 3 | CSS3,我们可以创建动画,它可以取代许多网页动画图像,Flash动画,和JAVAScripts。 4 | 5 | ## @keyframs 规则 6 | 7 | @keyframes规则是创建动画 8 | 9 | @keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改为新的样式 10 | 11 | ```css 12 | @keyframes myfirst 13 | { 14 | from {background: red;} 15 | to {background: yellow;} 16 | } 17 | 18 | @-webkit-keyframes myfirst /* Safari and Chrome */ 19 | { 20 | from {background: red;} 21 | to {background: yellow;} 22 | } 23 | ``` 24 | 25 | ### 动画规则 26 | 27 | 当在@keyframe创建动画,把它绑定到一个选择器,否则动画不会有任何效果 28 | 29 | 指定至少这两个CSS3的动画属性绑定向一个选择器: 30 | 31 | - 规定动画的名称 32 | - 规定动画的时长 33 | 34 | ```css 35 | div 36 | { 37 | width:100px; 38 | height:100px; 39 | background:red; 40 | animation:myfirst 5s; 41 | -webkit-animation:myfirst 5s; /* Safari and Chrome */ 42 | } 43 | 44 | @keyframes myfirst 45 | { 46 | from {background:red;} 47 | to {background:yellow;} 48 | } 49 | 50 | @-webkit-keyframes myfirst /* Safari and Chrome */ 51 | { 52 | from {background:red;} 53 | to {background:yellow;} 54 | } 55 | ``` 56 | 57 | **注意:** 您必须定义动画的名称和动画的持续时间。如果省略的持续时间,动画将无法运行,因为默认值是0 58 | 59 | ### 属性 60 | 61 | | 属性 | 描述 | CSS | 62 | | ------------------------------------------------------------ | -------------------------------------------------------- | ---- | 63 | | [@keyframes](https://www.w3cschool.cn/cssref/css3-pr-animation-keyframes.html) | 规定动画。 | 3 | 64 | | [animation](https://www.w3cschool.cn/cssref/css3-pr-animation.html) | 所有动画属性的简写属性,除了 animation-play-state 属性。 | 3 | 65 | | [animation-name](https://www.w3cschool.cn/cssref/css3-pr-animation-name.html) | 规定 @keyframes 动画的名称。 | 3 | 66 | | [animation-duration](https://www.w3cschool.cn/cssref/css3-pr-animation-duration.html) | 规定动画完成一个周期所花费的秒或毫秒。默认是 0。 | 3 | 67 | | [animation-timing-function](https://www.w3cschool.cn/cssref/css3-pr-animation-timing-function.html) | 规定动画的速度曲线。默认是 "ease"。 | 3 | 68 | | [animation-delay](https://www.w3cschool.cn/cssref/css3-pr-animation-delay.html) | 规定动画何时开始。默认是 0。 | 3 | 69 | | [animation-iteration-count](https://www.w3cschool.cn/cssref/css3-pr-animation-iteration-count.html) | 规定动画被播放的次数。默认是 1。 | 3 | 70 | | [animation-direction](https://www.w3cschool.cn/cssref/css3-pr-animation-direction.html) | 规定动画是否在下一周期逆向地播放。默认是 "normal"。 | 3 | 71 | | [animation-play-state](https://www.w3cschool.cn/cssref/css3-pr-animation-play-state.html) | 规定动画是否正在运行或暂停。默认是 "running"。 | 3 | -------------------------------------------------------------------------------- /css/css3学习笔记/图片.md: -------------------------------------------------------------------------------- 1 | ### 圆角图片 2 | 3 | ```css 4 | img { 5 | border-radius: 8px; 6 | } 7 | ``` 8 | 9 | ### 椭圆形图片 10 | 11 | ```css 12 | img { 13 | border-radius: 50%; 14 | } 15 | ``` 16 | 17 | ### 响应式图片 18 | 19 | 响应式图片会自动适配各种尺寸的屏幕 20 | 21 | ```css 22 | img { 23 | max-width: 100%; 24 | height: auto; 25 | } 26 | ``` 27 | 28 | ### 卡片式图片 29 | 30 | ```css 31 | div.polaroid { 32 | width: 80%; 33 | background-color: white; 34 | box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); 35 | } 36 | 37 | img {width: 100%} 38 | 39 | div.container { 40 | text-align: center; 41 | padding: 10px 20px; 42 | } 43 | ``` 44 | 45 | ### 图片滤镜 46 | 47 | CSS `filter` 属性用为元素添加可视效果 (例如:模糊与饱和度) 48 | 49 | ```css 50 | img { 51 | width: 33%; 52 | height: auto; 53 | float: left; 54 | max-width: 235px; 55 | } 56 | 57 | .blur {-webkit-filter: blur(4px);filter: blur(4px);} 58 | .brightness {-webkit-filter: brightness(250%);filter: brightness(250%);} 59 | .contrast {-webkit-filter: contrast(180%);filter: contrast(180%);} 60 | .grayscale {-webkit-filter: grayscale(100%);filter: grayscale(100%);} 61 | .huerotate {-webkit-filter: hue-rotate(180deg);filter: hue-rotate(180deg);} 62 | .invert {-webkit-filter: invert(100%);filter: invert(100%);} 63 | .opacity {-webkit-filter: opacity(50%);filter: opacity(50%);} 64 | .saturate {-webkit-filter: saturate(7); filter: saturate(7);} 65 | .sepia {-webkit-filter: sepia(100%);filter: sepia(100%);} 66 | .shadow {-webkit-filter: drop-shadow(8px 8px 10px green);filter: drop-shadow(8px 8px 10px green);} 67 | ``` 68 | 69 | ### 响应式图片相册 70 | 71 | ```css 72 | .responsive { 73 | padding: 0 6px; 74 | float: left; 75 | width: 24.99999%; 76 | } 77 | 78 | @media only screen and (max-width: 700px){ 79 | .responsive { 80 | width: 49.99999%; 81 | margin: 6px 0; 82 | } 83 | } 84 | 85 | @media only screen and (max-width: 500px){ 86 | .responsive { 87 | width: 100%; 88 | } 89 | } 90 | ``` 91 | 92 | ### Modal(模态) 93 | 94 | ```css 95 | // 获取模态窗口 96 | var modal = document.getElementById('myModal'); 97 | 98 | // 获取图片模态框,alt 属性作为图片弹出中文本描述 99 | var img = document.getElementById('myImg'); 100 | var modalImg = document.getElementById("img01"); 101 | var captionText = document.getElementById("caption"); 102 | img.onclick = function(){ 103 | modal.style.display = "block"; 104 | modalImg.src = this.src; 105 | modalImg.alt = this.alt; 106 | captionText.innerHTML = this.alt; 107 | } 108 | 109 | // Get the element that closes the modal 110 | var span = document.getElementsByClassName("close")[0]; 111 | 112 | // When the user clicks on (x), close the modal 113 | span.onclick = function() { 114 | modal.style.display = "none"; 115 | } 116 | ``` -------------------------------------------------------------------------------- /css/css3学习笔记/多列.md: -------------------------------------------------------------------------------- 1 | ## 多列 2 | 3 | 通过 CSS3,您能够创建多个列来对文本进行布局 4 | 5 | - column-count 6 | - column-gap 7 | - column-rule 8 | - column-rule-color 9 | - column-rule-style 10 | - column-rule-width 11 | - column-width 12 | 13 | ### 创建多列 14 | 15 | column-count属性指定元素的列数应分为几列 16 | 17 | ```css 18 | div 19 | { 20 | -moz-column-count:3; /* Firefox */ 21 | -webkit-column-count:3; /* Safari and Chrome */ 22 | column-count:3; 23 | } 24 | ``` 25 | 26 | ### 指定列中间的间距 27 | 28 | column-gap属性指定的列之间的间距 29 | 30 | ```css 31 | .newspaper 32 | { 33 | -moz-column-count:3; /* Firefox */ 34 | -webkit-column-count:3; /* Safari and Chrome */ 35 | column-count:3; 36 | 37 | -moz-column-gap:40px; /* Firefox */ 38 | -webkit-column-gap:40px; /* Safari and Chrome */ 39 | column-gap:40px; 40 | } 41 | ``` 42 | 43 | ### 列规则 44 | 45 | column-rule属性设置列之间的宽度,样式和颜色 46 | 47 | ```css 48 | .newspaper 49 | { 50 | -moz-column-count:3; /* Firefox */ 51 | -webkit-column-count:3; /* Safari and Chrome */ 52 | column-count:3; 53 | 54 | -moz-column-gap:40px; /* Firefox */ 55 | -webkit-column-gap:40px; /* Safari and Chrome */ 56 | column-gap:40px; 57 | 58 | -moz-column-rule:4px outset #ff00ff; /* Firefox */ 59 | -webkit-column-rule:4px outset #ff00ff; /* Safari and Chrome */ 60 | column-rule:4px outset #ff00ff; 61 | } 62 | ``` 63 | 64 | ### 属性 65 | 66 | | 属性 | 说明 | CSS | 67 | | ------------------------------------------------------------ | -------------------------------- | ---- | 68 | | [column-count](https://www.w3cschool.cn/cssref/css3-pr-column-count.html) | 指定元素应分为的列数 | 3 | 69 | | [column-fill](https://www.w3cschool.cn/cssref/css3-pr-column-fill.html) | 指定如何填充列 | 3 | 70 | | [column-gap](https://www.w3cschool.cn/cssref/css3-pr-column-gap.html) | 指定列之间差距 | 3 | 71 | | [column-rule](https://www.w3cschool.cn/cssref/css3-pr-column-rule.html) | 一个用于设置所有列规则的简写属性 | 3 | 72 | | [column-rule-color](https://www.w3cschool.cn/cssref/css3-pr-column-rule-color.html) | 指定的列之间颜色规则 | 3 | 73 | | [column-rule-style](https://www.w3cschool.cn/cssref/css3-pr-column-rule-style.html) | 指定的列之间的样式规则 | 3 | 74 | | [column-rule-width](https://www.w3cschool.cn/cssref/css3-pr-column-rule-width.html) | 指定的列之间的宽度规则 | 3 | 75 | | [column-span](https://www.w3cschool.cn/cssref/css3-pr-column-span.html) | 指定一个元素应该横跨多少列 | 3 | 76 | | [column-width](https://www.w3cschool.cn/cssref/css3-pr-column-width.html) | 指定列的宽度 | 3 | 77 | | [columns](https://www.w3cschool.cn/cssref/css3-pr-columns.html) | 缩写属性设置列宽和列数 | 3 | -------------------------------------------------------------------------------- /css/css3学习笔记/字体.md: -------------------------------------------------------------------------------- 1 | ## 字体 2 | 3 | 在CSS3之前,web设计师必须使用已在用户计算机上安装好的字体,不能够使用离线字体,不过通过CSS3,web设计师可以使用他们喜欢的任意字体。 4 | 5 | 当您找到或购买到希望使用的字体时,可将该字体文件存放到web服务器上,它会在需要时被自动下载到用户的计算机上 6 | 7 | 在新的 @font-face 规则中,您必须首先定义字体的名称(比如 myFirstFont),然后指向该字体文件 8 | 9 | ```css 10 | 22 | ``` -------------------------------------------------------------------------------- /css/css3学习笔记/按钮.md: -------------------------------------------------------------------------------- 1 | ### 自定义按钮样式 2 | 3 | ```css 4 | .button { 5 | background-color: #4CAF50; 6 | border: none; 7 | color: white; 8 | padding: 15px 32px; 9 | text-align: center; 10 | text-decoration: none; 11 | display: inline-block; 12 | font-size: 16px; 13 | margin: 4px 2px; 14 | cursor: pointer; 15 | border-radius:10px; 16 | } 17 | ``` 18 | 19 | ### 按钮边框颜色 20 | 21 | 可以使用 `border` 属性设置按钮边框颜色 22 | 23 | ```css 24 | .button1 { 25 | background-color: white; 26 | color: black; 27 | border: 2px solid #4CAF50; /* Green */ 28 | } 29 | ``` 30 | 31 | ### 鼠标悬停按钮样式 32 | 33 | ```css 34 | .button { 35 | -webkit-transition-duration: 0.4s; /* Safari */ 36 | transition-duration: 0.4s; 37 | } 38 | 39 | .button:hover { 40 | background-color: #4CAF50; /* Green */ 41 | color: white; 42 | } 43 | ``` 44 | 45 | ### 按钮阴影 46 | 47 | 可以使用 `box-shadow` 属性来为按钮添加阴影 48 | 49 | ```css 50 | .button1 { 51 | box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0rgba(0,0,0,0.19); 52 | } 53 | 54 | .button2:hover { 55 | box-shadow: 0 12px16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19); 56 | } 57 | ``` 58 | 59 | ### 禁用按钮 60 | 61 | 可以使用 `opacity` 属性为按钮添加透明度 (看起来类似"disabled" 属性效果) 62 | 63 | **提示:** 我么可以添加 `cursor` 属性并设置为"not-allowed" 来设置一个禁用的图片 64 | 65 | ```css 66 | .disabled { 67 | opacity: 0.6; 68 | cursor: not-allowed; 69 | } 70 | ``` 71 | 72 | ### 按钮动画 73 | 74 | ```css 75 | .button { 76 | display: inline-block; 77 | border-radius: 4px; 78 | background-color: #f4511e; 79 | border: none; 80 | color: #FFFFFF; 81 | text-align: center; 82 | font-size: 28px; 83 | padding: 20px; 84 | width: 200px; 85 | transition: all 0.5s; 86 | cursor: pointer; 87 | margin: 5px; 88 | } 89 | 90 | .button span { 91 | cursor: pointer; 92 | display: inline-block; 93 | position: relative; 94 | transition: 0.5s; 95 | } 96 | 97 | .button span:after { 98 | content: '»'; 99 | position: absolute; 100 | opacity: 0; 101 | top: 0; 102 | right: -20px; 103 | transition: 0.5s; 104 | } 105 | 106 | .button:hover span { 107 | padding-right: 25px; 108 | } 109 | 110 | .button:hover span:after { 111 | opacity: 1; 112 | right: 0; 113 | } 114 | ``` -------------------------------------------------------------------------------- /css/css3学习笔记/文本效果.md: -------------------------------------------------------------------------------- 1 | ## 文本效果 2 | 3 | CSS3中包含几个新的文本特征 4 | 5 | - text-shadow 文本阴影 6 | - box-shadow 盒子阴影 7 | - text-overflow 文本溢出 8 | - word-wrap 文本包裹方式 9 | - word-break 10 | 11 | ### 文本阴影 12 | 13 | 指定了水平阴影,垂直阴影,模糊的距离,以及阴影的颜色 14 | 15 | ```css 16 | h1 17 | { 18 | text-shadow: 5px 5px 5px #FF0000; 19 | } 20 | ``` 21 | 22 | ### 盒子阴影 23 | 24 | ```css 25 | div { box-shadow: 10px 10px grey;} 26 | ``` 27 | 28 | ### Text OverFlow 29 | 30 | CSS3文本溢出属性指定应向用户如何显示溢出内容 31 | 32 | ```css 33 | 34 | 35 | 36 | 37 | W3Cschool教程(w3cschool.cn) 38 | 47 | 48 | 49 | 50 |

以下 div 容器内的文本无法完全显示,可以看到它被裁剪了。

51 |

div 使用 "text-overflow:ellipsis":

52 | 53 |
This is some long text that will not fit in the box
54 |

div 使用 "text-overflow:clip":

55 |
This is some long text that will not fit in the box
56 |

div 使用自定义字符串 "text-overflow: >>"(只在 Firefox 浏览器下有效):

57 |
This is some long text that will not fit in the box
58 | 59 | 60 | ``` 61 | 62 | ### 换行 63 | 64 | 如果某个单词太长,不适合在一个区域内,它扩展到外面: 65 | 66 | CSS3中,自动换行属性允许您强制文本换行 - 即使这意味着分裂它中间的一个字: 67 | 68 | ```css 69 | p {word-wrap:break-word;} 70 | ``` 71 | 72 | ### 单词拆分换行 73 | 74 | CSS3 单词拆分换行属性指定换行规则: 75 | 76 | ```css 77 | p.test1 { 78 | word-break: keep-all; 79 | } 80 | p.test2 { 81 | word-break: break-all; 82 | } 83 | ``` 84 | 85 | ### 属性 86 | 87 | | 属性 | 描述 | CSS | 88 | | ------------------------------------------------------------ | -------------------------------------------------------- | ---- | 89 | | [hanging-punctuation](https://www.w3cschool.cn/cssref/css3-pr-hanging-punctuation.html) | 规定标点字符是否位于线框之外。 | 3 | 90 | | [punctuation-trim](https://www.w3cschool.cn/cssref/css3-pr-punctuation-trim.html) | 规定是否对标点字符进行修剪。 | 3 | 91 | | [text-align-last](https://www.w3cschool.cn/cssref/css3-pr-text-align-last.html) | 设置如何对齐最后一行或紧挨着强制换行符之前的行。 | 3 | 92 | | text-emphasis | 向元素的文本应用重点标记以及重点标记的前景色。 | 3 | 93 | | [text-justify](https://www.w3cschool.cn/cssref/css3-pr-text-justify.html) | 规定当 text-align 设置为 "justify" 时所使用的对齐方法。 | 3 | 94 | | [text-outline](https://www.w3cschool.cn/cssref/css3-pr-text-outline.html) | 规定文本的轮廓。 | 3 | 95 | | [text-overflow](https://www.w3cschool.cn/cssref/css3-pr-text-overflow.html) | 规定当文本溢出包含元素时发生的事情。 | 3 | 96 | | [text-shadow](https://www.w3cschool.cn/cssref/css3-pr-text-shadow.html) | 向文本添加阴影。 | 3 | 97 | | [text-wrap](https://www.w3cschool.cn/cssref/css3-pr-text-wrap.html) | 规定文本的换行规则。 | 3 | 98 | | [word-break](https://www.w3cschool.cn/cssref/css3-pr-word-break.html) | 规定非中日韩文本的换行规则。 | 3 | 99 | | [word-wrap](https://www.w3cschool.cn/cssref/css3-pr-word-wrap.html) | 允许对长的不可分割的单词进行分割并换行到下一行。 | 3 | -------------------------------------------------------------------------------- /css/css3学习笔记/用户界面.md: -------------------------------------------------------------------------------- 1 | ## 用户界面 2 | 3 | 在 CSS3 中, 增加了一些新的用户界面特性来调整元素尺寸,框尺寸和外边框 4 | 5 | - resize 6 | - box-sizing 7 | - outline-offset 8 | 9 | ### 调整尺寸(resizing) 10 | 11 | CSS3中,resize属性指定一个元素是否应该由用户去调整大小 12 | 13 | ```css 14 | div 15 | { 16 | resize:both; 17 | overflow:auto; 18 | } 19 | ``` 20 | 21 | ### 方框大小调整 22 | 23 | box-sizing 属性允许您以确切的方式定义适应某个区域的具体内容 24 | 25 | ```css 26 | div 27 | { 28 | box-sizing:border-box; 29 | -moz-box-sizing:border-box; /* Firefox */ 30 | width:50%; 31 | float:left; 32 | } 33 | ``` 34 | 35 | ### 外形修饰(outline-offset) 36 | 37 | outline-offset 属性对轮廓进行偏移,并在超出边框边缘的位置绘制轮廓 38 | 39 | 轮廓与边框有两点不同: 40 | 41 | - 轮廓不占用空间 42 | - 轮廓可能是非矩形 43 | 44 | ```css 45 | div 46 | { 47 | border:2px solid black; 48 | outline:2px solid red; 49 | outline-offset:15px; 50 | } 51 | ``` 52 | 53 | ### 新的用户界面特性 54 | 55 | | 属性 | 说明 | CSS | 56 | | ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | 57 | | [appearance](https://www.w3cschool.cn/cssref/css3-pr-appearance.html) | 允许您使一个元素的外观像一个标准的用户界面元素 | 3 | 58 | | [box-sizing](https://www.w3cschool.cn/cssref/css3-pr-box-sizing.html) | 允许你以适应区域而用某种方式定义某些元素 | 3 | 59 | | [icon](https://www.w3cschool.cn/cssref/css3-pr-icon.html) | Provides the author the ability to style an element with an iconic equivalent | 3 | 60 | | [nav-down](https://www.w3cschool.cn/cssref/css3-pr-nav-down.html) | 指定在何处使用箭头向下导航键时进行导航 | 3 | 61 | | [nav-index](https://www.w3cschool.cn/cssref/css3-pr-nav-index.html) | 指定一个元素的Tab的顺序 | 3 | 62 | | [nav-left](https://www.w3cschool.cn/cssref/css3-pr-nav-left.html) | 指定在何处使用左侧的箭头导航键进行导航 | 3 | 63 | | [nav-right](https://www.w3cschool.cn/cssref/css3-pr-nav-right.html) | 指定在何处使用右侧的箭头导航键进行导航 | 3 | 64 | | [nav-up](https://www.w3cschool.cn/cssref/css3-pr-nav-up.html) | 指定在何处使用箭头向上导航键时进行导航 | 3 | 65 | | [outline-offset](https://www.w3cschool.cn/cssref/css3-pr-outline-offset.html) | 外轮廓修饰并绘制超出边框的边缘 | 3 | 66 | | [resize](https://www.w3cschool.cn/cssref/css3-pr-resize.html) | 指定一个元素是否是由用户调整大小 | 3 | -------------------------------------------------------------------------------- /css/css3学习笔记/盒阴影.md: -------------------------------------------------------------------------------- 1 | ## 盒阴影 2 | 3 | CSS3中的box-shadow属性被用来添加阴影: 4 | 5 | ```css 6 | div 7 | { 8 | width:300px; 9 | height:100px; 10 | background-color:yellow; 11 | box-shadow: 10px 10px 5px #888888; 12 | } 13 | ``` -------------------------------------------------------------------------------- /css/css3学习笔记/背景.md: -------------------------------------------------------------------------------- 1 | ## 背景 2 | 3 | - background-image 4 | - background-size 5 | - background-origin 6 | - background-clip 7 | 8 | ### background-image 9 | 10 | CSS3中可以通过background-image属性添加背景图片 11 | 12 | 不同的背景图像和图像用逗号隔开,所有的图片中显示在最顶端的为第一张 13 | 14 | ```css 15 | #example1 { 16 | background-image: url(img_flwr.gif), url(paper.gif); 17 | background-position: right bottom, left top; 18 | background-repeat: no-repeat, repeat; 19 | } 20 | ``` 21 | 22 | ### background-size 23 | 24 | background-size指定背景图像的大小。CSS3以前,背景图像大小由图像的实际大小决定 25 | 26 | CSS3中可以指定背景图片,让我们重新在不同的环境中指定背景图片的大小 27 | 28 | 您可以指定像素或相对于父元素宽高的百分比大小 29 | 30 | ```css 31 | div 32 | { 33 | background:url(img_flwr.gif); 34 | background-size:80px 60px; 35 | background-repeat:no-repeat; 36 | } 37 | ``` 38 | 39 | ### backgroud-origin 40 | 41 | background-Origin属性指定了背景图像的位置区域 42 | 43 | content-box, padding-box,和 border-box区域内可以放置背景图像 44 | 45 | ```css 46 | div 47 | { 48 | background:url(img_flwr.gif); 49 | background-repeat:no-repeat; 50 | background-size:100% 100%; 51 | background-origin:content-box; 52 | } 53 | ``` 54 | 55 | ### background-clip 56 | 57 | CSS3中background-clip背景剪裁属性是从指定位置开始绘制 58 | 59 | ```css 60 | #example1 { 61 | border: 10px dotted black; 62 | padding: 35px; 63 | background: yellow; 64 | background-clip: content-box; 65 | } 66 | ``` 67 | 68 | ### 属性 69 | 70 | | 顺序 | 描述 | CSS | 71 | | ------------------------------------------------------------ | ------------------------ | ---- | 72 | | [background-clip](https://www.w3cschool.cn/cssref/css3-pr-background-clip.html) | 规定背景的绘制区域。 | 3 | 73 | | [background-origin](https://www.w3cschool.cn/cssref/css3-pr-background-origin.html) | 规定背景图片的定位区域。 | 3 | 74 | | [background-size](https://www.w3cschool.cn/cssref/css3-pr-background-size.html) | 规定背景图片的尺寸。 | 3 | -------------------------------------------------------------------------------- /css/css3学习笔记/边框图片.md: -------------------------------------------------------------------------------- 1 | ## 边框图片 2 | 3 | CSS3的border-image属性,可以使用图像创建一个边框 4 | 5 | border-image属性允许你指定一个图片作为边框!用于创建上文边框的原始图像 6 | 7 | ```css 8 | div 9 | { 10 | border-image:url(border.png) 30 30 round; 11 | -webkit-border-image:url(border.png) 30 30 round; /* Safari 5 and older */ 12 | -o-border-image:url(border.png) 30 30 round; /* Opera */ 13 | } 14 | ``` -------------------------------------------------------------------------------- /css/css3学习笔记/边框圆角.md: -------------------------------------------------------------------------------- 1 | ## 边框圆角 2 | 3 | 在CSS3中border-radius属性就是被用于创建圆角的 4 | 5 | ```Html 6 | 7 | 8 | 9 | 10 | W3Cschool教程(w3cschool.cn) 11 | 21 | 22 | 23 | 24 |
border-radius 属性允许您为元素添加圆角边框!
25 | 26 | 27 | 28 | ``` 29 | 30 | ## 椭圆边角 31 | 32 | ```css 33 | #rcorners9 { 34 | border-radius: 50%; 35 | background: #8AC007; 36 | padding: 20px; 37 | width: 200px; 38 | height: 150px; 39 | } 40 | ``` 41 | 42 | ## 圆角属性 43 | 44 | | 属性 | 描述 | 45 | | ------------------------------------------------------------ | ----------------------------------------- | 46 | | [border-radius](https://www.w3cschool.cn/cssref/css3-pr-border-radius.html) | 所有四个边角 border-*-*-radius 属性的缩写 | 47 | | [border-top-left-radius](https://www.w3cschool.cn/cssref/css3-pr-border-top-left-radius.html) | 定义了左上角的弧度 | 48 | | [border-top-right-radius](https://www.w3cschool.cn/cssref/css3-pr-border-top-right-radius.html) | 定义了右上角的弧度 | 49 | | [border-bottom-right-radius](https://www.w3cschool.cn/cssref/css3-pr-border-bottom-right-radius.html) | 定义了右下角的弧度 | 50 | | [border-bottom-left-radius](https://www.w3cschool.cn/cssref/css3-pr-border-bottom-left-radius.html) | 定义了左下角的弧度 | -------------------------------------------------------------------------------- /css/css3学习笔记/过渡.md: -------------------------------------------------------------------------------- 1 | ## 过渡 2 | 3 | CSS3中,我们为了添加某种效果可以从一种样式转变到另一个的时候,无需使用Flash动画或JavaScript。 4 | 5 | ### 如何工作 6 | 7 | CSS3 过渡是元素从一种样式逐渐改变为另一种的效果。 8 | 9 | 要实现这一点,必须规定两项内容: 10 | 11 | - 指定要添加效果的CSS属性 12 | - 指定效果的持续时间。 13 | 14 | ```html 15 | 16 | 17 | 18 | 19 | W3Cschool教程(w3cschool.cn) 20 | 36 | 37 | 38 |

注意:该实例无法在 Internet Explorer 9 及更早 IE 版本上工作。

39 | 40 |
鼠标移动到 div 元素上,查看过渡效果。
41 | 42 | 43 | ``` 44 | 45 | ### 多项改变 46 | 47 | 要添加多个样式的变换效果,添加的属性由逗号分隔: 48 | 49 | ```css 50 | div 51 | { 52 | transition: width 2s, height 2s, transform 2s; 53 | -webkit-transition: width 2s, height 2s, -webkit-transform 2s; 54 | } 55 | ``` 56 | 57 | ### 属性 58 | 59 | | 属性 | 描述 | CSS | 60 | | ------------------------------------------------------------ | -------------------------------------------- | ---- | 61 | | [transition](https://www.w3cschool.cn/cssref/css3-pr-transition.html) | 简写属性,用于在一个属性中设置四个过渡属性。 | 3 | 62 | | [transition-property](https://www.w3cschool.cn/cssref/css3-pr-transition-property.html) | 规定应用过渡的 CSS 属性的名称。 | 3 | 63 | | [transition-duration](https://www.w3cschool.cn/cssref/css3-pr-transition-duration.html) | 定义过渡效果花费的时间。默认是 0。 | 3 | 64 | | [transition-timing-function](https://www.w3cschool.cn/cssref/css3-pr-transition-timing-function.html) | 规定过渡效果的时间曲线。默认是 "ease"。 | 3 | 65 | | [transition-delay](https://www.w3cschool.cn/cssref/css3-pr-transition-delay.html) | 规定过渡效果何时开始。默认是 0。 | 3 | 66 | 67 | ```css 68 | div 69 | { 70 | transition-property: width; 71 | transition-duration: 1s; 72 | transition-timing-function: linear; 73 | transition-delay: 2s; 74 | /* Safari */ 75 | -webkit-transition-property:width; 76 | -webkit-transition-duration:1s; 77 | -webkit-transition-timing-function:linear; 78 | -webkit-transition-delay:2s; 79 | } 80 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/伪类.md: -------------------------------------------------------------------------------- 1 | ## 伪类(pseudo-classes) 2 | 3 | CSS伪类是用来添加一些选择器的特殊效果 4 | 5 | 由于状态的变化是非静态的,所以元素达到一个特定状态时,它可能得到一个伪类的样式 6 | 7 | 当状态改变时,它又会失去这个样式。由此可以看出,它的功能和class有些类似,但它是基于文档之外的抽象,所以叫伪类 8 | 9 | ### 语法 10 | 11 | ```css 12 | selector:pseudo-class {property:value;} 13 | ``` 14 | 15 | CSS类也可以使用伪类 16 | 17 | ```css 18 | selector.class:pseudo-class {property:value;} 19 | ``` 20 | 21 | ### anchor伪类 22 | 23 | 在支持 CSS 的浏览器中,链接的不同状态都可以以不同的方式显示 24 | 25 | ```css 26 | a:link {color:#FF0000;} /* 未访问的链接 */ 27 | a:visited {color:#00FF00;} /* 已访问的链接 */ 28 | a:hover {color:#FF00FF;} /* 鼠标划过链接 */ 29 | a:active {color:#0000FF;} /* 已选中的链接 */ 30 | ``` 31 | 32 | **注意:** 在CSS定义中,a:hover 必须被置于 a:link 和 a:visited 之后,才是有效的。 33 | 34 | **注意:** 在 CSS 定义中,a:active 必须被置于 a:hover 之后,才是有效的。 35 | 36 | **注意:**伪类的名称不区分大小写。 37 | 38 | ### 伪类和css类 39 | 40 | 伪类可以与 CSS 类配合使用: 41 | 42 | ```css 43 | a.red:visited {color:#FF0000;} 44 | CSS Syntax 45 | ``` 46 | 47 | 如果在上面的例子的链接已被访问,它会显示为红色 48 | 49 | ### 所有CSS伪类/元素 50 | 51 | | 选择器 | 示例 | 示例说明 | 52 | | ------------------------------------------------------------ | -------------- | ------------------------------------------------ | 53 | | [:link](https://www.w3cschool.cn/cssref/sel-link.html) | a:link | 选择所有未访问链接 | 54 | | [:visited](https://www.w3cschool.cn/cssref/sel-visited.html) | a:visited | 选择所有访问过的链接 | 55 | | [:active](https://www.w3cschool.cn/cssref/sel-active.html) | a:active | 选择正在活动链接 | 56 | | [:hover](https://www.w3cschool.cn/cssref/sel-hover.html) | a:hover | 把鼠标放在链接上的状态 | 57 | | [:focus](https://www.w3cschool.cn/cssref/sel-focus.html) | input:focus | 选择元素输入后具有焦点 | 58 | | [:first-letter](https://www.w3cschool.cn/cssref/sel-firstletter.html) | p:first-letter | 选择每个

元素的第一个字母 | 59 | | [:first-line](https://www.w3cschool.cn/cssref/sel-firstline.html) | p:first-line | 选择每个

元素的第一行 | 60 | | [:first-child](https://www.w3cschool.cn/cssref/sel-firstchild.html) | p:first-child | 选择器匹配属于任意元素的第一个子元素的 <]p> 元素 | 61 | | [:before](https://www.w3cschool.cn/cssref/sel-before.html) | p:before | 在每个

元素之前插入内容 | 62 | | [:after](https://www.w3cschool.cn/cssref/sel-after.html) | p:after | 在每个

元素之后插入内容 | 63 | | [:lang(*language*)](https://www.w3cschool.cn/cssref/sel-lang.html) | p:lang(it) | 为

元素的lang属性选择一个开始值 | -------------------------------------------------------------------------------- /css/css学习笔记/内边距.md: -------------------------------------------------------------------------------- 1 | ## 内边距(padding) 2 | 3 | CSS Padding(填充)属性定义元素边框与元素内容之间的空间 4 | 5 | ### 可能的值 6 | 7 | | 值 | 说明 | 8 | | ------ | ----------------------------------- | 9 | | length | 定义一个固定的填充(像素, pt, em,等) | 10 | | % | 使用百分比值定义一个填充 | 11 | 12 | CSS padding 属性可以使用长度值或百分比值,但与 margin 属性不同,它不允许使用负值 13 | 14 | ### 内边距的百分比数值 15 | 16 | CSS padding 属性的百分比数值是相对于其父元素的 width 计算的,如果改变了父元素的 width,则它们也会改变 17 | 18 | ```css 19 | p {padding: 20%;} 20 | ``` 21 | 22 | **注意:**上下内边距与左右内边距一致,即上下内边距的百分数会相对于父元素宽度设置,而不是相对于高度 23 | 24 | ### 填充所有属性 25 | 26 | | 属性 | 说明 | 27 | | ------------------------------------------------------------ | ------------------------------------------ | 28 | | [padding](https://www.w3cschool.cn/cssref/pr-padding.html) | 使用缩写属性设置在一个声明中的所有填充属性 | 29 | | [padding-bottom](https://www.w3cschool.cn/cssref/pr-padding-bottom.html) | 设置元素的底部填充 | 30 | | [padding-left](https://www.w3cschool.cn/cssref/pr-padding-left.html) | 设置元素的左部填充 | 31 | | [padding-right](https://www.w3cschool.cn/cssref/pr-padding-right.html) | 设置元素的右部填充 | 32 | | [padding-top](https://www.w3cschool.cn/cssref/pr-padding-top.html) | 设置元素的顶部填充 | -------------------------------------------------------------------------------- /css/css学习笔记/分组选择器.md: -------------------------------------------------------------------------------- 1 | ## 分组选择器(grouping selectors) 2 | 3 | CSS分组可以将具有相同样式的选择器进行分组,减少代码量 4 | 5 | 在样式表中有很多具有相同样式的元素 6 | 7 | ```css 8 | h1 9 | { 10 | color:green; 11 | } 12 | h2 13 | { 14 | color:green; 15 | } 16 | p 17 | { 18 | color:green; 19 | } 20 | ``` 21 | 22 | 为了尽量减少代码,你可以使用分组选择器 23 | 24 | 每个选择器用逗号分隔 25 | 26 | ```css 27 | h1,h2,p 28 | { 29 | color:green; 30 | } 31 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/列表样式.md: -------------------------------------------------------------------------------- 1 | ## 列表样式 2 | 3 | CSS列表属性作用如下: 4 | 5 | - 设置不同的列表项标记为有序列表(数字或字母) 6 | - 设置不同的列表项标记为无序列表 (小黑点、小方框等) 7 | - 设置列表项标记为图像 8 | 9 | ### 列表项标记(list-style-type) 10 | 11 | ```html 12 | 13 | 14 | 15 | 16 | W3Cschool教程(w3cschool.cn) 17 | 23 | 24 | 25 | 26 |

无序列表实例:

27 | 28 |
    29 |
  • Coffee
  • 30 |
  • Tea
  • 31 |
  • Coca Cola
  • 32 |
33 | 34 |
    35 |
  • Coffee
  • 36 |
  • Tea
  • 37 |
  • Coca Cola
  • 38 |
39 | 40 |

有序列表实例:

41 | 42 |
    43 |
  1. Coffee
  2. 44 |
  3. Tea
  4. 45 |
  5. Coca Cola
  6. 46 |
47 | 48 |
    49 |
  1. Coffee
  2. 50 |
  3. Tea
  4. 51 |
  5. Coca Cola
  6. 52 |
53 | 54 | 55 | 56 | ``` 57 | 58 | 下列是对list-style-type属性的常见属性值的描述: 59 | 60 | - none:不使用项目符号 61 | - disc:实心圆 62 | - circle:空心圆 63 | - square:实心方块 64 | - demical:阿拉伯数字 65 | - lower-alpha:小写英文字母 66 | - upper-alpha:大写英文字母 67 | - lower-roman:小写罗马数字 68 | - upper-roman:大写罗马数字 69 | 70 | ### 列表项标记的图像 71 | 72 | 要指定列表项标记的图像,使用列表样式图像属性: 73 | 74 | ```css 75 | ul 76 | { 77 | list-style-image: url('sqpurple.gif'); 78 | } 79 | ``` 80 | 81 | ### 缩写 82 | 83 | 在单个属性中可以指定所有的列表属性,这就是所谓的缩写属性 84 | 85 | ```css 86 | ul 87 | { 88 | list-style: square url("sqpurple.gif"); 89 | } 90 | ``` 91 | 92 | 如果使用缩写属性值的顺序是: 93 | 94 | - list-style-type 95 | - list-style-position 96 | - list-style-image 97 | 98 | ### 所有css列表属性 99 | 100 | | 属性 | 描述 | 101 | | ------------------------------------------------------------ | -------------------------------------------------- | 102 | | [list-style](https://www.w3cschool.cn/cssref/pr-list-style.html) | 简写属性。用于把所有用于列表的属性设置于一个声明中 | 103 | | [list-style-image](https://www.w3cschool.cn/cssref/pr-list-style-image.html) | 将图象设置为列表项标志。 | 104 | | [list-style-position](https://www.w3cschool.cn/cssref/pr-list-style-position.html) | 设置列表中列表项标志的位置。 | 105 | | [list-style-type](https://www.w3cschool.cn/cssref/pr-list-style-type.html) | 设置列表项标志的类型。 | -------------------------------------------------------------------------------- /css/css学习笔记/响应式设计.md: -------------------------------------------------------------------------------- 1 | ## 可视区域(Viewport) 2 | 3 | viewport 是用户网页的可视区域 4 | 5 | 手机浏览器是把页面放在一个虚拟的"窗口"(viewport)中,通常这个虚拟的"窗口"(viewport)比屏幕宽,这样就不用把每个网页挤到很小的窗口中(这样会破坏没有针对手机浏览器优化的网页的布局),用户可以通过平移和缩放来看网页的不同部分 6 | 7 | ## 设置Viewport 8 | 9 | 一个常用的针对移动网页优化过的页面的 viewport meta 标签大致如下: 10 | 11 | - width:控制 viewport 的大小,可以指定的一个值,如果 600,或者特殊的值,如 device-width 为设备的宽度(单位为缩放为 100% 时的 CSS 的像素)。 12 | - height:和 width 相对应,指定高度。 13 | - initial-scale:初始缩放比例,也即是当页面第一次 load 的时候缩放比例。 14 | - maximum-scale:允许用户缩放到的最大比例。 15 | - minimum-scale:允许用户缩放到的最小比例。 16 | - user-scalable:用户是否可以手动缩放 17 | 18 | ```html 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | Chania 33 |

34 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam 35 | nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat 36 | volutpat. 37 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 38 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 39 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie 40 | consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et 41 | accumsan et iusto odio dignissim qui blandit praesent luptatum zzril 42 | delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor 43 | cum soluta nobis eleifend option congue nihil imperdiet doming id quod 44 | mazim placerat facer possim assum. 45 | Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet 46 | doming id quod mazim placerat facer possim assum. 47 |

48 | 49 | 50 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/外边距.md: -------------------------------------------------------------------------------- 1 | ## 外边距(margin) 2 | 3 | CSS Margin(外边距)属性定义元素周围的空间 4 | 5 | CSS Margin属性接受任何长度单位、百分数值甚至负值 6 | 7 | margin可以单独改变元素的上,下,左,右边距。也可以一次改变所有的属性 8 | 9 | | 值 | 说明 | 10 | | -------- | ------------------------------------------ | 11 | | auto | 设置浏览器边距。这样做的结果会依赖于浏览器 | 12 | | *length* | 定义一个固定的margin(使用像素,pt,em等) | 13 | | *%* | 定义一个使用百分比的边距 | -------------------------------------------------------------------------------- /css/css学习笔记/媒体查询.md: -------------------------------------------------------------------------------- 1 | ## 媒体查询(@media) 2 | 3 | 使用 @media 查询,你可以针对不同的媒体类型定义不同的样式 4 | 5 | 如果浏览器窗口小于 500px, 背景将变为浅蓝色: 6 | 7 | ```css 8 | @media only screen and (max-width: 500px) { 9 | body { 10 | background-color: lightblue; 11 | } 12 | } 13 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/字体.md: -------------------------------------------------------------------------------- 1 | ## 字体(fonts) 2 | 3 | CSS字体属性定义字体,加粗,大小,文字样式 4 | 5 | ### 字型 6 | 7 | 在CSS中,有两种类型的字体系列名称: 8 | 9 | - **通用字体系列** - 拥有相似外观的字体系统组合(如 "Serif" 或 "Monospace") 10 | - **特定字体系列** - 一个特定的字体系列(如 "Times" 或 "Courier") 11 | 12 | ### 字体系列(font-family) 13 | 14 | font-family 属性设置文本的字体系列 15 | 16 | font-family 属性应该设置几个字体名称作为一种"后备"机制,如果浏览器不支持第一种字体,他将尝试下一种字体 17 | 18 | 如果字体系列的名称超过一个字,它必须用引号,如Font Family:"宋体" 19 | 20 | ```html 21 | 22 | 23 | 24 | 25 | W3Cschool教程(w3cschool.cn) 26 | 30 | 31 | 32 | 33 |

CSS font-family

34 |

这一段的字体是 Times New Roman 。

35 |

这一段的字体是 Arial 。

36 | 37 | 38 | 39 | ``` 40 | 41 | ### 样式(font-style) 42 | 43 | 主要是用于指定斜体文字的字体样式属性 44 | 45 | 这个属性有三个值: 46 | 47 | - 正常 - 正常显示文本 48 | - 斜体 - 以斜体字显示的文字 49 | - 倾斜的文字 - 文字向一边倾斜(和斜体非常类似,但不太支持) 50 | 51 | ```html 52 | 53 | 54 | 55 | 56 | W3Cschool教程(w3cschool.cn) 57 | 62 | 63 | 64 | 65 |

This is a paragraph, normal.

66 |

This is a paragraph, italic.

67 |

This is a paragraph, oblique.

68 | 69 | 70 | 71 | ``` 72 | 73 | ### 字体大小(font-size) 74 | 75 | font-size 属性设置文本的大小 76 | 77 | 绝对大小: 78 | 79 | - 设置一个指定大小的文本 80 | - 不允许用户在所有浏览器中改变文本大小 81 | - 确定了输出的物理尺寸时绝对大小很有用 82 | 83 | 相对大小: 84 | 85 | - 相对于周围的元素来设置大小 86 | - 允许用户在浏览器中改变文字大小 87 | 88 | #### 设置字体大小像素 89 | 90 | ```css 91 | h1 {font-size:40px;} 92 | h2 {font-size:30px;} 93 | p {font-size:14px;} 94 | ``` 95 | 96 | #### 用em设置字体大小 97 | 98 | 为了避免Internet Explorer 中无法调整文本的问题,许多开发者使用 em 单位代替像素 99 | 100 | 1em和当前字体大小相等。在浏览器中默认的文字大小是16px 101 | 102 | ```css 103 | h1 {font-size:2.5em;} /* 40px/16=2.5em */ 104 | h2 {font-size:1.875em;} /* 30px/16=1.875em */ 105 | p {font-size:0.875em;} /* 14px/16=0.875em */ 106 | ``` 107 | 108 | #### 使用百分比和em组合 109 | 110 | 在所有浏览器的解决方案中,设置 元素的默认字体大小的是百分比 111 | 112 | ```css 113 | body {font-size:100%;} 114 | h1 {font-size:2.5em;} 115 | h2 {font-size:1.875em;} 116 | p {font-size:0.875em;} 117 | ``` 118 | 119 | ### 所有css字体属性 120 | 121 | | Property | 描述 | 122 | | ------------------------------------------------------------ | ---------------------------------- | 123 | | [font](https://www.w3cschool.cn/cssref/pr-font-font.html) | 在一个声明中设置所有的字体属性 | 124 | | [font-family](https://www.w3cschool.cn/cssref/pr-font-font-family.html) | 指定文本的字体系列 | 125 | | [font-size](https://www.w3cschool.cn/cssref/pr-font-font-size.html) | 指定文本的字体大小 | 126 | | [font-style](https://www.w3cschool.cn/cssref/pr-font-font-style.html) | 指定文本的字体样式 | 127 | | [font-variant](https://www.w3cschool.cn/cssref/pr-font-font-variant.html) | 以小型大写字体或者正常字体显示文本 | 128 | | [font-weight](https://www.w3cschool.cn/cssref/pr-font-weight.html) | 指定字体的粗细。 | -------------------------------------------------------------------------------- /css/css学习笔记/定位.md: -------------------------------------------------------------------------------- 1 | ## 定位(positioning) 2 | 3 | CSS定位属性允许你为一个元素定位。它也可以将一个元素放在另一个元素后面,并指定一个元素的内容太大时,应该发生什么 4 | 5 | 元素可以使用的顶部,底部,左侧和右侧属性定位。然而,这些属性无法工作,除非是先设定position属性。他们也有不同的工作方式,这取决于定位方法 6 | 7 | ### static 定位 8 | 9 | HTML元素的默认值,即没有定位,元素出现在正常的流中 10 | 11 | 静态定位的元素不会受到top, bottom, left, right影响 12 | 13 | ### fixed 定位 14 | 15 | 元素的位置相对于浏览器窗口是固定位置 16 | 17 | 即使窗口是滚动的它也不会移动 18 | 19 | ```css 20 | p.pos_fixed 21 | { 22 | position:fixed; 23 | top:30px; 24 | right:5px; 25 | } 26 | ``` 27 | 28 | ### relative 定位 29 | 30 | 相对定位元素的定位是相对其正常位置 31 | 32 | ```css 33 | h2.pos_left 34 | { 35 | position:relative; 36 | left:-20px; 37 | } 38 | h2.pos_right 39 | { 40 | position:relative; 41 | left:20px; 42 | } 43 | ``` 44 | 45 | 相对定位元素经常被用来作为绝对定位元素的容器块 46 | 47 | ### absolute 定位 48 | 49 | 绝对定位的元素的位置相对于最近的已定位父元素,如果元素没有已定位的父元素,那么它的位置相对于 50 | 51 | ```css 52 | h2 53 | { 54 | position:absolute; 55 | left:100px; 56 | top:150px; 57 | } 58 | ``` 59 | 60 | ### 重叠的元素 61 | 62 | 元素的定位与文档流无关,所以它们可以覆盖页面上的其它元素 63 | 64 | z-index属性指定了一个元素的堆叠顺序(哪个元素应该放在前面,或后面) 65 | 66 | 一个元素可以有正数或负数的堆叠顺序 67 | 68 | ```css 69 | img 70 | { 71 | position:absolute; 72 | left:0px; 73 | top:0px; 74 | z-index:-1; 75 | } 76 | ``` 77 | 78 | ### 定位所有属性 79 | 80 | | 属性 | 说明 | 值 | CSS | 81 | | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ---- | 82 | | [bottom](https://www.w3cschool.cn/cssref/pr-pos-bottom.html) | 定义了定位元素下外边距边界与其包含块下边界之间的偏移。 | auto *length%*inherit | 2 | 83 | | [clip](https://www.w3cschool.cn/cssref/pr-pos-clip.html) | 剪辑一个绝对定位的元素 | *shape*auto inherit | 2 | 84 | | [cursor](https://www.w3cschool.cn/cssref/pr-class-cursor.html) | 显示光标移动到指定的类型 | *url*auto crosshair default pointer move e-resize ne-resize nw-resize n-resize se-resize sw-resize s-resize w-resize text wait help | 2 | 85 | | [left](https://www.w3cschool.cn/cssref/pr-pos-left.html) | 定义了定位元素左外边距边界与其包含块左边界之间的偏移。 | auto *length%*inherit | 2 | 86 | | [overflow](https://www.w3cschool.cn/cssref/pr-pos-overflow.html) | 设置当元素的内容溢出其区域时发生的事情。 | auto hidden scroll visible inherit | 2 | 87 | | [position](https://www.w3cschool.cn/cssref/pr-class-position.html) | 指定元素的定位类型 | absolute fixed relative static inherit | 2 | 88 | | [right](https://www.w3cschool.cn/cssref/pr-pos-right.html) | 定义了定位元素右外边距边界与其包含块右边界之间的偏移。 | auto *length%*inherit | 2 | 89 | | [top](https://www.w3cschool.cn/cssref/pr-pos-top.html) | 定义了一个定位元素的上外边距边界与其包含块上边界之间的偏移。 | auto *length%*inherit | 2 | 90 | | [z-index](https://www.w3cschool.cn/cssref/pr-pos-z-index.html) | 设置元素的堆叠顺序 | *number*auto inherit | 2 | -------------------------------------------------------------------------------- /css/css学习笔记/尺寸.md: -------------------------------------------------------------------------------- 1 | ## 尺寸(dimension) 2 | 3 | CSS 尺寸 (Dimension) 属性允许你控制元素的高度和宽度。同样,它允许你增加行间距 4 | 5 | | 属性 | 描述 | 6 | | ------------------------------------------------------------ | -------------------- | 7 | | [height](https://www.w3cschool.cn/cssref/pr-dim-height.html) | 设置元素的高度。 | 8 | | [line-height](https://www.w3cschool.cn/cssref/pr-dim-line-height.html) | 设置行高。 | 9 | | [max-height](https://www.w3cschool.cn/cssref/pr-dim-max-height.html) | 设置元素的最大高度。 | 10 | | [max-width](https://www.w3cschool.cn/cssref/pr-dim-max-width.html) | 设置元素的最大宽度。 | 11 | | [min-height](https://www.w3cschool.cn/cssref/pr-dim-min-height.html) | 设置元素的最小高度。 | 12 | | [min-width](https://www.w3cschool.cn/cssref/pr-dim-min-width.html) | 设置元素的最小宽度。 | 13 | | [width](https://www.w3cschool.cn/cssref/pr-dim-width.html) | 设置元素的宽度。 | -------------------------------------------------------------------------------- /css/css学习笔记/嵌套选择器.md: -------------------------------------------------------------------------------- 1 | ## 嵌套选择器 2 | 3 | CSS嵌套适用于选择器内部的选择器的样式。它可能适用于选择器内部的选择器的样式。 4 | 5 | ```html 6 | 7 | 8 | 9 | 10 | W3Cschool教程(w3cschool.cn) 11 | 26 | 27 | 28 | 29 |

This paragraph has blue text, and is center aligned.

30 |
31 |

This paragraph has not blue text.

32 |
33 |

p elements inside a "marked" classed element keeps the alignment style, but has a different text color.

34 | 35 | 36 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/文本.md: -------------------------------------------------------------------------------- 1 | ### 颜色(color) 2 | 3 | 颜色属性被用来设置文字的颜色 4 | 5 | ```html 6 | 7 | 8 | 9 | 10 | W3Cschool教程(w3cschool.cn) 11 | 16 | 17 | 18 | 19 |

This is heading 1

20 |

This is an ordinary paragraph. Notice that this text is red. The default text-color for a page is defined in the body selector.

21 |

This is a paragraph with class="ex". This text is blue.

22 | 23 | 24 | ``` 25 | 26 | ### 对齐方式(text-align) 27 | 28 | 文本排列属性是用来设置文本的水平对齐方式 29 | 30 | 文本可居中或对齐到左或右,两端对齐 31 | 32 | 当text-align设置为"justify",每一行被展开为宽度相等,左,右外边距是对齐(如杂志和报纸) 33 | 34 | ```html 35 | 36 | 37 | 38 | 39 | W3Cschool教程(w3cschool.cn) 40 | 45 | 46 | 47 | 48 |

CSS text-align 实例

49 |

2015 年 3 月 14 号

50 |

“当我年轻的时候,我梦想改变这个世界;当我成熟以后,我发现我不能够改变这个世界,我将目光缩短了些,决定只改变我的国家;当我进入暮年以后,我发现我不能够改变我们的国家,我的最后愿望仅仅是改变一下我的家庭,但是,这也不可能。当我现在躺在床上,行将就木时,我突然意识到:如果一开始我仅仅去改变我自己,然后,我可能改变我的家庭;在家人的帮助和鼓励下,我可能为国家做一些事情;然后,谁知道呢?我甚至可能改变这个世界。”

51 |

注意: 重置浏览器窗口大小查看 "justify" 是如何工作的。

52 | 53 | 54 | 55 | ``` 56 | 57 | ### 修饰(text-decoration) 58 | 59 | text-decoration 属性用来设置或删除文本的装饰 60 | 61 | 从设计的角度看 text-decoration属性主要是用来删除链接的下划线 62 | 63 | ```html 64 | 65 | 66 | 67 | 68 | W3Cschool教程(w3cschool.cn) 69 | 75 | 76 | 77 | 78 |

This is heading 1

79 |

This is heading 2

80 |

This is heading 3

81 |

Link to: w3cschool.cn

82 | 83 | 84 | 85 | ``` 86 | 87 | ### 转换(text-transform) 88 | 89 | 文本转换属性是用来指定在一个文本中的大写和小写字母 90 | 91 | 可用于所有字句变成大写或小写字母,或每个单词的首字母大写 92 | 93 | ```html 94 | 95 | 96 | 97 | 98 | W3Cschool教程(w3cschool.cn) 99 | 104 | 105 | 106 | 107 |

This is some text.

108 |

This is some text.

109 |

This is some text.

110 | 111 | 112 | ``` 113 | 114 | ### 缩进(text-indent) 115 | 116 | 文本缩进属性是用来指定文本的第一行的缩进 117 | 118 | ```html 119 | 120 | 121 | 122 | 123 | W3Cschool教程(w3cschool.cn) 124 | 127 | 128 | 129 | 130 |

In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing anyone,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.'

131 | 132 | 133 | 134 | ``` 135 | 136 | ### 间隔(word-spacing) 137 | 138 | word-spacing 属性可以改变字(单词)之间的标准间隔。其默认值 normal 与设置值为 0 是一样的 139 | 140 | ```html 141 | 142 | 143 | 144 | 145 | W3Cschool教程(w3cschool.cn) 146 | 152 | 153 | 154 | 155 |

156 | This is some text. This is some text. 157 |

158 | 159 | 160 | 161 | ``` 162 | 163 | ### 所有css文本属性 164 | 165 | | 属性 | 描述 | 166 | | ------------------------------------------------------------ | ------------------------ | 167 | | [color](https://www.w3cschool.cn/cssref/pr-text-color.html) | 设置文本颜色 | 168 | | [direction](https://www.w3cschool.cn/cssref/pr-text-direction.html) | 设置文本方向 | 169 | | [letter-spacing](https://www.w3cschool.cn/cssref/pr-text-letter-spacing.html) | 设置字符间距 | 170 | | [line-height](https://www.w3cschool.cn/cssref/pr-dim-line-height.html) | 设置行高 | 171 | | [text-align](https://www.w3cschool.cn/cssref/pr-text-text-align.html) | 对齐元素中的文本 | 172 | | [text-decoration](https://www.w3cschool.cn/cssref/pr-text-text-decoration.html) | 向文本添加修饰 | 173 | | [text-indent](https://www.w3cschool.cn/cssref/pr-text-text-indent.html) | 缩进元素中文本的首行 | 174 | | [text-shadow](https://www.w3cschool.cn/cssref/css3-pr-text-shadow.html) | 设置文本阴影 | 175 | | [text-transform](https://www.w3cschool.cn/cssref/pr-text-text-transform.html) | 控制元素中的字母 | 176 | | [unicode-bidi](https://www.w3cschool.cn/cssref/pr-text-unicode-bidi.html) | 设置或返回文本是否被重写 | 177 | | [vertical-align](https://www.w3cschool.cn/cssref/pr-pos-vertical-align.html) | 设置元素的垂直对齐 | 178 | | [white-space](https://www.w3cschool.cn/cssref/pr-text-white-space.html) | 设置元素中空白的处理方式 | 179 | | [word-spacing](https://www.w3cschool.cn/cssref/pr-text-word-spacing.html) | 设置字间距 | -------------------------------------------------------------------------------- /css/css学习笔记/显示和可见性.md: -------------------------------------------------------------------------------- 1 | ## 显示(display)和可见性(visibility) 2 | 3 | display 属性和 visibility属性都可以用来隐藏某个元素,但是这两个属性有不同的定义 4 | 5 | ### 隐藏元素 display:none或visibility:hidden 6 | 7 | 隐藏一个元素可以通过把display属性设置为"none",或把visibility属性设置为"hidden" 8 | 9 | visibility:hidden可以隐藏某个元素,但隐藏的元素仍需占用与未隐藏之前一样的空间。也就是说,该元素虽然被隐藏了,但仍然会影响布局 10 | 11 | ```css 12 | h1.hidden {visibility:hidden;} 13 | ``` 14 | 15 | display:none可以隐藏某个元素,且隐藏的元素不会占用任何空间。也就是说,该元素不但被隐藏了,而且该元素原本占用的空间也会从页面布局中消失 16 | 17 | ```css 18 | h1.hidden {display:none;} -------------------------------------------------------------------------------- /css/css学习笔记/样式表.md: -------------------------------------------------------------------------------- 1 | ### 外部样式表 2 | 3 | 当样式需要应用于很多页面时,外部样式表将是理想的选择 4 | 5 | 在使用外部样式表的情况下,你可以通过改变一个文件来改变整个站点的外观 6 | 7 | ```html 8 | 9 | ``` 10 | 11 | 外部样式表可以在任何文本编辑器中进行编辑 12 | 13 | 文件不能包含任何的 html 标签 14 | 15 | 样式表应该以 .css 扩展名进行保存 16 | 17 | ```css 18 | hr {color:sienna;} 19 | p {margin-left:20px;} 20 | body {background-image:url(/images/back40.gif);} 21 | ``` 22 | 23 | #### 内部样式表 24 | 25 | 当单个文档需要特殊的样式时,就应该使用内部样式表 26 | 27 | 你可以使用 36 | 37 | ``` 38 | 39 | ### 内联样式 40 | 41 | 由于要将表现和内容混杂在一起,内联样式会损失掉样式表的许多优势,请慎用这种方法 42 | 43 | 例如当样式仅需要在一个元素上应用一次时,要使用内联样式,你需要在相关的标签内使用样式(style)属性,Style 属性可以包含任何 CSS 属性 44 | 45 | ```html 46 |

这是一个段落。

47 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/注释.md: -------------------------------------------------------------------------------- 1 | ## 注释 2 | 3 | ```css 4 | /*这是个注释*/ 5 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/浮动.md: -------------------------------------------------------------------------------- 1 | ## 浮动(float) 2 | 3 | CSS 的 Float(浮动),会使元素向左或向右移动,其周围的元素也会重新排列 4 | 5 | Float(浮动),往往是用于图像,但它在布局时一样非常有用 6 | 7 | ### 元素怎样浮动 8 | 9 | 元素的水平方向浮动,意味着元素只能左右移动而不能上下移动 10 | 11 | 浮动元素之后的元素将围绕它 12 | 13 | 浮动元素之前的元素将不会受到影响 14 | 15 | ```html 16 | 17 | 18 | 19 | 20 | W3Cschool(w3cschool.cn) 21 | 27 | 28 | 29 | 30 |

在下面的段落中,我们添加了一个 float:left 的图片。导致图片将会浮动在段落的左边。

31 |

32 | 33 | 这是一些文本。这是一些文本。这是一些文本。 34 | 这是一些文本。这是一些文本。这是一些文本。 35 | 这是一些文本。这是一些文本。这是一些文本。 36 | 这是一些文本。这是一些文本。这是一些文本。 37 | 这是一些文本。这是一些文本。这是一些文本。 38 | 这是一些文本。这是一些文本。这是一些文本。 39 | 这是一些文本。这是一些文本。这是一些文本。 40 | 这是一些文本。这是一些文本。这是一些文本。 41 | 这是一些文本。这是一些文本。这是一些文本。 42 | 这是一些文本。这是一些文本。这是一些文本。 43 |

44 | 45 | 46 | 47 | ``` 48 | 49 | ### 彼此相邻的浮动元素 50 | 51 | 如果你把几个浮动的元素放到一起,如果有空间的话,它们将彼此相邻 52 | 53 | ```html 54 | 55 | 56 | 57 | 58 | W3Cschool教程(w3cschool.cn) 59 | 68 | 69 | 70 | 71 |

图片库

72 |

试着调整窗口,看看当图片没有足够的空间会发生什么。

73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | ``` 84 | 85 | ### 清除浮动(clear) 86 | 87 | 元素浮动之后,周围的元素会重新排列,为了避免这种情况,使用 clear 属性 88 | 89 | clear 属性指定元素两侧不能出现浮动元素 90 | 91 | ```html 92 | 93 | 94 | 95 | 96 | W3Cschool教程(w3cschool.cn) 97 | 111 | 112 | 113 | 114 |

图片库

115 |

试着调整窗口,看看当图片没有足够的空间会发生什么。.

116 | 117 | 118 | 119 | 120 |

第二行

121 | 122 | 123 | 124 | 125 | 126 | 127 | ``` 128 | 129 | ### 浮动的所有属性 130 | 131 | | 属性 | 描述 | 值 | CSS | 132 | | ------------------------------------------------------------ | ---------------------------------- | ---------------------------- | ---- | 133 | | [clear](https://www.w3cschool.cn/cssref/pr-class-clear.html) | 指定不允许元素周围有浮动元素。 | left right both none inherit | 1 | 134 | | [float](https://www.w3cschool.cn/cssref/pr-class-float.html) | 指定一个盒子(元素)是否可以浮动。 | left right none inherit | 1 | -------------------------------------------------------------------------------- /css/css学习笔记/盒子模型.md: -------------------------------------------------------------------------------- 1 | ## 盒子模型 2 | 3 | CSS盒模型本质上是一个盒子,封装周围的HTML元素,它包括:边距,边框,填充,和实际内容 4 | 5 | ![](https://www.w3cschool.cn/statics/images/course/box-model.gif) 6 | 7 | 不同部分的说明: 8 | 9 | - **Margin(外边距)** - 清除边框区域。Margin没有背景颜色,它是完全透明 10 | - **Border(边框)** - 边框周围的填充和内容。边框是受到盒子的背景颜色影响 11 | - **Padding(内边距)** - 清除内容周围的区域。会受到框中填充的背景颜色影响 12 | - **Content(内容)** - 盒子的内容,显示文本和图像 13 | 14 | 在盒模型中,外边距可以是负值,而且在很多情况下都要使用负值的外边距 -------------------------------------------------------------------------------- /css/css学习笔记/简介.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 3 | * CSS 指层叠样式表 (Cascading Style Sheets) 4 | * 样式定义**如何显示** HTML 元素 5 | * 样式通常存储在**样式表**中 6 | * 把样式添加到 HTML 4.0 中,是为了**解决内容与表现分离的问题** 7 | * **外部样式表**可以极大提高工作效率,外部样式表通常存储在 **.css 文件**中 8 | * 多个样式定义可**层叠**为一个 9 | * 样式对网页中元素位置的排版进行像素级精确控制 -------------------------------------------------------------------------------- /css/css学习笔记/组合选择器.md: -------------------------------------------------------------------------------- 1 | ## 组合选择器 2 | 3 | CSS 组合选择器可以让你直观的明白选择器与选择器之间的关系 4 | 5 | 在 CSS3 中包含了四种组合方式: 6 | 7 | - 后代选取器(以空格分隔) 8 | - 子元素选择器(以大于号分隔) 9 | - 相邻兄弟选择器(以加号分隔) 10 | - 普通兄弟选择器(以波浪号分隔) 11 | 12 | ### 后代选取器(以空格分隔) 13 | 14 | 后代选取器匹配所有指定元素的后代元素 15 | 16 | ```html 17 | 18 | 19 | 20 | 21 | W3Cschool教程(w3cschool.cn) 22 | 28 | 29 | 30 | 31 |
32 |

段落 1。 在 div 中。

33 |

段落 2。 在 div 中。

34 |
35 | 36 |

段落 3。不在 div 中。

37 |

段落 4。不在 div 中。

38 | 39 | 40 | 41 | ``` 42 | 43 | ### 子元素选择器(以大于号分隔) 44 | 45 | 与后代选择器相比,子元素选择器(Child selectors)只能选择作为某元素子元素的元素 46 | 47 | ```html 48 | 49 | 50 | 51 | 52 | W3Cschool教程(w3cschool.cn) 53 | 59 | 60 | 61 | 62 |

Welcome to My Homepage

63 |
64 |

My name is Donald

65 |

I live in Duckburg.

66 |
67 | 68 |
69 |

I will not be styled.

70 |
71 | 72 |

My best friend is Mickey.

73 | 74 | 75 | ``` 76 | 77 | ### 相邻兄弟选择器(以加号分隔) 78 | 79 | 相邻兄弟选择器(Adjacent sibling selector)可选择紧接在另一元素后的元素,且二者有相同父元素 80 | 81 | 如果需要选择紧接在另一个元素后的元素,而且二者有相同的父元素,可以使用相邻兄弟选择器(Adjacent sibling selector) 82 | 83 | ```html 84 | 85 | 86 | 87 | 88 | W3Cschool教程(w3cschool.cn) 89 | 95 | 96 | 97 | 98 |

Welcome to My Homepage

99 | 100 |
101 |

My name is Donald

102 |

I live in Duckburg.

103 |
104 | 105 |

My best friend is Mickey.

106 | 107 |

I will not be styled.

108 | 109 | 110 | 111 | ``` 112 | 113 | ### 普通相邻兄弟选择器(以波浪号分隔) 114 | 115 | 普通兄弟选择器选取所有指定元素的相邻兄弟元素 116 | 117 | ```html 118 | 119 | 120 | 121 | 122 | W3Cschool教程(w3cschool.cn) 123 | 129 | 130 | 131 | 132 |
133 |

段落 1。 在 div 中。

134 |

段落 2。 在 div 中。

135 |
136 | 137 |

段落 3。不在 div 中。

138 |

段落 4。不在 div 中。

139 | 140 | 141 | 142 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/网格视图.md: -------------------------------------------------------------------------------- 1 | ## 网格视图 2 | 3 | 使用网格视图有助于我们设计网页。这让我们向网页添加元素变的更简单 4 | 5 | ### 创建响应式网格视图 6 | 7 | 首先确保所有的 HTML 元素都有 **box-sizing** 属性且设置为 **border-box** 8 | 9 | 确保边距和边框包含在元素的宽度和高度间 10 | 11 | ```html 12 | 13 | 14 | 15 | 16 | 65 | 66 | 67 | 68 |
69 |

Chania

70 |
71 | 72 |
73 | 74 | 82 | 83 |
84 |

The City

85 |

Chania is the capital of the Chania region on the island of Crete. The city can be divided in two parts, the old town and the modern city.

86 |

Resize the browser window to see how the content respond to the resizing.

87 |
88 | 89 |
90 | 91 | 92 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/背景.md: -------------------------------------------------------------------------------- 1 | ## 背景(Backgrounds) 2 | 3 | 背景属性用于定义HTML元素的背景 4 | 5 | - background-color 背景颜色 6 | - background-image 背景图像 7 | - background-repeat 设置背景图像是否及如何重复 8 | - background-attachment 背景图像是否固定或者随着页面的其余部分滚动 9 | - background-position 设置背景图像的起始位置 10 | 11 | ### 背景颜色(background-color) 12 | 13 | background-color 属性定义了元素的背景颜色 14 | 15 | ```css 16 | h1 {background-color:#6495ed;} 17 | p {background-color:#e0ffff;} 18 | div {background-color:#b0c4de;} 19 | ``` 20 | 21 | 可以为所有元素设置背景色,包括 body 一直到 em 和 a 等行内元素 22 | 23 | background-color 不能继承,其默认值是 transparent。如果一个元素没有指定背景色,那么背景就是透明的,这样其父元素的背景才可见 24 | 25 | ### 背景图像(backgrond-image) 26 | 27 | background-image 属性描述了元素的背景图像 28 | 29 | 默认情况下,背景图像进行平铺重复显示,以覆盖整个元素实体 30 | 31 | ```css 32 | body 33 | { 34 | background-image:url('http://img.w3cschool.cn/attachments/knowledge/201611/31824.png'); 35 | background-color:#cccccc; 36 | } 37 | ``` 38 | 39 | ### 定位 40 | 41 | ```css 42 | body 43 | { 44 | background-image:url('img_tree.png'); 45 | background-repeat:no-repeat; 46 | background-position:right top; 47 | } 48 | ``` 49 | 50 | #### 关键字 51 | 52 | | 单一关键字 | 等价的关键字 | 53 | | ---------- | ------------------------------ | 54 | | center | center center | 55 | | top | top center 或 center top | 56 | | bottom | bottom center 或 center bottom | 57 | | right | right center 或 center right | 58 | | left | left center 或 center left | 59 | 60 | #### 百分数值 61 | 62 | ```css 63 | body 64 | { 65 | background-image:url('img_tree.png'); 66 | background-repeat:no-repeat; 67 | background-position:66% 33%; 68 | } 69 | ``` 70 | 71 | #### 长度值 72 | 73 | ```css 74 | body 75 | { 76 | background-image:url('img_tree.png'); 77 | background-repeat:no-repeat; 78 | background-position:50px 100px; 79 | } 80 | ``` 81 | 82 | ### 重复模式 83 | 84 | | 值 | 说明 | 85 | | --------- | -------------------------------------------- | 86 | | repeat | 背景图像将向垂直和水平方向重复。这是默认 | 87 | | repeat-x | 只有水平位置会重复背景图像 | 88 | | repeat-y | 只有垂直位置会重复背景图像 | 89 | | no-repeat | background-image不会重复 | 90 | | inherit | 指定background-repea属性设置应该从父元素继承 | 91 | 92 | ### 简写属性 93 | 94 | ```css 95 | body {background:#ffffff url('img_tree.png') no-repeat right top;} 96 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/表格.md: -------------------------------------------------------------------------------- 1 | ## 表格(table) 2 | 3 | 使用css提升html表格的外观 4 | 5 | ### 边框(border) 6 | 7 | ```css 8 | table, th, td 9 | { 10 | border: 1px solid black; 11 | } 12 | ``` 13 | 14 | 在上面的例子中的表格有双边框。这是因为表和th/ td元素有独立的边界 15 | 16 | 为了显示一个表的单个边框,使用 border-collapse属性 17 | 18 | ### 折叠边框(border-collapse) 19 | 20 | ```css 21 | table 22 | { 23 | border-collapse:collapse; 24 | } 25 | table,th, td 26 | { 27 | border: 1px solid black; 28 | } 29 | ``` 30 | 31 | ### 宽度和高度(width,height) 32 | 33 | ```css 34 | table 35 | { 36 | width:100%; 37 | } 38 | th 39 | { 40 | height:50px; 41 | } 42 | ``` 43 | 44 | ### 文字对齐(text-align,vertical-align) 45 | 46 | 表格中的文本对齐和垂直对齐属性 47 | 48 | text-align属性设置水平对齐方式,像左,右,或中心: 49 | 50 | ```css 51 | td 52 | { 53 | text-align:right; 54 | } 55 | ``` 56 | 57 | 垂直对齐属性设置垂直对齐,比如顶部,底部或中间: 58 | 59 | ```css 60 | td 61 | { 62 | height:50px; 63 | vertical-align:bottom; 64 | } 65 | ``` 66 | 67 | ### 填充 68 | 69 | 如果在表的内容中控制空格之间的边框,应使用td和th元素的填充属性 70 | 71 | ```css 72 | td 73 | { 74 | padding:15px; 75 | } 76 | ``` 77 | 78 | ### 颜色 79 | 80 | 下面的例子指定边框的颜色,和th元素的文本和背景颜色 81 | 82 | ```css 83 | table, td, th 84 | { 85 | border:1px solid green; 86 | } 87 | th 88 | { 89 | background-color:green; 90 | color:white; 91 | } 92 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/语法.md: -------------------------------------------------------------------------------- 1 | ## 语法 2 | 3 | CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明 4 | 5 | ```css 6 | h1 {color:blue;font-size:12px;} 7 | ``` 8 | 9 | 选择器通常是您需要改变样式的 HTML 元素。 10 | 11 | 每条声明由一个属性和一个值组成。 12 | 13 | 属性(property)是您希望设置的样式属性(style attribute)。每个属性有一个值。属性和值被冒号分开。 14 | 15 | ```html 16 | 17 | 18 | 19 | 20 | W3Cschool教程(w3cschool.cn) 21 | 28 | 29 | 30 | 31 |

Hello World!

32 |

This paragraph is styled with CSS.

33 | 34 | 35 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/轮廓.md: -------------------------------------------------------------------------------- 1 | ## 轮廓(outline) 2 | 3 | 轮廓(outline)是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用 4 | 5 | 轮廓(outline)属性指定了样式,颜色和外边框的宽度 6 | 7 | 轮廓(outline)属性的位置让它不像边框那样参与到文档流中,因此轮廓出现或消失时不会影响文档流,即不会导致文档的重新显示 8 | 9 | ![](https://www.w3cschool.cn/statics/images/course/box_outline.gif) 10 | 11 | ### 轮廓属性 12 | 13 | | 属性 | 说明 | 值 | CSS | 14 | | ------------------------------------------------------------ | -------------------------------- | -------------------------------------------------------- | ---- | 15 | | [outline](https://www.w3cschool.cn/cssref/pr-outline.html) | 在一个声明中设置所有的外边框属性 | *outline-coloroutline-styleoutline-width*inherit | 2 | 16 | | [outline-color](https://www.w3cschool.cn/cssref/pr-outline-color.html) | 设置外边框的颜色 | *color-namehex-numberrgb-number*invertinherit | 2 | 17 | | [outline-style](https://www.w3cschool.cn/cssref/pr-outline-style.html) | 设置外边框的样式 | nonedotteddashedsoliddoublegrooveridgeinsetoutsetinherit | 2 | 18 | | [outline-width](https://www.w3cschool.cn/cssref/pr-outline-width.html) | 设置外边框的宽度 | thinmediumthick*length*inherit | | -------------------------------------------------------------------------------- /css/css学习笔记/边框.md: -------------------------------------------------------------------------------- 1 | ## 边框(border) 2 | 3 | CSS 边框 (border) 可以是围绕元素内容和内边距的一条或多条线,对于这些线条,您可以自定义它们的样式、宽度以及颜色 4 | 5 | ### 样式(border-style) 6 | 7 | ```html 8 | 9 | 10 | 11 | 12 | W3Cschool教程(w3cschool.cn) 13 | 35 | 36 | 37 | 38 |

No border.

39 |

A dotted border.

40 |

A dashed border.

41 |

A solid border.

42 |

A double border.

43 |

A groove border.

44 |

A ridge border.

45 |

An inset border.

46 |

An outset border.

47 | 48 | 49 | 50 | 51 | ``` 52 | 53 | ### 宽度(border-width) 54 | 55 | 为边框指定宽度有两种方法:可以指定长度值,比如 2px 或 0.1em;或者使用 3 个关键字之一,它们分别是 thin 、medium(默认值) 和 thick 56 | 57 | ### 颜色(border-color) 58 | 59 | border-color属性用于设置边框的颜色,它一次可以接受最多 4 个颜色值 60 | 61 | 您还可以设置边框的颜色为"transparent" 62 | 63 | border-color单独使用是不起作用的,必须得先使用border-style来设置边框样式 64 | 65 | ### 单独设置各边的样式 66 | 67 | ```css 68 | p 69 | { 70 | border-top-style:dotted; 71 | border-right-style:solid; 72 | border-bottom-style:dotted; 73 | border-left-style:solid; 74 | } 75 | ``` 76 | 77 | ### css边框全部属性 78 | 79 | | 属性 | 描述 | 80 | | ------------------------------------------------------------ | ------------------------------------------------------------ | 81 | | [border](https://www.w3cschool.cn/cssref/pr-border.html) | 简写属性,用于把针对四个边的属性设置在一个声明。 | 82 | | [border-style](https://www.w3cschool.cn/cssref/pr-border-style.html) | 用于设置元素所有边框的样式,或者单独地为各边设置边框样式。 | 83 | | [border-width](https://www.w3cschool.cn/cssref/pr-border-width.html) | 简写属性,用于为元素的所有边框设置宽度,或者单独地为各边边框设置宽度。 | 84 | | [border-color](https://www.w3cschool.cn/cssref/pr-border-color.html) | 简写属性,设置元素的所有边框中可见部分的颜色,或为 4 个边分别设置颜色。 | 85 | | [border-bottom](https://www.w3cschool.cn/cssref/pr-border-bottom.html) | 简写属性,用于把下边框的所有属性设置到一个声明中。 | 86 | | [border-bottom-color](https://www.w3cschool.cn/cssref/pr-border-bottom-color.html) | 设置元素的下边框的颜色。 | 87 | | [border-bottom-style](https://www.w3cschool.cn/cssref/pr-border-bottom-style.html) | 设置元素的下边框的样式。 | 88 | | [border-bottom-width](https://www.w3cschool.cn/cssref/pr-border-bottom-width.html) | 设置元素的下边框的宽度。 | 89 | | [border-left](https://www.w3cschool.cn/cssref/pr-border-left.html) | 简写属性,用于把左边框的所有属性设置到一个声明中。 | 90 | | [border-left-color](https://www.w3cschool.cn/cssref/pr-border-left-color.html) | 设置元素的左边框的颜色。 | 91 | | [border-left-style](https://www.w3cschool.cn/cssref/pr-border-left-style.html) | 设置元素的左边框的样式。 | 92 | | [border-left-width](https://www.w3cschool.cn/cssref/pr-border-left-width.html) | 设置元素的左边框的宽度。 | 93 | | [border-right](https://www.w3cschool.cn/cssref/pr-border-right.html) | 简写属性,用于把右边框的所有属性设置到一个声明中。 | 94 | | [border-right-color](https://www.w3cschool.cn/cssref/pr-border-right-color.html) | 设置元素的右边框的颜色。 | 95 | | [border-right-style](https://www.w3cschool.cn/cssref/pr-border-right-style.html) | 设置元素的右边框的样式。 | 96 | | [border-right-width](https://www.w3cschool.cn/cssref/pr-border-right-width.html) | 设置元素的右边框的宽度。 | 97 | | [border-top](https://www.w3cschool.cn/cssref/pr-border-top.html) | 简写属性,用于把上边框的所有属性设置到一个声明中。 | 98 | | [border-top-color](https://www.w3cschool.cn/cssref/pr-border-top-color.html) | 设置元素的上边框的颜色。 | 99 | | [border-top-style](https://www.w3cschool.cn/cssref/pr-border-top-style.html) | 设置元素的上边框的样式。 | 100 | | [border-top-width](https://www.w3cschool.cn/cssref/pr-border-top-width.html) | 设置元素的上边框的宽度。 | -------------------------------------------------------------------------------- /css/css学习笔记/选择器.md: -------------------------------------------------------------------------------- 1 | ## 选择器 2 | 3 | 如果你要在HTML元素中设置CSS样式,你需要在元素中设置"id" 或 "class"选择器。 4 | 5 | ### id选择器(#) 6 | 7 | ```css 8 | #para1 9 | { 10 | text-align:center; 11 | color:red; 12 | } 13 | ``` 14 | 15 | id 选择器可以为标有特定 id 的 HTML 元素指定特定的样式 16 | 17 | HTML元素以id属性来设置id选择器,CSS 中 id 选择器以 "#" 来定义 18 | 19 | ```html 20 | 21 | 22 | 23 | 24 | W3Cschool教程(w3cschool.cn) 25 | 32 | 33 | 34 | 35 |

Hello World!!!

36 |

This paragraph is not affected by the style.

37 | 38 | 39 | ``` 40 | 41 | > ID属性不要以数字开头,数字开头的ID在 Mozilla/Firefox 浏览器中不起作用 42 | > 43 | > ID属性只能在每个 HTML 文档中出现一次 44 | 45 | ### class 选择器(.) 46 | 47 | ```css 48 | .center { 49 | text-align:center; 50 | color:red; 51 | } 52 | ``` 53 | 54 | class 选择器用于描述一组元素的样式,class 选择器有别于id选择器,class可以在多个元素中使用 55 | 56 | class 选择器在HTML中以class属性表示, 在 CSS 中,类选择器以一个点"."号显示 57 | 58 | **所有拥有 center 类的 HTML 元素均为居中** 59 | 60 | ```html 61 | 62 | 63 | 64 | 65 | W3Cschool教程(w3cschool.cn) 66 | 72 | 73 | 74 | 75 |

标题居中

76 |

段落居中。

77 | 78 | 79 | ``` 80 | 81 | **所有的 p 元素使用 class="center" 让该元素的文本居中** 82 | 83 | ```html 84 | 85 | 86 | 87 | 88 | W3Cschool教程(w3cschool.cn) 89 | 95 | 96 | 97 | 98 |

This heading will not be affected

99 |

This paragraph will be center-aligned.

100 | 101 | 102 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/链接.md: -------------------------------------------------------------------------------- 1 | ### 链接样式 2 | 3 | 链接的样式,可以用任何CSS属性(如颜色,字体,背景等) 4 | 5 | 特别的链接,可以有不同的样式,这取决于他们是什么状态 6 | 7 | 这四个链接状态是: 8 | 9 | - a:link - 正常,未访问过的链接 10 | - a:visited - 用户已访问过的链接 11 | - a:hover - 当用户鼠标放在链接上时 12 | - a:active - 链接被点击的那一刻 13 | 14 | ```html 15 | 16 | 17 | 18 | 19 | W3Cschool教程(w3cschool.cn) 20 | 26 | 27 | 28 | 29 |

这是一个链接

30 |

注意: a:hover 必须在 a:link 和 a:visited 之后,需要严格按顺序才能看到效果。

31 |

注意: a:active 必须在 a:hover 之后。

32 | 33 | 34 | ``` 35 | 36 | ### 文本修饰(text-decoration) 37 | 38 | ```css 39 | a:link {text-decoration:none;} 40 | a:visited {text-decoration:none;} 41 | a:hover {text-decoration:underline;} 42 | a:active {text-decoration:underline;} 43 | ``` 44 | 45 | ### 背景颜色 46 | 47 | 背景颜色属性指定链接背景色 48 | 49 | ```css 50 | a:link {background-color:#B2FF99;} 51 | a:visited {background-color:#FFFF85;} 52 | a:hover {background-color:#FF704D;} 53 | a:active {background-color:#FF704D;} 54 | ``` -------------------------------------------------------------------------------- /css/css学习笔记/颜色的写法.md: -------------------------------------------------------------------------------- 1 | ## 颜色的写法 2 | 3 | **英文单词** 4 | 5 | ```css 6 | p { color: red; } 7 | ``` 8 | 9 | **16进制** 10 | 11 | ```css 12 | p { color: #ff0000; } 13 | p { color: #f00; } 14 | ``` 15 | 16 | **RGB值** 17 | 18 | ```css 19 | p { color: rgb(255,0,0); } 20 | p { color: rgb(100%,0%,0%); } 21 | ``` -------------------------------------------------------------------------------- /data_structure/_sidebar.md: -------------------------------------------------------------------------------- 1 | - 数据结构 2 | - [简介](data_structure/intro.md) 3 | - [数组](data_structure/array.md) 4 | - [线性表](data_structure/list.md) 5 | - [栈](data_structure/stack.md) 6 | - [堆](data_structure/heap.md) 7 | - [队列](data_structure/queue.md) 8 | - [散列表](data_structure/hash_table.md) 9 | - [字符串](data_structure/string.md) 10 | - [树](data_structure/tree.md) 11 | - [图](data_structure/graph.md) 12 | - [参考](data_structure/reference.md) -------------------------------------------------------------------------------- /data_structure/array.md: -------------------------------------------------------------------------------- 1 | # 数组 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/数组) 4 | 5 | -------------------------------------------------------------------------------- /data_structure/graph.md: -------------------------------------------------------------------------------- 1 | # 图 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/图_(数据结构)) 4 | 5 | -------------------------------------------------------------------------------- /data_structure/hash_table.md: -------------------------------------------------------------------------------- 1 | # 哈希表(散列表) 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/哈希表) 4 | 5 | -------------------------------------------------------------------------------- /data_structure/heap.md: -------------------------------------------------------------------------------- 1 | # 堆-Heap 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/堆積) 4 | 5 | 在计算机中存在一个自由存储区,叫做`堆`。 6 | 7 | 这个堆可由C语言的动态分配函数`malloc`和`free`函数来管理,其他语言有各自的实现。 -------------------------------------------------------------------------------- /data_structure/intro.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/数据结构) 4 | 5 | 程序设计 = 数据结构 + 算法 6 | 7 | 数据结构:是相互之间存在一种或多种特定关系的数据元素的集合。 8 | 9 | ## 逻辑结构 10 | 11 | 逻辑结构:是指数据对象中数据元素之间的相互关系。 12 | 13 | * 集合结构:集合结构中的数据元素除了同属与一个集合外,它们之间没有其他关系。 14 | * 线性结构:线性结构中的数据元素之间是一对一的关系。 15 | * 树形结构:树形结构中的数据元素之间存在一对多的层次关系。 16 | * 图形结构:图形结构的数据元素使多对多的关系。 17 | 18 | ## 物理结构 19 | 20 | 物理结构:是指数据的逻辑结构在计算机中的存储形式。 21 | 22 | * 顺序存储结构:是把数据元素存放在地址连续的存储单元里,其数据间的逻辑关系和物理关系是一致的。 23 | * 链式存储结构:是把数据元素存放在任意的存储单元里,这组存储单元可以是连续的,也可以是不连续的。 -------------------------------------------------------------------------------- /data_structure/list.md: -------------------------------------------------------------------------------- 1 | # 线性表-List 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/链表) 4 | 5 | 零个或多个数据元素的`有限`序列 6 | 7 | 线性表的元素的个数(n>=0)定义为线性表的长度,当`n=0`时,称为`空表` 8 | 9 | ## 顺序存储结构 10 | 11 | 线性表的顺序存储结构,指的是用一段地址连续的存储单元依次存储线性表的数据元素。 12 | 13 | Java中的`ArrayList`的底层实现,底层使用`数组`实现。 14 | 15 | 优点: 16 | 17 | * 无须为表示表中元素之间的逻辑关系而增加额外的存储空间 18 | * 查询,添加较快 19 | 20 | 缺点: 21 | 22 | * 插入和删除需要移动大量的元素 23 | * 容器长度需要指定,当元素个数超过指定容量,需要扩容操作 24 | * 造成存储空间的碎片(元素个数较少时,造成的空间浪费) 25 | 26 | ## 链式存储结构 27 | 28 | 由结点(Node)组成 29 | 30 | Java中的`LinkedList`的底层实现 31 | 32 | ### 单链表 33 | 34 | n个结点(Node)链接成一个链表,即为线性表的链式存储结构,因为此链表的每个结点中只包含一个`指针域`,所以叫做`单链表` 35 | 36 | 链表中第一个结点的存储位置叫做`头指针` 37 | 38 | 单链表的最后一个结点的的指针域为“空”(通常用`NULL`或`^`表示) 39 | 40 | 有时为了更加方便的对链表进行操作,会在`单链表`的第一个结点前预设一个`头结点`,但不是必须。 41 | 42 | 结点(Node)由存放数据元素的`数据域`和存放后继结点的`指针域`组成 43 | 44 | ### 静态链表 45 | 46 | 用数组实现的链表就称之为`静态链表`(游标实现法) 47 | 48 | 优点: 49 | 50 | * 在插入和删除操作时,只需要修改游标,不需要移动元素,从而改进了在顺序存储结构中的插入和删除操作需要移动大量元素的缺点 51 | 52 | 缺点: 53 | 54 | * 没有解决需要先设定表长度的问题 55 | * 失去了顺序存储结构随机存取的特性 56 | 57 | ### 循环链表 58 | 59 | 将单链表中`终端结点`的指针由`空指针`指向`头结点`,就使整个单链表形成一个`环`,这种头尾相接的单链表称为`单循环链表`,简称`循环链表(circular linked list)` 60 | 61 | ### 双链表 62 | 63 | `双向链表(double linked list)`是在单链表的每个结点中,在添加一个`指向其前驱结点`的指针域。 64 | 65 | 使用`空间换时间`的方法提升了查询效率 66 | 67 | ## 总结 68 | 69 | * 线性表 70 | * 顺序存储结构 71 | * 链式存储结构 72 | * 单链表 73 | * 静态链表 74 | * 循环链表 75 | * 双向链表 76 | -------------------------------------------------------------------------------- /data_structure/queue.md: -------------------------------------------------------------------------------- 1 | # 队列-Queue 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/队列) 4 | 5 | `队列(queue)`是只允许在一端进行插入操作,而在另一端进行删除操作的线性表。所以队列也有`顺序存储`和`链式存储`两种存储方式。 6 | 7 | 队列是一种`先进先出(First In First Out)`的线性表,简称FIFO。 8 | 9 | 允许插入的一端称为`队尾`,允许删除的一端称为`队头` 10 | 11 | 队列作为一种特性对的线性表,也同样存在两种存储方式 12 | 13 | * 顺序存储 14 | * 链式存储 15 | 16 | ## 顺序队列 17 | 18 | 为了解决`假溢出`,当队尾满了就从队头开始,也就是头尾相接的循环。我们把队列的这种头尾相接的顺序存储结构称为`循环队列`。 19 | 20 | ## 链队列 21 | 22 | 队列的链式存储结构,其实就是线性表的单链表,只不过它只能尾进头出而已,我们把它简称为`链队列`。 23 | 24 | 在可以确定队列长度最大值的情况下,建议使用顺序队列的循环队列。如果无法确定队列的长度时,则用链队列。 -------------------------------------------------------------------------------- /data_structure/reference.md: -------------------------------------------------------------------------------- 1 | # 参考 2 | 3 | * 《大话数据结构》 4 | * [常见的数据结构](https://zhuanlan.zhihu.com/p/93928546) 5 | * [24张图彻底弄懂九大常见数据结构!](https://cloud.tencent.com/developer/article/1634155) 6 | 7 | -------------------------------------------------------------------------------- /data_structure/stack.md: -------------------------------------------------------------------------------- 1 | # 栈-Stack 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/堆栈) 4 | 5 | `栈(stack)`是限定仅在表尾进行插入和删除操作的线性表 6 | 7 | 栈又称为`后进先出(Last In First Out)`的线性表,简称`LIFO`结构 8 | 9 | 允许插入和删除的一端称为`栈顶(top)`,另一端称为`栈底(bottom)` 10 | 11 | 不含任何数据元素的栈称为`空栈` 12 | 13 | 栈的插入操作(push),叫做进栈,也称为压栈,入栈 14 | 15 | 栈的删除操作(pop),叫做出栈,也称为弹栈 16 | 17 | ## 栈的存储结构 18 | 19 | * 顺序栈 20 | * 链栈 21 | 22 | 如果栈的使用过程中`元素个数变化不可预料`,有时小,有时非常大,那么最好使用`链栈`,如果`变化在可控范围内`,那么使用`顺序栈`会更好一点。 23 | 24 | ### 顺序栈 25 | 26 | 既然栈是线性表的特例,那么栈的顺序存储其实也是线性表顺序存储的简化,我们简称为`顺序栈`。 27 | 28 | ### 链栈 29 | 30 | 栈的链式存储结构,简称为`链栈`。 31 | 32 | 对于链栈来说,基本不存在栈满的情况,除非已经没有可以使用的内存空间。 33 | 34 | ## 栈的应用 35 | 36 | * 递归 37 | * 四则运算表达式求值 38 | 39 | ### 递归 40 | 41 | 把一个直接调用自己或通过一系列的调用语句间接调用自己的函数,称作`递归函数`。 42 | 43 | 每个递归定义必须满足至少一个条件,满足时递归不再执行,即不再引用自身而是退出函数。 44 | 45 | ### 四则运算表达式求值 46 | 47 | 我们把平时所用的`标准四则运算表达式`,即"9+(3-1)*3+10/2"叫做`中缀表达式`。 48 | 49 | `不需要括号的`四则运算表达式称为`后缀表示式`,也称为`逆波兰(reverse polish natation)表示`。 50 | 51 | 叫后缀的原因是因为所有的运算符号都是在要运算数字的后面出现。 52 | 53 | >9+(3-1)*3+10/2 54 | > 55 | >转换为后缀表达式: 56 | > 57 | >9 3 1 -3 * + 10 2 / + 58 | 59 | 要让计算机具有处理我们通常的标准(中缀)表达式的能力,最重要的就是两步: 60 | 61 | 1. 将中缀表达式转为后缀表达式(`栈用来进出运算的符号`) 62 | 2. 将后缀表达式进行运算得出结果(`栈用来进出运算的数字`) 63 | 64 | 中缀表达式转后缀表达式:从左到右遍历中缀表达式的每个数字和符号,若是数字就输出,即成为后缀表达式的一部分;若是符号,则判断其与栈顶符号的优先级,是右括号或优先级不高于栈顶符号(乘除高于加减)则栈顶元素依次出栈并输出,并将当前符号进栈,一直到最后输出后缀表达式为止。 65 | 66 | 后缀表达式计算结果:从左到右遍历表达式的每个数字和符号,遇到数字就进栈,遇到是符号,就将处于栈顶两个数字出栈,进行运算,运算结果进栈,一直到最终获得结果。 67 | 68 | -------------------------------------------------------------------------------- /data_structure/string.md: -------------------------------------------------------------------------------- 1 | # 字符串-string 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/字符串) 4 | 5 | `串(string)`是有零个或多个字符组成的有限序列,又名`字符串`。 6 | 7 | 串中的字符数目成为串的长度。 8 | 9 | 零个字符的串称为`空串(null string)`。 10 | 11 | 串也是一种特殊的线性表,所以它也有`顺序存储`和`链式存储`两种存储结构。 12 | 13 | 大多数开发语言中的字符串使用`\0`来表示这个串值的终结。 14 | 15 | ## 模式匹配算法 16 | 17 | 子串的定位操作通常称为串的`模式匹配`。例如:在"goodgoogle"串中找出"google"这个子串。 18 | 19 | ### 朴素的模式匹配算法 20 | 21 | ### KMP模式匹配算法 22 | 23 | [最浅显易懂的 KMP 算法讲解](https://www.bilibili.com/video/BV1AY4y157yL) 24 | 25 | (Knuth和Pratt共同研究,Morris独立研究)发表一个模式匹配算法,可以大大避免重复遍历的情况,我们把它称之为克努特-莫里斯-普拉特算法,简称`KMP`算法。 26 | 27 | -------------------------------------------------------------------------------- /data_structure/tree.md: -------------------------------------------------------------------------------- 1 | # 树-Tree 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/树_(数据结构)) 4 | 5 | `树`是n(n>=0)个结点的有限集。 6 | 7 | n=0时称为`空树`。 8 | 9 | 树的定义大多数使用的是`递归`方法。 10 | 11 | 结点的层次(Level)从根开始定义起,根为第一层,根的孩子为第二层。 12 | 13 | 树结点的最大层次称为树的`深度(Depth)`或`高度`。 14 | 15 | 如果把树中结点的各子树看成从左至右是有次序的,不能互换的,则称该树为`有序树`,否则为`无序树`。 16 | 17 | `森林(Forest)`是`m(m>=0)`棵互不相交的树的集合。 18 | 19 | ## 对比线性表和树的结构 20 | 21 | * 线性表 22 | * 第一个元素:无前驱 23 | * 最后一个元素:无后继 24 | * 中间元素:一个前驱,一个后继 25 | * 树结构 26 | * 根结点:无双亲,唯一 27 | * 叶结点:无孩子,可以多个 28 | * 中间结点:一个双亲,多个孩子 29 | 30 | ## 二叉树 31 | 32 | [维基百科](https://zh.wikipedia.org/wiki/二叉树) 33 | 34 | `二叉树(Binary Tree)`是n(n>=0)个结点的有限集合,该集合或者为空集(空二叉树),或者由一个根节点和两棵互不相交的`左子树`和`右子树`的二叉树组成。 35 | 36 | 二叉树的特点: 37 | 38 | * 每个结点最多两棵子树 39 | * 左子树和右子树是有顺序的 40 | * 即使树中某结点只有一颗子树,也要区分它是左子树还是右子树 41 | 42 | ## 特殊二叉树 43 | 44 | * 斜树 45 | * 满二叉树 46 | * 完全二叉树 47 | 48 | 所有的结点都只有左子树的二叉树叫`左斜树`。所有结点都是只有右子树的二叉树叫`右斜树`。这两者统称为`斜树`。 49 | 50 | 斜树有很明显的特点,就是每一层都只有一个结点,结点的个数与二叉树的深度相同。 51 | 52 | 在一个二叉树中,如果所有分支结点都存在左子树和右子树,并且所有叶子都在**同一层上**,这样的二叉树称为`满二叉树`。 53 | 54 | 对一棵具有n个结点的二叉树按层序编号,如果编号为i(1<=i<=n)的结点与同样深度的满二叉树中编号为i的结点在二叉树中位置完全相同,则这棵树称为`完全二叉树`。 55 | 56 | ## 建立二叉树 57 | 58 | ## 遍历二叉树 59 | 60 | * 前序遍历 61 | * 中序遍历 62 | * 后序遍历 63 | * 层序遍历 64 | 65 | 前序遍历:先根后左再右,先访问根结点,然后前序遍历左子树,再前序遍历右子树。若树为空,则空操作返回。 66 | 67 | 中序遍历:先左后跟再右,先中序遍历根结点的左子树,然后访问根结点,最后中序遍历右子树。若树为空,则空操作返回。 68 | 69 | 后序遍历:先左后右再根,从左到右先叶子后结点的方式遍历访问左右子树,最后访问根结点。若树为空,则空操作返回。 70 | 71 | 层序遍历:从树的第一层,也就是根结点开始访问,从上而下逐层遍历,在同一层中,按从左到右的顺序对结点逐个访问。若树为空,则空操作返回。 72 | 73 | * 已知前序遍历序列和中序遍历序列,可以唯一确定一棵二叉树。 74 | * 已知后序遍历序列和中序遍历序列,可以唯一确定一棵二叉树。 75 | * 但是已知前序和后序遍历,是不能确定一棵二叉树的。 76 | 77 | ## 线索二叉树 78 | 79 | 在一个结点上有指向前驱和后继的指针,这种指针称为`线索`,加上线索的二叉链表称为`线索链表`,相应的二叉树就称为`线索二叉树(Thread Binary Tree)`。 80 | 81 | 线索二叉树等于是把一棵二叉树转变成了双向链表,这样对我们插入删除结点,查找某个结点都带来了方便。所以我们对二叉树以某种次序遍历使其变为线索二叉树的过程称为`线索化`。 82 | 83 | 线索化的过程就是在遍历的过程中修改空指针的过程。 84 | 85 | 如果所用的二叉树需经常遍历或查找结点时需要某种遍历序列中的前驱和后继,那么采用线索二叉链表的存储结构就是非常不错的选择。 86 | 87 | ## 树,森林与二叉树的转换 88 | 89 | ## 哈夫曼树 90 | 91 | [维基百科](https://zh.wikipedia.org/wiki/霍夫曼编码) 92 | 93 | `哈夫曼树`也称之为`最优二叉树`。与之对应的算法就是`哈夫曼编码`。 94 | 95 | ## 平衡二叉搜索树 96 | 97 | [维基百科](https://zh.wikipedia.org/wiki/平衡二元搜尋樹) 98 | 99 | * AVL树 100 | * 红黑树 101 | * Treap(树堆) 102 | * 节点大小平衡树 103 | 104 | ## 红黑树 105 | 106 | [维基百科](https://zh.wikipedia.org/wiki/红黑树) 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /design_pattern/_sidebar.md: -------------------------------------------------------------------------------- 1 | - 设计模式 2 | - [简介](design_pattern/intro.md) 3 | - [模式类型](design_pattern/type.md) 4 | - [六大原则](design_pattern/principle.md) 5 | - [单例模式](design_pattern/singleton.md) 6 | - [工厂模式](design_pattern/factory.md) 7 | - [抽象工厂模式](design_pattern/abstract_factory.md) 8 | - [建造者模式](design_pattern/builder.md) 9 | - [原型模式](design_pattern/prototype.md) 10 | - [适配器模式](design_pattern/adapter.md) 11 | - [桥接模式](design_pattern/bridge.md) 12 | - [过滤器模式](design_pattern/filter.md) 13 | - [组合模式](design_pattern/composite.md) 14 | - [装饰器模式](design_pattern/decorator.md) 15 | - [外观模式](design_pattern/facade.md) 16 | - [享元模式](design_pattern/flyweight.md) 17 | - [代理模式](design_pattern/proxy.md) 18 | - [责任链模式](design_pattern/chain_of_responsibility.md) 19 | - [命令模式](design_pattern/command.md) 20 | - [解释器模式](design_pattern/interpreter.md) 21 | - [迭代器模式](design_pattern/iterator.md) 22 | - [中介者模式](design_pattern/mediator.md) 23 | - [备忘录模式](design_pattern/memento.md) 24 | - [观察者模式](design_pattern/observer.md) 25 | - [状态模式](design_pattern/state.md) 26 | - [空对象模式](design_pattern/null_object.md) 27 | - [策略模式](design_pattern/strategy.md) 28 | - [模板模式](design_pattern/template.md) 29 | - [访问者模式](design_pattern/visitor.md) 30 | - [参考](design_pattern/reference.md) -------------------------------------------------------------------------------- /design_pattern/abstract_factory.md: -------------------------------------------------------------------------------- 1 | # 抽象工厂模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/抽象工厂) 4 | 5 | 抽象工厂模式是工厂模式的扩展,是围绕一个超级工厂创建其他工厂。 6 | -------------------------------------------------------------------------------- /design_pattern/adapter.md: -------------------------------------------------------------------------------- 1 | # 适配器模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/适配器模式) 4 | 5 | Android中Recycler.Adapter有点类似。 -------------------------------------------------------------------------------- /design_pattern/bridge.md: -------------------------------------------------------------------------------- 1 | # 桥接模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/橋接模式) 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/builder.md: -------------------------------------------------------------------------------- 1 | # 建造者模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/生成器模式) 4 | 5 | 也叫`生成器模式`,是一种对象构建模式。它可以将复杂对象的建造过程抽象出来(抽象类别),使这个抽象过程的不同实现方法可以构造出不同表现(属性)的对象。 6 | 7 | 和Android里面AlertDialog.Builder方式创建弹窗类似。 -------------------------------------------------------------------------------- /design_pattern/chain_of_responsibility.md: -------------------------------------------------------------------------------- 1 | # 责任链模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/责任链模式) 4 | 5 | Android中View的事件分发类似,父View传达触摸事件给子View,看子View是否消费这个事件。 -------------------------------------------------------------------------------- /design_pattern/command.md: -------------------------------------------------------------------------------- 1 | # 命令模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/命令模式) -------------------------------------------------------------------------------- /design_pattern/composite.md: -------------------------------------------------------------------------------- 1 | # 组合模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/组合模式) 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/decorator.md: -------------------------------------------------------------------------------- 1 | # 装饰器模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/修饰模式) 4 | 5 | 又名`修饰模式`,是面向对象程式领域中,一种动态地往一个类别中添加新的行为的设计模式。 6 | 7 | 就功能而言,修饰模式相比生成子类别更为灵活,这样可以给某个对象而不是整个类别添加一些功能。 8 | 9 | -------------------------------------------------------------------------------- /design_pattern/facade.md: -------------------------------------------------------------------------------- 1 | # 外观模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/外觀模式) 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/factory.md: -------------------------------------------------------------------------------- 1 | # 工厂模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/工厂方法) 4 | 5 | Android中BitmapFactory类就是Bitmap的工厂模式应用,它提供了不同的方法来创建Bitmap。 6 | -------------------------------------------------------------------------------- /design_pattern/filter.md: -------------------------------------------------------------------------------- 1 | # 过滤器模式 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/flyweight.md: -------------------------------------------------------------------------------- 1 | # 享元模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/享元模式) 4 | 5 | 享元模式主要用于减少创建对象的数量,以减少内存占用和提高性能。 6 | 7 | 这种类型的设计模式属于结构型模式,它提供了减少对象数量从而改善应用所需的对象结构的方式。 8 | 9 | 有点类似Android中Looper的Messager,Messager.obtain()方法会重用之前已经创建过但是没被回收的Message对象。 -------------------------------------------------------------------------------- /design_pattern/interpreter.md: -------------------------------------------------------------------------------- 1 | # 解释器模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/解释器模式) 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/intro.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/设计模式_(计算机)) 4 | 5 | 设计模式(Design pattern)代表了最佳的实践,通常被有经验的面向对象的软件开发人员所采用。 6 | 7 | 软件开发人员在软件开发过程中面临的一般问题的解决方案。 8 | 9 | 这些解决方案是众多软件开发人员经过相当长的一段时间的试验和错误总结出来的。 10 | 11 | 在 1994 年,由 Erich Gamma、Richard Helm、Ralph Johnson 和 John Vlissides 四人合著出版了一本名为 Design Patterns - Elements of Reusable Object-Oriented Software(中文译名:设计模式 - 可复用的面向对象软件元素) 的书,该书首次提到了软件开发中设计模式的概念。 12 | 13 | 四位作者合称 GOF(四人帮,全拼 Gang of Four),他们所提出的设计模式主要是基于以下的面向对象设计原则。 14 | 15 | * 对接口编程而不是对实现编程。 16 | * 优先使用对象组合而不是继承。 -------------------------------------------------------------------------------- /design_pattern/iterator.md: -------------------------------------------------------------------------------- 1 | # 迭代器模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/迭代器模式) 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/mediator.md: -------------------------------------------------------------------------------- 1 | # 中介者模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/中介者模式) 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/memento.md: -------------------------------------------------------------------------------- 1 | # 备忘录模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/备忘录模式) 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/null_object.md: -------------------------------------------------------------------------------- 1 | ## 空对象模式 2 | 3 | -------------------------------------------------------------------------------- /design_pattern/observer.md: -------------------------------------------------------------------------------- 1 | ## 观察者模式 2 | 3 | -------------------------------------------------------------------------------- /design_pattern/principle.md: -------------------------------------------------------------------------------- 1 | # 设计模式的六大原则 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/SOLID_(面向对象设计)) 4 | 5 | * 开闭原则(Open Close Principle) 6 | * 里氏替换原则(Liskov Substitution Principle) 7 | * 依赖倒置原则(Dependence Inversion Principle) 8 | * 接口隔离原则(Interface Segregation Principle) 9 | * 迪米特法则,又称最少知道原则(Demeter Principle) 10 | * 合成复用原则(Composite Reuse Principle) 11 | 12 | ## 开闭原则 13 | 14 | 对扩展开放,对修改关闭 15 | 16 | 尽量使用接口和抽象类,而不是去修改原有代码 17 | 18 | ## 里氏替换原则 19 | 20 | 里氏代换原则中说,任何基类可以出现的地方,子类一定可以出现 21 | 22 | 只有当派生类可以替换掉基类,且软件单位的功能不受到影响时,基类才能真正被复用,而派生类也能够在基类的基础上增加新的行为 23 | 24 | ## 依赖倒置原则 25 | 26 | 依赖抽象而不依赖具体 27 | 28 | ## 接口隔离原则 29 | 30 | 使用多个隔离的接口,比使用单个接口要好 31 | 32 | 降低类之间的耦合度 33 | 34 | ## 迪米特法则 35 | 36 | 一个实体应当尽量少地与其他实体之间发生相互作用,使得系统功能模块相对独立 37 | 38 | ## 合成复用原则 39 | 40 | 尽量使用合成/聚合的方式,而不是使用继承 -------------------------------------------------------------------------------- /design_pattern/prototype.md: -------------------------------------------------------------------------------- 1 | # 原型模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/原型模式) 4 | 5 | 这种模式是实现了一个原型接口,该接口用于创建当前对象的克隆。 6 | 7 | 例如JAVA中的Object的clone()方法。JS中的原型链感觉也有点类似。 -------------------------------------------------------------------------------- /design_pattern/proxy.md: -------------------------------------------------------------------------------- 1 | # 代理模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/代理模式) 4 | 5 | -------------------------------------------------------------------------------- /design_pattern/reference.md: -------------------------------------------------------------------------------- 1 | ## 参考 2 | 3 | * [菜鸟教程](https://www.runoob.com/design-pattern/design-pattern-intro.html) 4 | * 《大话设计模式》 5 | * 《Head First 设计模式》 6 | * 《设计模式之禅-第二版》 -------------------------------------------------------------------------------- /design_pattern/singleton.md: -------------------------------------------------------------------------------- 1 | # 单例模式 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/单例模式) 4 | 5 | 单例类只能有一个实例 6 | 7 | 单例类必须自己创建自己的唯一实例 8 | 9 | 单例类必须给所有其他对象提供这一实例 10 | 11 | * 懒汉式-线程不安全 12 | * 懒汉式-线程安全 13 | * 饿汉式 14 | * 双重校验锁(double checked locking) 15 | * 静态内部类 16 | * 枚举 17 | 18 | ## 懒汉式-线程不安全 19 | 20 | 没有`synchronized`,也就是没有加锁,严格来说不算单例模式,因为在多线程下还是会创建多个实例。 21 | 22 | ```java 23 | public class Singleton { 24 | 25 | private static Singleton instance; 26 | 27 | private Singleton (){} 28 | 29 | public static Singleton getInstance() { 30 | if (instance == null) { 31 | instance = new Singleton(); 32 | } 33 | return instance; 34 | } 35 | } 36 | ``` 37 | 38 | ## 懒汉式-线程安全 39 | 40 | 这种方式虽然虽然加了锁,但是效率很低。 41 | 42 | ```java 43 | public class Singleton { 44 | 45 | private static Singleton instance; 46 | 47 | private Singleton (){} 48 | 49 | public static synchronized Singleton getInstance() { 50 | if (instance == null) { 51 | instance = new Singleton(); 52 | } 53 | return instance; 54 | } 55 | } 56 | ``` 57 | 58 | ## 饿汉式 59 | 60 | 这种方式没有懒加载,容易浪费内存,比如该类有个其他静态方法被调用,一样也会创建该类的实例。 61 | 62 | 但是因为没有加锁,相对于来说效率也会高点。 63 | 64 | ```java 65 | public class Singleton { 66 | 67 | private static Singleton instance = new Singleton(); 68 | 69 | private Singleton (){} 70 | 71 | public static Singleton getInstance() { 72 | return instance; 73 | } 74 | } 75 | ``` 76 | 77 | ## 双重校验锁 78 | 79 | 这种方式采用双锁机制,安全且在多线程情况下能保持高性能。 80 | 81 | ```java 82 | public class Singleton { 83 | 84 | private volatile static Singleton singleton; 85 | 86 | private Singleton (){} 87 | 88 | public static Singleton getSingleton() { 89 | if (singleton == null) { 90 | synchronized (Singleton.class) { 91 | if (singleton == null) { 92 | singleton = new Singleton(); 93 | } 94 | } 95 | } 96 | return singleton; 97 | } 98 | } 99 | ``` 100 | 101 | ## 静态内部类 102 | 103 | 这种方式能达到双检锁方式一样的功效,但实现更简单。 104 | 105 | 对静态域使用延迟初始化,应使用这种方式而不是双检锁方式。这种方式只适用于静态域的情况,双检锁方式可在实例域需要延迟初始化时使用。 106 | 107 | 这种方式同样利用了 classloader 机制来保证初始化 instance 时只有一个线程,它跟第 3 种方式不同的是:第 3 种方式只要 Singleton 类被装载了,那么 instance 就会被实例化(没有达到懒加载效果),而这种方式是 Singleton 类被装载了,instance 不一定被初始化。 108 | 109 | ```java 110 | public class Singleton { 111 | 112 | private static class SingletonHolder { 113 | 114 | private static final Singleton INSTANCE = new Singleton(); 115 | 116 | } 117 | 118 | private Singleton (){} 119 | 120 | public static final Singleton getInstance() { 121 | return SingletonHolder.INSTANCE; 122 | } 123 | } 124 | ``` 125 | 126 | ## 枚举 127 | 128 | 这种方式是 Effective Java 作者 Josh Bloch 提倡的方式,它不仅能避免多线程同步问题,而且还自动支持序列化机制,防止反序列化重新创建新的对象,绝对防止多次实例化。 129 | 130 | 不过,由于 JDK1.5 之后才加入 enum 特性,好像大多数人都不喜欢这么用。 131 | 132 | ```java 133 | public enum Singleton { 134 | INSTANCE; 135 | public void whateverMethod() { 136 | } 137 | } 138 | ``` 139 | 140 | ## 题外话 141 | 142 | Kotlin实现单例模式,直接用`object`关键字就行了,是真的香。 143 | 144 | -------------------------------------------------------------------------------- /design_pattern/state.md: -------------------------------------------------------------------------------- 1 | ## 状态模式 2 | 3 | -------------------------------------------------------------------------------- /design_pattern/strategy.md: -------------------------------------------------------------------------------- 1 | ## 策略模式 2 | 3 | -------------------------------------------------------------------------------- /design_pattern/template.md: -------------------------------------------------------------------------------- 1 | ## 模板模式 2 | 3 | -------------------------------------------------------------------------------- /design_pattern/type.md: -------------------------------------------------------------------------------- 1 | # 设计模式的类型 2 | 3 | 创建型模式:这些设计模式提供了一种在创建对象的同时隐藏创建逻辑的方式,而不是使用 new 运算符直接实例化对象。这使得程序在判断针对某个给定实例需要创建哪些对象时更加灵活。 4 | 5 | 结构型模式:这些设计模式关注类和对象的组合。继承的概念被用来组合接口和定义组合对象获得新功能的方式。 6 | 7 | 行为型模式:这些设计模式特别关注对象之间的通信。 8 | 9 | * 创建型模式(Creational Patterns) 10 | * 工厂模式(Factory Pattern) 11 | * 抽象工厂模式(Abstract Factory Pattern) 12 | * 单例模式(Singleton Pattern) 13 | * 建造者模式(Builder Pattern) 14 | * 原型模式(Prototype Pattern) 15 | 16 | * 结构型模式(Structural Patterns) 17 | * 适配器模式(Adapter Pattern) 18 | * 桥接模式(Bridge Pattern) 19 | * 过滤器模式(Filter、Criteria Pattern) 20 | * 组合模式(Composite Pattern) 21 | * 装饰器模式(Decorator Pattern) 22 | * 外观模式(Facade Pattern) 23 | * 享元模式(Flyweight Pattern) 24 | * 代理模式(Proxy Pattern) 25 | 26 | * 行为型模式(Behavioral Patterns) 27 | * 责任链模式(Chain of Responsibility Pattern) 28 | * 命令模式(Command Pattern) 29 | * 解释器模式(Interpreter Pattern) 30 | * 迭代器模式(Iterator Pattern) 31 | * 中介者模式(Mediator Pattern) 32 | * 备忘录模式(Memento Pattern) 33 | * 观察者模式(Observer Pattern) 34 | * 状态模式(State Pattern) 35 | * 空对象模式(Null Object Pattern) 36 | * 策略模式(Strategy Pattern) 37 | * 模板模式(Template Pattern) 38 | * 访问者模式(Visitor Pattern) -------------------------------------------------------------------------------- /design_pattern/visitor.md: -------------------------------------------------------------------------------- 1 | ## 访问者模式 2 | 3 | -------------------------------------------------------------------------------- /english/imgs/img_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/english/imgs/img_1.jpg -------------------------------------------------------------------------------- /english/learn.md: -------------------------------------------------------------------------------- 1 | # 语法学习笔记 2 | 3 | ## 英语的5种基本句式 4 | 5 | `系动词`就是起联系作用的动词 6 | 7 | `表语` 通常是描述主语的性质,特点,位置的词 8 | 9 | `宾语` 是动作执行的对象,`间宾`通常是人,`直宾`通常指物,`宾补`是补充说明宾语的词或句子 10 | 11 | `谓语` 主语执行的动作叫谓语,也叫指`谓语动词` 12 | 13 | * S V = 主+谓 14 | * S V P = 主+系+表 15 | * S V O = 主+谓+宾 16 | * S V o O = 主+谓+间宾+直宾 17 | * S V O C = 主+谓+宾+宾补 18 | 19 | ### 主语(Subject)+谓语(Verb) 20 | 21 | The universe remains 宇宙长存 22 | 23 | ### S(主语)+ V(系动词)+ P(表语) 24 | 25 | The food is delicious 这个食物很好吃 26 | 27 | ### Subject(主语)+Verb(谓语)+Object(宾语) 28 | 29 | He took his bag and left 他拿着书包离开了 30 | 31 | ### S(主语)+V(谓语)+l.o(间接宾语)+D.o(直接宾语) 32 | 33 | Her father bought her a dictionary 她爸爸给她买了一本词典 34 | 35 | ### S(主语)+V(谓语)+ O(宾语)+C(补语) 36 | 37 | We made him our monitor 38 | 39 | ## Be动词 40 | 41 | ### be动词的形式 42 | 43 | `be`, `is` ,`am` ,`are`, `was`, `were`, `being`, `been` 44 | 45 | * be-原型 46 | * Is,am,are -- be动词的现在时时态 47 | * was,were -- 过去时时态 48 | * being -- 现在分词 49 | * been -- 过去分词 50 | 51 | ### be动词的用法 52 | 53 | 后面接名词,形容词,地点副词或短语作补足语。 54 | 55 | * The man is a teacher 56 | 57 | 关键:`be动词就是起联系的作用` 58 | 59 | 60 | ### be动词的否定 61 | 62 | 在`am`,`is`,`are`,`was`,`were`后面加`not`,缩略式`am not`,` isn't`, `aren't`, `wasn't`, `weren't` 63 | 64 | * The man isn't back 65 | * I am not back 66 | * They aren't back 67 | * He wasn't back 68 | * They weren't back 69 | 70 | ### 使用be动词提问和回答 71 | 72 | * Is he a teacher? 73 | * Yes,he is/No,he isn't 74 | * Are you a teacher? 75 | * Yes,I am/No,I am not 76 | * Were they teachers? 77 | * Yes,they were/No,they weren't 78 | 79 | ## 代词 80 | 81 | 代词就是代替人或者事物的名词。 82 | 83 | ### 主格和宾格 84 | 85 | 主格代词:`I`,`he`,`she`,`it`,`you`,`we`,`they` 86 | 87 | * I am a teacher 88 | * He is a teacher 89 | 90 | 宾格代词:`me`,`him`,`her`,`it`,`you`,`us`,`them` 91 | 92 | * He likes me 93 | * We like her 94 | * I like him 95 | 96 | ### 物主代词 97 | 98 | 物主就是物的主人,代词就是代替名词,代替事物,代替人的名词叫做代词。 99 | 100 | #### 形容词性物主代词 101 | 102 | 单数形式:`my`,`your`,`his/her/its`,`one's` 103 | 104 | one's=某人的 105 | 106 | 复数形式:`our`,`your`,`their` 107 | 108 | their=他们的 109 | 110 | * This is my book 111 | * We love our montherland 112 | 113 | #### 名词性物主代词 114 | 115 | 物的主人要像名词一样去使用 116 | 117 | 单数形式:`mine`,`yours`,`his/hers/its`,`ones` 118 | 119 | 复数形式:`ours`,`yours`,`theirs` 120 | 121 | * The book is ours 122 | * The apple is heres 123 | 124 | ### 总结 125 | 126 | | 主格代词 | 宾格代词 | 形容词性物主代词 | 名词性物主代词 | 127 | | :------: | :------: | :--------------: | :------------: | 128 | | I | me | my | mine | 129 | | He | him | his | his | 130 | | She | her | her | hers | 131 | | It | it | its | its | 132 | | You | you | your | yours | 133 | | We | us | our | ours | 134 | | They | them | their | theirs | 135 | 136 | ### 反身代词 137 | 138 | `myself`,`yourself`,`herself`,`himself`,`itself` 139 | 140 | `yourselves`,`ourselves`,`themselves` 141 | 142 | ## 实意动词 143 | 144 | 具有实在意义的动词 145 | 146 | `come`,`read`,`go`,`watch`,`play`,`fly` 147 | 148 | ## 助动词 149 | 150 | `do`,`does`,`did` 151 | 152 | 否定形式:`don't`,`doesn't`,`didn't` 153 | 154 | ## 疑问词 155 | 156 | `when`,`where`,`who`,`what`,`how` 157 | 158 | * when:什么时候 159 | * here:什么地点 160 | * who:什么人 -------------------------------------------------------------------------------- /git/query.md: -------------------------------------------------------------------------------- 1 | ## 创建 2 | 3 | ### 复制一个已创建的仓库 4 | 5 | ```shell 6 | git clone 仓库链接 7 | ``` 8 | 9 | 仓库链接可以是`https`和`ssh`的 10 | 11 | ### 创建一个新的仓库 12 | 13 | ```shell 14 | git init 15 | ``` 16 | 17 | ## 本地修改 18 | 19 | ### 显示工作路径下全部已修改的文件 20 | 21 | ```shell 22 | git status 23 | ``` 24 | 25 | ### 显示与上次提交版本文件的不同 26 | 27 | ```shell 28 | git diff 29 | ``` 30 | 31 | ### 把当前所有修改添加到下次提交中 32 | 33 | ```shell 34 | git add . 35 | ``` 36 | 37 | ### 指定某个文件的修改添加到下次提交中 38 | 39 | ```shell 40 | git add -p 41 | ``` 42 | 43 | ### 提交本地的所有修改 44 | 45 | ```shell 46 | git commit -a 47 | ``` 48 | 49 | ### 提交之前已标记的变化 50 | 51 | ```shell 52 | git commit 53 | ``` 54 | 55 | ### 修改上次提交 56 | 57 | 请勿修改已发布的提交记录 58 | 59 | ```shell 60 | git commit --amend 61 | ``` 62 | 63 | ## 提交历史 64 | 65 | ### 从最新提交开始显示所有的提交记录 66 | 67 | ```shell 68 | git log 69 | ``` 70 | 71 | ### 显示指定文件的所有修改 72 | 73 | ```shell 74 | git log -p 75 | ``` 76 | 77 | ### 谁,在什么时间,修改了文件的什么内容 78 | 79 | ```shell 80 | git blame 81 | ``` 82 | 83 | ## 分支与标签 84 | 85 | ### 显示所有分支 86 | 87 | ```shell 88 | git branch -av 89 | ``` 90 | 91 | ### 切换当前分支 92 | 93 | ```shell 94 | git checkout 95 | ``` 96 | 97 | ### 创建新分支,基于当前分支 98 | 99 | ```shell 100 | git branch 101 | ``` 102 | 103 | ### 创建新的可追溯分支,基于远程分支 104 | 105 | ```shell 106 | git checkout --track 107 | ``` 108 | 109 | ### 删除本地分支 110 | 111 | ```shell 112 | git branch -d 113 | ``` 114 | 115 | ### 给当前提交打标签 116 | 117 | ```shell 118 | git tag 119 | ``` 120 | 121 | ## 更新与发布 122 | 123 | ### 列出当前配置的远程端 124 | 125 | ```shell 126 | git remote -v 127 | ``` 128 | 129 | ### 显示远程端信息 130 | 131 | ```shell 132 | git remote show 133 | ``` 134 | 135 | ### 添加新的远程端 136 | 137 | ```shell 138 | git remote add 139 | ``` 140 | 141 | ### 下载远程端的所有改动到本地,不自动合并到当前 142 | 143 | ```shell 144 | git fetch 145 | ``` 146 | 147 | ### 下载远程端的所有改动到本地,自动合并到当前 148 | 149 | ```shell 150 | git pull 151 | ``` 152 | 153 | ### 将本地版本发布到远程端 154 | 155 | ```shell 156 | git push 157 | ``` 158 | 159 | ### 删除远程端分支 160 | 161 | ```shell 162 | git branch -dr 163 | ``` 164 | 165 | ### 发布标签 166 | 167 | ```shell 168 | git push --tags 169 | ``` 170 | 171 | ## 合并与重置 172 | 173 | ### 将分支合并到当前 174 | 175 | ```shell 176 | git merge 177 | ``` 178 | 179 | ### 将当前版本重置到分支中 180 | 181 | 请勿重置已发布的提交 182 | 183 | ```shell 184 | git rebase 185 | ``` 186 | 187 | ### 退出重置 188 | 189 | ```shell 190 | git rebase --abort 191 | ``` 192 | 193 | ### 解决冲突后继续重置 194 | 195 | ```shell 196 | git rebase --continue 197 | ``` 198 | 199 | ### 使用配置好的合并工具去解决冲突 200 | 201 | ```shell 202 | git mergetool 203 | ``` 204 | 205 | ### 在编辑器中手动解决冲突后,标记文件为已解决冲突 206 | 207 | ```shell 208 | git add 209 | git rm 210 | ``` 211 | 212 | ## 撤销 213 | 214 | ### 放弃工作目录下的所有修改 215 | 216 | ```shell 217 | git reset --hard HEAD 218 | ``` 219 | 220 | ### 放弃某个文件的所有本地修改 221 | 222 | ```shell 223 | git checkout HEAD 224 | ``` 225 | 226 | ### 重置一个提交 227 | 228 | 通过创建一个截然不同的新提交 229 | 230 | ```shell 231 | git revert 232 | ``` 233 | 234 | ### 将HEAD重置到上一次提交的版本,并抛弃该版本之后的所有修改 235 | 236 | ```shell 237 | git reset --hard 238 | ``` 239 | 240 | ### 将HEAD重置到上一次提交的版本,并将之后修改标记为未添加到缓存区的修改 241 | 242 | ```shell 243 | git reset 244 | ``` 245 | 246 | ### 将HEAD重置到上一次提交的版本,并保留未提交的本地修改 247 | 248 | ```shell 249 | git reset --keep 250 | ``` 251 | -------------------------------------------------------------------------------- /groovy/learn.md: -------------------------------------------------------------------------------- 1 | ## Groovy是什么 2 | 3 | Groovy是一种基于JVM(Java虚拟机)的敏捷开发语言,它结合了Python、Ruby和Smalltalk的许多强大的特性,Groovy 代码能够与 Java 代码很好地结合,也能用于扩展现有代码。由于其运行在 JVM 上的特性,Groovy 可以使用其他 Java 语言编写的库。 4 | 5 | ## HelloWorld 6 | 7 | ```groovy 8 | class HelloWrold{ 9 | static void static main(args) { 10 | println "Hello World" 11 | } 12 | } 13 | ``` 14 | 15 | ## 变量 16 | 17 | Groovy中的变量可以通过两种方式定义 - 使用数据类型的本地语法,或者使用def关键字。 18 | 19 | ```groovy 20 | def a = "hello" 21 | def b = 1 22 | def c = 'world' 23 | ``` 24 | 25 | ## 运算符 26 | 27 | 常用运算符和Java没什么区别 28 | 29 | ### 范围运算符 30 | 31 | Groovy支持范围的概念,并在`..`符号的帮助下提供范围运算符的符号。 32 | 33 | ```groovy 34 | def rang = 0..5 35 | ``` 36 | 37 | ## 循环 38 | 39 | `while`,`for`常规循环和Java类似 40 | 41 | ### for-in 42 | 43 | ```groovy 44 | for(int i in 1..5) { 45 | println(i); 46 | } 47 | ``` 48 | 49 | ## 逻辑条件语句 50 | 51 | `if-else`,`switch`和Java类似 52 | 53 | ## 方法 54 | 55 | Groovy的方法使用`def`关键字定义,定义形参时不必声明类型。 56 | 57 | 也可以给方法添加修饰符`public`,`private`,`protected`,默认为`public` 58 | 59 | ```groovy 60 | def method(){ 61 | return "hello world"; 62 | } 63 | ``` 64 | 65 | ### 默认参数 66 | 67 | 如果使用非默认和默认参数,则必须注意,默认参数应在参数列表的末尾定义。 68 | 69 | ```groovy 70 | def method(arg,arg2 = 1,arg3 = "hello"){ 71 | 72 | } 73 | ``` 74 | 75 | ## 集合-List 76 | 77 | ```groovy 78 | def list = [1,2,3,4]; 79 | println(list); 80 | 81 | list.add(12); 82 | ``` 83 | 84 | ## 映射-Map 85 | 86 | ## 闭包 87 | 88 | 89 | 90 | ## 参考文献 91 | 92 | * https://www.w3cschool.cn/groovy/ 93 | * https://www.ibm.com/developerworks/cn/education/java/j-groovy/j-groovy.html -------------------------------------------------------------------------------- /html/_sidebar.md: -------------------------------------------------------------------------------- 1 | - HTML 2 | - [HTML](html/learn_html.md) 3 | - [HTML5](html/learn_html5.md) -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 学习笔记 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /index.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /learn_list.md: -------------------------------------------------------------------------------- 1 | # 学习记录 2 | 3 | 记录自己看过的书籍或视频,听过的博客,以及一切有趣的东西。 4 | 5 | ## 2023元年 6 | 7 | ### 二月 8 | 9 | * [《Web前端开发精品课 HTML CSS JavaScript》]() - 莫振杰 10 | * [《Android应用开发揭秘》]() - 杨丰盛 11 | * [《Web前端开发精品课 HTML与CSS进阶》]() - 莫振杰 12 | * [《从0到1:HTML5+CSS3修炼之道》]() - 莫振杰 13 | * [《Android应用安全防护和逆向分析]() - 姜维 14 | * [《技巧:如何用一年时间获得十年经验》]() - 郝培强 15 | * [《赖世雄零起点英语1(入门篇)》]() - 赖世雄 16 | * [《赖世雄的英语学习法》]() - 赖世雄 17 | * [《数据结构(C语言版)》]() - 邓文华 18 | * [《Jetpack Compose:Android全新UI编程》]() - 朱江 19 | 20 | ###  三月 21 | 22 | * [《零基础学好英语语法》](https://weread.qq.com/web/bookDetail/732328b0718995a47324961) - 邱律苍 23 | - 要是能早点看到这本书,我的英语应该会更好一点。 24 | * [关于告别与死亡:沉重过后,感受当下](https://www.xiaoyuzhoufm.com/episode/63d66c596bcfd94102d0db5b?s=eyJ1IjoiNjM4OWJmMzhlZGNlNjcxMDRhY2I4ODI2In0%3D) - MacTalk 25 | - 死亡是中国人很不愿谈及的一个话题,但是又是一个避免不了的话题,活在当下,过好每一天,把每一天都当做生命的最后一天那么过,做有意义的事,做有兴趣的事。 26 | * [《黑客与画家》](https://weread.qq.com/web/bookDetail/5b9328f05dd9fb5b922d1eb)- 保罗·格雷厄姆/阮一峰 译 27 | * [如何不被ChatGPT卷掉](bilibili.com/video/BV1Lo4y1q7AP) 28 | * 能把工具用好的人大概率不会被卷掉,就好像互联网让很多人失业了,但是同样也创造了很多就业机会,把ChatGPT当做一个博识多才得老师就好了。 29 | * [“创业大学”YCombinator的故事](https://www.bilibili.com/video/BV15T411k75c) 30 | - YC的故事,里面都是些老熟人了,《黑客与画家》的作者保罗,`互联网之子`的主人公,还有奥特曼 31 | 32 | -------------------------------------------------------------------------------- /libs/docsify-copy-code.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * docsify-copy-code 3 | * v2.1.1 4 | * https://github.com/jperasmus/docsify-copy-code 5 | * (c) 2017-2020 JP Erasmus 6 | * MIT license 7 | */ 8 | !function(){"use strict";function s(o){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o})(o)}!function(o,e){void 0===e&&(e={});var t=e.insertAt;if(o&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],c=document.createElement("style");c.type="text/css","top"===t&&n.firstChild?n.insertBefore(c,n.firstChild):n.appendChild(c),c.styleSheet?c.styleSheet.cssText=o:c.appendChild(document.createTextNode(o))}}(".docsify-copy-code-button,.docsify-copy-code-button span{cursor:pointer;transition:all .25s ease}.docsify-copy-code-button{position:absolute;z-index:1;top:0;right:0;overflow:visible;padding:.65em .8em;border:0;border-radius:0;outline:0;font-size:1em;background:grey;background:var(--theme-color,grey);color:#fff;opacity:0}.docsify-copy-code-button span{border-radius:3px;background:inherit;pointer-events:none}.docsify-copy-code-button .error,.docsify-copy-code-button .success{position:absolute;z-index:-100;top:50%;right:0;padding:.5em .65em;font-size:.825em;opacity:0;-webkit-transform:translateY(-50%);transform:translateY(-50%)}.docsify-copy-code-button.error .error,.docsify-copy-code-button.success .success{right:100%;opacity:1;-webkit-transform:translate(-115%,-50%);transform:translate(-115%,-50%)}.docsify-copy-code-button:focus,pre:hover .docsify-copy-code-button{opacity:1}"),document.querySelector('link[href*="docsify-copy-code"]')&&console.warn("[Deprecation] Link to external docsify-copy-code stylesheet is no longer necessary."),window.DocsifyCopyCodePlugin={init:function(){return function(o,e){o.ready(function(){console.warn("[Deprecation] Manually initializing docsify-copy-code using window.DocsifyCopyCodePlugin.init() is no longer necessary.")})}}},window.$docsify=window.$docsify||{},window.$docsify.plugins=[function(o,r){o.doneEach(function(){var o=Array.apply(null,document.querySelectorAll("pre[data-lang]")),c={buttonText:"Copy to clipboard",errorText:"Error",successText:"Copied"};r.config.copyCode&&Object.keys(c).forEach(function(t){var n=r.config.copyCode[t];"string"==typeof n?c[t]=n:"object"===s(n)&&Object.keys(n).some(function(o){var e=-1',''.concat(c.buttonText,""),''.concat(c.errorText,""),''.concat(c.successText,""),""].join("");o.forEach(function(o){o.insertAdjacentHTML("beforeend",e)})}),o.mounted(function(){document.querySelector(".content").addEventListener("click",function(o){if(o.target.classList.contains("docsify-copy-code-button")){var e="BUTTON"===o.target.tagName?o.target:o.target.parentNode,t=document.createRange(),n=e.parentNode.querySelector("code"),c=window.getSelection();t.selectNode(n),c.removeAllRanges(),c.addRange(t);try{document.execCommand("copy")&&(e.classList.add("success"),setTimeout(function(){e.classList.remove("success")},1e3))}catch(o){console.error("docsify-copy-code: ".concat(o)),e.classList.add("error"),setTimeout(function(){e.classList.remove("error")},1e3)}"function"==typeof(c=window.getSelection()).removeRange?c.removeRange(t):"function"==typeof c.removeAllRanges&&c.removeAllRanges()}})})}].concat(window.$docsify.plugins||[])}(); 9 | //# sourceMappingURL=docsify-copy-code.min.js.map 10 | -------------------------------------------------------------------------------- /materials/ref.md: -------------------------------------------------------------------------------- 1 | # 收集的学习资料 2 | 3 | 在这样一个网络时代,想学习一门功课或技术真的比以前容易了太多。真心感谢在互联网上分享知识,传播知识的人。 4 | 不管其目的是啥,知识能在人与人之间传播,这本身都应该值得赞扬,希望自己将来也能称为其中的一份子。 5 | 6 | 以下大多数视频都是B站链接,我的推荐是先看书,再看视频,书可以先找PDF快速过一遍,觉得有收获就买本实体书支持一下, 7 | 书只看一遍是没啥用的,多看多想多总结。 8 | 视频可以倍速观看,没懂的可以暂停回放,再听一遍想一遍,这就是视频教程相对于上课听讲的优势。 9 | 下面的链接我大多数是看完了的,都讲得不错,但是有的看得快也忘得快,所以记笔记真的很重要,温故而知新。 10 | 11 | 可以star收藏一下,不定期更新。`收藏不等于学习`,斜眼笑.jpg 12 | 13 | ## 计算机基础 14 | 15 | * [计算机速成课-Crash Course](https://www.bilibili.com/video/BV1EW411u7th) - 强推,无意中在B站刷到的 16 | * [自学计算机科学](https://github.com/izackwu/TeachYourselfCS-CN/blob/master/TeachYourselfCS-CN.md) 17 | * 《计算机是怎么跑起来的 - How Computers Work》 18 | * 《程序是怎么跑起来的 - How Program Works》 19 | 20 | ## 计算机网络 21 | 22 | * 《计算机网络-自顶向下》- 第六版 23 | * [计算机网络-自顶向下-第7版](https://www.bilibili.com/video/BV1JV411t7ow) - 中科大-郑烇老师讲的 24 | * 《计算机网络》 - 谢希仁 25 | 26 | ## 计算机组成原理 27 | 28 | * 《计算机组成原理》 29 | * [计算机组成 - 北京大学](https://www.bilibili.com/video/BV1Xx411Q7Nz) 30 | * [计算机原理 - 国防科技大学](https://www.bilibili.com/video/BV1Jt411G7v9) 31 | * 《计算机组成与设计:硬件/软件接口》 - 第5版 32 | 33 | ## 编译原理 34 | 35 | * 《编译原理》 - 俗称`龙书`,我没看过,还没到那个境界,视频倒是看过一些 36 | * [编译原理 - 哈工大](https://www.bilibili.com/video/BV1zW411t7YE) 37 | 38 | ## 操作系统 39 | 40 | * [操作系统 - 北京大学](https://www.bilibili.com/video/BV1Gx411Q7ro) 41 | * [操作系统 - 清华大学](https://www.bilibili.com/video/BV1wq4y1M7qf) 42 | * 《计算机操作系统教程》 - 张尧学 43 | 44 | ## 数据结构和算法 45 | 46 | * 《大话数据结构》 47 | * 《剑指Offer》 48 | * [高级数据结构和算法 - 北京大学](https://www.bilibili.com/video/BV1Wx411U7Ls) 49 | * [数据结构基础 - 北京大学](https://www.bilibili.com/video/BV1Hx411U7Km) 50 | * [数据结构和算法 - 尚学堂](https://www.bilibili.com/video/BV1bW411o7xJ) 51 | * [算法导论 - MIT](https://www.bilibili.com/video/BV1ex411k7gk) 52 | * 《数据结构C语言版》 - 严蔚敏 53 | 54 | ## C/C++ 55 | 56 | * 《C程序语言设计-K&R》 57 | * 《C Primer Plus》- 第六版 58 | * [翁凯-C语言](https://www.bilibili.com/video/BV19W411B7w1) - 浙江大学-翁凯老师 59 | * 《C++ Primer》 60 | * 《C++ Primer Plus》 61 | * [C++程序设计 - 北京大学](https://www.bilibili.com/video/BV1Hx411U7xL) 62 | * [跟候捷学CPP]() - 收藏的链接过期了,但是大佬B站有号 63 | * [最好的C++教程](https://www.bilibili.com/video/BV1VJ411M7WR) - 这是上传的up主起的名字,但是还是讲得可以,顺便学下英语了 64 | 65 | ## Java 66 | 67 | *《Head First Java》 68 | *《Effective java》 69 | *《Java编程思想》 70 | * [Java入门视频教程](https://www.bilibili.com/video/av48144058) - 尚硅谷 71 | 72 | ## Python 73 | 74 | * [Python官方教程](https://docs.python.org/zh-cn/3.12/tutorial/index.html) 75 | * [8天python从入门到精通](https://www.bilibili.com/video/BV1qW4y1a7fU) - 黑马程序员 76 | 77 | ## Rust 78 | 79 | * [Rust语言圣经](https://course.rs/about-book.html) 80 | * [Rust程序设计语言](https://kaisery.github.io/trpl-zh-cn/) 81 | 82 | ## Go 83 | 84 | * 《Go程序设计语言》 85 | 86 | ## 人工智能 87 | 88 | * [深度学习与计算机视觉 - 斯坦福]() - 李飞飞教授的课 89 | * [机器学习 - 台大](https://www.bilibili.com/video/BV1Ht411g7Ef) - 李宏毅 90 | * [深度学习 - 台大](https://www.bilibili.com/video/BV1JA411c7VT) - 李宏毅 91 | * [深度学习](https://www.bilibili.com/video/BV16r4y1Y7jv) - 吴恩达 92 | 93 | ## 其他 94 | 95 | * [软件工程](https://www.bilibili.com/video/BV1F34y1j7Sn) - Udemy 96 | * [汇编语言 - 第3版](https://www.bilibili.com/video/BV1Wu411B72F) - 王爽 97 | * [Git应用详解](https://www.bilibili.com/video/BV1Bt411b7sk) 98 | * 《代码整洁之道 - Clean Code》 99 | * 《架构整洁之道 - Clean Architecture》 100 | * 《人月神话》 101 | 102 | ## 推荐的up主 103 | 104 | * [bennyhuo不是算命的](https://space.bilibili.com/28615855) - Kotlin GDE,Android大佬(利益相关在大佬群里,放在首位,括号内删掉) 105 | * [扔物线](https://space.bilibili.com/27559447) - Kotlin&Android GDE,Android大佬 106 | * [稚晖君](https://space.bilibili.com/20259914) - 华为天才少年 107 | * [YJango](https://space.bilibili.com/344849038) - 余博士,学习观那些视频讲得真好 108 | * [跟李沐学AI](https://space.bilibili.com/1567748478) - 亚马逊资深首席科学家,AI大佬 109 | * [AliveGameStudio](https://space.bilibili.com/580207) - 独立游戏开发大佬 110 | * [中国大学MOOC](https://space.bilibili.com/243619979) - 也有官网 111 | 112 | ## 一些学习网站 113 | 114 | * [稀土掘金](https://juejin.cn/) 115 | * [LeetCode](https://leetcode.cn) - 用来刷题,现在很多公司都喜欢出算法面试题了 116 | * [菜鸟教程](https://www.runoob.com/) 117 | * [w3school](https://www.w3school.com.cn/) 118 | * [慕课网](https://www.imooc.com/) 119 | * [牛客网](https://www.nowcoder.com/) 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: KeepLearning 2 | theme: 3 | name: readthedocs 4 | sticky_navigation: false 5 | repo_url: https://github.com/simplepeng/KeepLearning/ 6 | 7 | -------------------------------------------------------------------------------- /network/imgs/OSI七层模型.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/network/imgs/OSI七层模型.png -------------------------------------------------------------------------------- /network/imgs/TCP-OS对应关系.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/network/imgs/TCP-OS对应关系.png -------------------------------------------------------------------------------- /network/learn.md: -------------------------------------------------------------------------------- 1 | # 计算机网络学习笔记 2 | 3 | ## 计算机网络分类 4 | 5 | * 广域网(WAN) 6 | * 城域网(MAN) 7 | * 局域网(LAN) 8 | 9 | ## 层次结构设计的基本原则 10 | 11 | * 各层之间是相互独立的 12 | * 每一层要有足够的灵活性 13 | * 各层之间完全解耦 14 | 15 | ## OSI七层模型 16 | 17 | * 应用层:为计算机用户提供接口和服务 18 | * 表示层:数据处理(编码解码,加密解密等) 19 | * 会话层:管理(建立,维护,重连)通信会话 20 | * 传输层:管理端到端的通信连接 21 | * 网络层:数据路由(决定数据在网络的路径) 22 | * 数据链路层:管理相邻节点之间的数据通信 23 | * 物理层:数据通信的光电物理特性 24 | 25 | 注:OSI七层模型应用较少,更多的还是使用TCP/IP模型 26 | 27 | ## TCP/IP四层模型 28 | 29 | * 应用层:OSI中的应用层,表示层,会话层 30 | * 传输层:OSI的传输层 31 | * 网络层:OSI中的网络层 32 | * 网络接口层:OSI中的数据链路层,物理层 33 | 34 | ## 最大传输单元(MTU) 35 | 36 | MTU = **M**aximum **T**ransmission **U**nit,是指一种通信协议的某一层上面能通过的的`最大数据包大小` 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /network/reference.md: -------------------------------------------------------------------------------- 1 | ## 参考 2 | 3 | * 《计算机网络-自顶向下》 -------------------------------------------------------------------------------- /nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/KeepLearning/f172ec826de72d31bbf664347b2a897f54585513/nojekyll -------------------------------------------------------------------------------- /postgraduate.md: -------------------------------------------------------------------------------- 1 | # 计算机考研 2 | 3 | ## 参考 4 | 5 | * https://zhuanlan.zhihu.com/p/109633924 6 | * https://www.sohu.com/a/465528148_100149726 7 | 8 | ## 会考哪些科目 9 | 10 | * 数据结构 11 | * 计算机组成原理 12 | * 操作系统 13 | * 计算机网络 14 | * 数学 15 | * 英语 16 | * 政治 17 | 18 | ## 推荐的学习资料 19 | 20 | * 《数据结构-C语言版》- 严蔚敏 21 | * 《计算机操作系统》- 汤小丹 22 | * 《计算机组成原理》- 唐朔飞 23 | * 《计算机网络-第六版》- 谢希仁 24 | * 《计算机网络-自顶向下》 25 | * 《C语言程序设计-第三版》- 谭浩强 26 | * 《C++程序设计教程-第二版》- 钱能 27 | 28 | ## 专硕和学硕的区别 29 | 30 | * 学硕: 31 | * 学术学位硕士研究生,简称“学硕” 32 | * 以学术研究为导向,偏重理论和研究,以培养从事教学和科研的高层次学术研究型人才为主。 33 | * 学习方式一般为全日制,少量学校有非全日制。 34 | * 专硕: 35 | * 专业学位硕士研究生,简称“专硕”, 36 | * 以职业培养为导向,实践与学术并重,以培养工程师、医师、设计师等高层次应用型人才为主 37 | * 学习方式分为全日制与非全日制。 38 | * 学制年限不同: 39 | * 学硕的学制为两年到两年半。 40 | * 专硕学制为三年。 41 | * 读博方式不同: 42 | * 学硕可以通过自己的导师,按照规定申请直接读博,进行更深入的学习,不用参加全国统考。 43 | * 专硕无法硕博连读或直博,只能在毕业之后参加全国统考,取得博士入学资格。 44 | 45 | ## 统招研究生和在职研究生的区别 46 | 47 | * 报考方式的区别: 48 | * 49 | * 可报考的专业不同: 50 | * 非全:可报考专业都是专硕专业,有些学校可能没有相关专业 51 | * 全日制:几乎可以报考所有专业 52 | * 上课方式不同: 53 | * 在职硕士,学员不会耽误现有的工作,可以一边上班一边学习,有周末班、假期班和网络班3种形式. 54 | * 而统招硕士是周一到周五上课学习,全日制学习的一种形式。 55 | * 考试难度: 56 | * 考试难度相同 57 | * 但是非全社会认可的含金量不如全日制(这就很尴尬了) 58 | * 毕业证书不同: 59 | * 在职研究生会表明`非全日制` 60 | * 学费不同: 61 | * 在职研究生普通高于全日制研究生 62 | * 非全是申请不了奖学金的 63 | 64 | ## 院校 65 | 66 | * [重庆大学](http://graduate.cqu.edu.cn/index.htm) 67 | * [重庆理工大学](http://zs.yjs.cqut.edu.cn/index.htm) 68 | * [重庆邮电大学](https://yjs.cqupt.edu.cn/) 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /python/_sidebar.md: -------------------------------------------------------------------------------- 1 | - Python 2 | - [简介](python/intro.md) 3 | - [注释](python/comment.md) 4 | - [变量](python/variable.md) 5 | - [数据类型](python/data_type.md) 6 | - [字符串](python/string.md) 7 | - [列表](python/list.md) 8 | - [元组](python/tuple.md) 9 | - [字典](python/dict.md) 10 | - [集合](python/set.md) 11 | - [流程控制](python/flow_control.md) 12 | - [函数](python/fun.md) 13 | - [异常处理](python/error.md) 14 | - [类和对象](python/class.md) 15 | - [模块](python/module.md) 16 | - [参考](python/reference.md) -------------------------------------------------------------------------------- /python/class.md: -------------------------------------------------------------------------------- 1 | # 类和对象 2 | 3 | * 使用`class`关键字定义一个类 4 | * `__init__`是类的构造方法 5 | * python支持`多继承`,父类写在类名`()`中,并且先后顺序对子类也有影响 6 | * 类方法也是使用`def`关键字定义,并且第一个参数都是`self` 7 | * `self`表示类的实例对象 8 | * 和其他语音一样,可以在子类中复写父类的方法,也可以使用`super`调用父类的方法 9 | * `__`两个下划线开头的属性和函数,被定义为私有方法,只能在类中调用。 10 | * python也支持`运算符重载` 11 | 12 | ```python 13 | # 类和对象 14 | class MyClass: 15 | """这是一个类""" 16 | a = "hello" 17 | b = 28 18 | 19 | # 类初始化方法,也可以叫构造方法 20 | def __init__(self) -> None: 21 | print("init") 22 | 23 | def hello(self): 24 | print(self.a) 25 | print(self.b) 26 | 27 | object = MyClass() 28 | object.hello() 29 | 30 | 31 | class MyClass2: 32 | """这是一个类""" 33 | a = "hello" 34 | b = 28 35 | 36 | # 传递构造参数 37 | def __init__(self, name) -> None: 38 | print("init") 39 | print(name) 40 | 41 | def hello(self): 42 | print("MyClass2 hello") 43 | print(self.a) 44 | print(self.b) 45 | 46 | object2 = MyClass2("simple") 47 | object2.hello() 48 | 49 | # 继承,python支持多继承 50 | class MyClass3(MyClass2, MyClass): 51 | _private = 1 52 | 53 | def __init__(self) -> None: 54 | print("MyClass3 init") 55 | 56 | o3 = MyClass3() 57 | o3.hello() 58 | 59 | print(isinstance(o3, MyClass3)) 60 | print(issubclass(MyClass, MyClass3)) 61 | print(issubclass(MyClass3, MyClass2)) 62 | 63 | class MyClass4: 64 | __a = 1 65 | 66 | def __hello(): 67 | print("MyClass4 __hello") 68 | 69 | o4 = MyClass4() 70 | # 报错 71 | # o4.__a 72 | # o4.__hello() 73 | ``` -------------------------------------------------------------------------------- /python/comment.md: -------------------------------------------------------------------------------- 1 | # 注释 2 | 3 | ```python 4 | # 单行注释 5 | 6 | ''' 7 | 多行注释 8 | ''' 9 | 10 | """ 11 | 多行注释 12 | """ 13 | ``` -------------------------------------------------------------------------------- /python/data_type.md: -------------------------------------------------------------------------------- 1 | # 数据类型 2 | 3 | * int - 整型 4 | * float - 浮点型 5 | * complex - 复数类型 6 | * string - 字符串 7 | * bytes - 字节类型 8 | * bool - 布尔类型 9 | * list - 列表 10 | * tuple - 元组 11 | * dict - 字典 12 | * set - 集合 13 | 14 | ```python 15 | a = 1 16 | print(a) 17 | 18 | b = 3.14 19 | print(b) 20 | 21 | c = "hello" 22 | print(c) 23 | 24 | d = True 25 | print(d) 26 | 27 | # 通过 encode() 方法将字符串转换成 bytes 28 | e = "hello".encode("UTF-8") 29 | print(e) 30 | 31 | #为 bytes() 方法指定字符集 32 | e1 = bytes("hello world",encoding="UTF-8") 33 | print(e1) 34 | ``` -------------------------------------------------------------------------------- /python/dict.md: -------------------------------------------------------------------------------- 1 | # 字典 2 | 3 | * 字典(dict)可以理解为`键值对的集合`,类似Java中的`HashMap` 4 | * 使用花括号`{}`创建字典 5 | * 使用`del`关键字删除字典中某个键值对,对不存在的key会报错 6 | * 使用关键字`in`判断字典中是否存在某个键,`not in`则反之 7 | 8 | ```python 9 | dict1 = {"zs":"张三","ls":"李四"} 10 | print(dict1) 11 | 12 | # 删除 13 | del dict1["zs"] 14 | print(dict1) 15 | 16 | # 报错,不存在这个key 17 | # del dict1["ww"] 18 | 19 | # 新增 20 | dict1["zs"] = "张三" 21 | dict1["ww"] = "王五" 22 | print(dict1) 23 | 24 | # 判断是否存在 25 | print("zs" in dict1) 26 | print("zs" not in dict1) 27 | 28 | # 排序 29 | print(sorted(dict1)) 30 | 31 | # 转列表 32 | print(list(dict1)) 33 | ``` 34 | 35 | `dict()`函数可以直接用`键值对序列`创建字典 36 | 37 | ```python 38 | dict2 = dict([("zs","张三"), ("ls","李四")]) 39 | ``` 40 | 41 | 使用`items函数`可以取出`键值对`用于循环 42 | 43 | ```python 44 | for k,v in dict2.items(): 45 | print(k,v) 46 | ``` -------------------------------------------------------------------------------- /python/error.md: -------------------------------------------------------------------------------- 1 | # 异常处理 2 | 3 | * 异常处理可以使用`try/except/else/finally`语句块 4 | * 可以使用`raise`关键字抛出一个异常 5 | * 可以继承`Exception`类自定义异常 6 | * 使用`with`关键字使用`预定义的清理行为` 7 | 8 | ```python 9 | # 捕获异常 10 | try: 11 | 10 / 1 12 | except ZeroDivisionError: 13 | print("ZeroDivisionError") 14 | else: 15 | print("else") 16 | finally: 17 | print("finally") 18 | 19 | # 抛出异常 20 | def raiseFun(num): 21 | if num > 5: 22 | raise Exception("num 不能大于5") 23 | else: 24 | print("num = ", num) 25 | # raiseFun(6) 26 | 27 | # 自定义异常 28 | class MyException(Exception): 29 | pass 30 | 31 | # 预定义的清理行为 32 | with open("myfile.txt") as f: 33 | for line in f: 34 | print(line, end="") 35 | ``` -------------------------------------------------------------------------------- /python/flow_control.md: -------------------------------------------------------------------------------- 1 | # 流程控制 2 | 3 | ## if 4 | 5 | * `if`用来判断逻辑分支结构 6 | * if表达式不需要括号`()` 7 | * if分支用冒号`:`标记结尾 8 | * `elif`新增一个分支,`else`结束分支 9 | 10 | ```python 11 | age = 3 12 | if age < 4: 13 | print("age < 4") 14 | elif age > 6: 15 | print("age >6") 16 | else: 17 | print("age = 5") 18 | ``` 19 | 20 | ## for 21 | 22 | * `for`用来遍历元素组,也需要`:`标记结尾 23 | * 遍历集合时,同时修改集合内容时,应该使用集合的副本 24 | * `break`出循环,`continue`执行下一次循环 25 | * python的循环语句支持`else`分支 26 | * for循环中,可迭代对象中元素全部循环完毕,执行else子句 27 | * while循环中,条件语句为假时,执行该子句 28 | 29 | ```python 30 | items = ["cat", "dog", "horse"] 31 | for w in items: 32 | print(w) 33 | ``` 34 | 35 | ```python 36 | users = {'Hans': 'active', 'Éléonore': 'inactive', '景太郎': 'active'} 37 | for user, status in users.copy().items(): 38 | if status == 'inactive': 39 | del users[user] 40 | ``` 41 | 42 | ## while 43 | 44 | ```python 45 | age = 1 46 | while age < 10: 47 | age = age + 1 48 | else: 49 | print("age > 10") 50 | ``` 51 | 52 | ## range函数 53 | 54 | `range()`函数生成数字序列,可以直接用来遍历 55 | 56 | ```python 57 | for i in range(5): 58 | print(i) 59 | ``` 60 | 61 | ## pass语句 62 | 63 | pass是空语句,一般用来占位。 64 | 65 | ```python 66 | while True: 67 | pass 68 | 69 | class EmptyClass: 70 | pass 71 | 72 | def fun(): 73 | pass 74 | ``` 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /python/fun.md: -------------------------------------------------------------------------------- 1 | # 函数 2 | 3 | * 使用`def`关键字定义一个函数 4 | * 函数参数放在`()`中,`:`结尾 5 | * 参数可以有`默认值`和`关键字` 6 | * 也可以使用`不定长参数`,加了`*`号的参数会以`元组(tuple)`方式导入 7 | * 加了两个星号`**`的参数会以`字典`方式导入 8 | * 函数第一行语句可以使用文档字符串`""" """`标准函数的用途 9 | * `return`关键字返回函数的返回值,没有返回值函数也会返回`None` 10 | * 使用`lamda`关键字创建`匿名函数` 11 | 12 | ```python 13 | # 定义函数 14 | def hello(): 15 | print("hello") 16 | hello() 17 | 18 | # 文档注释 19 | def doc(): 20 | """这是文档注释""" 21 | return "doc" 22 | doc() 23 | 24 | # 带参数,返回值 25 | def hello2(n): 26 | print(n) 27 | return "world" 28 | print(hello2("hello")) 29 | 30 | # 默认参数 31 | def hello3(name, age = 11, sex = "boy"): 32 | print(name) 33 | print(age) 34 | print(sex) 35 | hello3("simple") 36 | hello3("simple", sex = "girl", age = 30) 37 | 38 | # 不定长参数 39 | def hello4(*args): 40 | print("不定长参数 = ", args) 41 | hello4(1, 2, 3) 42 | # 不定长参数 = (1, 2, 3) 43 | 44 | # 字典参数 45 | def hello5(**dict): 46 | print("字典参数 = ", dict) 47 | hello5(a = 1, b = 2) 48 | # 字典参数 = {'a': 1, 'b': 2} 49 | 50 | ``` 51 | 52 | ## 匿名函数(lambda) 53 | 54 | * 使用`lambda`关键字创建匿名函数 55 | 56 | > lambda 参数们: 表达式 57 | 58 | ```python 59 | sum = lambda a, b: a + b 60 | print("sum = ",sum(1, 2)) 61 | ``` 62 | 63 | ## 函数作为参数 64 | 65 | ```python 66 | def fun1(): 67 | print("fun1 call") 68 | 69 | def fun2(func): 70 | func() 71 | print("fun2 call") 72 | fun2(fun1) 73 | ``` 74 | 75 | ## 装饰器 76 | 77 | * python这个函数装饰器有点类似于Java中的注解 78 | 79 | ```python 80 | def decor_fun(func): 81 | def wrapper(*args, **kw): 82 | print("装饰器函数 -- start") 83 | func() 84 | print("装饰器函数 -- end") 85 | return wrapper 86 | 87 | @decor_fun 88 | def fun(): 89 | print("本体方法调用") 90 | fun() 91 | ``` -------------------------------------------------------------------------------- /python/intro.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | 3 | Python 是一门易于学习、功能强大的编程语言。它提供了高效的高级数据结构,还能简单有效地面向对象编程。 4 | 5 | Python 优雅的语法和动态类型以及解释型语言的本质,使它成为多数平台上写脚本和快速开发应用的理想语言。 6 | 7 | [维基百科](https://zh.wikipedia.org/wiki/Python) 8 | 9 | [官方网站](https://www.python.org/) 10 | 11 | [官方教程](https://docs.python.org/zh-cn/3/tutorial/index.html) 12 | 13 | 14 | ```python 15 | print("hello world") 16 | ``` -------------------------------------------------------------------------------- /python/list.md: -------------------------------------------------------------------------------- 1 | # 列表 2 | 3 | 列表(list)可以将多个元素放在一起,使用方括号`[]`标注 4 | 5 | ```python 6 | list1 = [1,2,3] 7 | ``` 8 | 9 | 列表可以包含不同类型的元素,但一般情况下,元素类型都相同 10 | 11 | ```python 12 | list2 = [1,2,3,"4"] 13 | ``` 14 | 15 | `append()`函数能在列表末尾添加新的元素 16 | 17 | ```python 18 | list1.append(5) 19 | ``` 20 | 21 | `len()`函数也支持列表 22 | 23 | ```python 24 | len = len(list1) 25 | print(len) 26 | ``` 27 | 28 | 列表的常用函数 29 | 30 | ```python 31 | list.remove(x) 32 | list.clear() 33 | list.index() 34 | list.count(x) 35 | list.sort() 36 | list.reverse() 37 | list.copy() 38 | ``` -------------------------------------------------------------------------------- /python/module.md: -------------------------------------------------------------------------------- 1 | # 模块 2 | 3 | * python中一个模块就是`.py`结尾的python文件 4 | * 模块中定义了一系列的的属性和方法 5 | * 使用`import`关键字导入模块 6 | * 使用`as`关键字给导入的模块重命名 7 | * 一个模块只会被导入一次,不管代码中import了多少次 8 | * 使用`from...import`可以导入模块中指定的部分 9 | * 模块也可以使用`包级管理` 10 | 11 | ```python 12 | # 导入模块 13 | import module2 14 | module2.hello() 15 | 16 | # 导入模块-重命名 17 | import module2 as m 18 | m.hello() 19 | 20 | # 导入模块中的某个方法 21 | from module2 import hello 22 | hello() 23 | ``` -------------------------------------------------------------------------------- /python/reference.md: -------------------------------------------------------------------------------- 1 | # 参考 2 | 3 | * [廖雪峰的Python博客](https://www.liaoxuefeng.com/wiki/1016959663602400) 4 | * 《简明Python教程》 5 | * [官方教程](https://docs.python.org/zh-cn/3/tutorial/index.html) 6 | * [菜鸟教程](https://www.runoob.com/python3/python3-tutorial.html) 7 | * [C语言中文网](http://c.biancheng.net/view/2170.html) -------------------------------------------------------------------------------- /python/set.md: -------------------------------------------------------------------------------- 1 | # 集合 2 | 3 | * 集合(set)是一个无序的不重复的元素列表 4 | * 类似Java总的`Set` 5 | * 可以使用`set()`函数和大括号`{}`创建集合 6 | * 创建空集合只能用`set`函数,`{}`用来创建空字典 7 | 8 | ```python 9 | set1 = {"apple", "orange", "pear", "apple"} 10 | print(set1) 11 | 12 | print("apple" in set1) 13 | 14 | set2 = set("apple") 15 | print(set2) 16 | 17 | set1.add("banana") 18 | print(set1) 19 | 20 | set1.remove("banana") 21 | print(set1) 22 | 23 | # 报错,没有这个元素 24 | # set1.remove("cat") 25 | ``` -------------------------------------------------------------------------------- /python/string.md: -------------------------------------------------------------------------------- 1 | # 字符串 2 | 3 | python使用单引号`'`或双引号`"`标记字符 4 | 5 | ```python 6 | str1 = "hello" 7 | str2 = 'world' 8 | 9 | print(str1) 10 | print(str2) 11 | ``` 12 | 13 | 长字符串使用3个双引号`"""`或3个单引号`'''`包围 14 | 15 | ```python 16 | str4 = """ 17 | nihao 18 | hello 19 | world 20 | """ 21 | 22 | print(str4) 23 | ``` 24 | 25 | 在字符串前面加上`r`开头,就变成了原始字符串,原始字符串会忽略字符串中的转移符号`\` 26 | 27 | ```python 28 | str5 = r"\user\simple\peng" 29 | print(str5) 30 | 31 | str6 = r"\'user\simple" 32 | print(str6) 33 | ``` -------------------------------------------------------------------------------- /python/tuple.md: -------------------------------------------------------------------------------- 1 | # 元组 2 | 3 | * 元组(tuple)使用圆括号`()`标注,不是必须的,但是经常是必须的 4 | * 元组和列表很像,但是使用场景不同。元组是不可变的(`inmutable`),列表是可变的(`mutable`) 5 | * 元组一般是包含异质元素类型,列表是同质元素类型 6 | * 元组可使用解包语法 7 | 8 | ```python 9 | tuple1 = (1,2,"3") 10 | print(tuple1) 11 | 12 | # 访问元素 13 | var1 = tuple1[0] 14 | print(var1) 15 | 16 | # 报错,不能修改元素 17 | tuple1[0] = "haha" 18 | print(tuple1) 19 | 20 | # 解包语法 21 | x,y,z = tuple1 22 | print(x) 23 | print(y) 24 | print(z) 25 | ``` -------------------------------------------------------------------------------- /python/variable.md: -------------------------------------------------------------------------------- 1 | # 变量 2 | 3 | * python定义变量不需要关键字 4 | * 变量名开始不能是数字 5 | * 约定`_`开头的变量是私有变量 6 | * 变量名,函数名使用`snake_case`命名法,例如`hello_world`,`add_num()` 7 | 8 | ```python 9 | a = 1 10 | b = 2 11 | c = "hello world" 12 | ``` 13 | 14 | -------------------------------------------------------------------------------- /rust/_sidebar.md: -------------------------------------------------------------------------------- 1 | - Rust 2 | - [简介](rust/intro.md) 3 | - [Cargo](rust/cargo.md) 4 | - [注释](rust/comments.md) 5 | - [变量](rust/varialbles.md) 6 | - [常量](rust/const.md) 7 | - [数据类型](rust/data_types.md) 8 | - [数组](rust/array.md) 9 | - [元组](rust/tuple.md) 10 | - [流程控制](rust/control_flow.md) 11 | - [函数](rust/functions.md) 12 | - [所有权](rust/ownership.md) 13 | - [引用](rust/referencs.md) 14 | - [切片](rust/slice.md) 15 | - [结构体](rust/structs.md) 16 | - [枚举](rust/enum.md) 17 | - [模式匹配](rust/match.md) 18 | - [泛型](rust/generics.md) 19 | - [生命周期](rust/lifetime.md) 20 | - [trait](rust/traits.md) 21 | - [错误处理](rust/error_handling.md) 22 | - [闭包](rust/closure.md) 23 | - [迭代器](rust/iterator.md) 24 | - [智能指针](rust/smart_pointer.md) 25 | - [并发](rust/concurrency.md) 26 | - [宏](rust/macros.md) 27 | - [异步](rust) 28 | - [参考](rust/refers.md) -------------------------------------------------------------------------------- /rust/array.md: -------------------------------------------------------------------------------- 1 | # 数组 2 | 3 | 数组中的每个元素的类型必须相同。 4 | 5 | Rust 中的数组与一些其他语言中的数组不同,Rust中的数组长度是固定的。 6 | 7 | ```rust 8 | let a = [1, 2, 3, 4, 5]; 9 | let b: [i32; 5] = [1, 2, 3, 4, 5]; 10 | 11 | let first = a[0]; 12 | ``` -------------------------------------------------------------------------------- /rust/cargo.md: -------------------------------------------------------------------------------- 1 | # Cargo 2 | 3 | `cargo`是rust的包管理器,安装好rust后cargo也会被自动安装,可以直接在命令行使用cargo命令。 4 | 5 | * 新建项目 6 | ```shell 7 | cargo new project_name 8 | ``` 9 | 10 | * 运行项目 11 | ```shell 12 | cargo run 13 | ``` 14 | 15 | * 先编译再运行 16 | ```shell 17 | cargo build 18 | ./hello_world 19 | ``` 20 | 21 | * 快速检查 22 | ```shell 23 | cargo check 24 | ``` 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /rust/closure.md: -------------------------------------------------------------------------------- 1 | # 闭包 -------------------------------------------------------------------------------- /rust/comments.md: -------------------------------------------------------------------------------- 1 | # 注释 2 | 3 | ```rust 4 | 5 | ///文档注释 6 | /// 7 | /// 8 | fn main(){ 9 | //通用注释 10 | 11 | /** 12 | * 块注释 13 | */ 14 | } 15 | 16 | ``` -------------------------------------------------------------------------------- /rust/concurrency.md: -------------------------------------------------------------------------------- 1 | # 并发 -------------------------------------------------------------------------------- /rust/const.md: -------------------------------------------------------------------------------- 1 | # 常量 2 | 3 | 常量使用`const`关键字声明,且类型必须标注 4 | 5 | 常量不允许使用`mut`,因为常量在编译完成后,就已经确定了值。 6 | 7 | 常量一般使用大写字母。 8 | 9 | ```rust 10 | const MAX = 10; 11 | ``` -------------------------------------------------------------------------------- /rust/control_flow.md: -------------------------------------------------------------------------------- 1 | # 流程控制 2 | 3 | rust 使用`if-else`做条件分支,`loop`,`while`,`for`做循环分支。 4 | 5 | ### if 6 | 7 | ```rust 8 | if a < b { 9 | 10 | } else { 11 | 12 | } 13 | ``` 14 | 15 | rust 的判断表达式不用加`()`括号。 16 | 17 | if 表达式可以返回值,但是不能加`;`分号。 18 | 19 | ```rust 20 | let a = if condition { 5 } else { 6 }; 21 | ``` 22 | 23 | ### loop 24 | 25 | ```rust 26 | loop { 27 | println!("again!"); 28 | } 29 | ``` 30 | 31 | ### while 32 | 33 | ```rust 34 | let mut number = 3; 35 | while number != 0 { 36 | println!("{number}!"); 37 | number -= 1; 38 | } 39 | println!("LIFTOFF!!!"); 40 | ``` 41 | 42 | ### for 43 | 44 | ```rust 45 | for number in (1..4).rev() { 46 | println!("{number}!"); 47 | } 48 | println!("LIFTOFF!!!"); 49 | ``` 50 | -------------------------------------------------------------------------------- /rust/data_types.md: -------------------------------------------------------------------------------- 1 | # 数据类型 2 | 3 | rust是静态类型(statically typed)语言,编译时就必须确定每个值得类型,大致可以分为两类:`标量类型`和`复合类型`。 4 | 5 | * 标量类型 6 | * 整型 7 | * 有符号整数 (i8, i16, i32, i64, i128,isize) 8 | * 无符号整数 (u8, u16, u32, u64, u128,usize) 9 | * 浮点型 10 | * f32:单精度 11 | * f64:双精度 12 | * 布尔(bool)类型:`true`和`fasle` 13 | * 字符(char)类型:表示单个 Unicode 字符,存储为 4 个字节 14 | * 复合类型 15 | * 元组 16 | * 数组 17 | * 其他 18 | * 字符串 19 | * 字符串字面量 20 | * 字符串切片 &str 21 | * 单元类型:即 () ,其唯一的值也是 () 22 | 23 | ### 布尔类型 24 | 25 | ```rust 26 | let a = true; 27 | let b:bool = false; 28 | ``` -------------------------------------------------------------------------------- /rust/enum.md: -------------------------------------------------------------------------------- 1 | # 枚举 2 | 3 | -------------------------------------------------------------------------------- /rust/error_handling.md: -------------------------------------------------------------------------------- 1 | # 错误处理 -------------------------------------------------------------------------------- /rust/functions.md: -------------------------------------------------------------------------------- 1 | # 函数 2 | 3 | * 函数名使用`snake case(蛇形命名法)`,比如`fn add_num() -> {}` 4 | * 每个函数参数都需标注类型 5 | 6 | ```rust 7 | fn add_num(a:i32) -> i32 { 8 | x + 5 9 | } 10 | ``` -------------------------------------------------------------------------------- /rust/generics.md: -------------------------------------------------------------------------------- 1 | # 泛型 2 | -------------------------------------------------------------------------------- /rust/intro.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | 3 | [维基百科](https://zh.wikipedia.org/wiki/Rust) 4 | 5 | [官方网站](https://www.rust-lang.org/) 6 | 7 | ## HelloWorld 8 | 9 | ```rust 10 | fn main() { 11 | println!("Hello, World!"); 12 | } 13 | ``` -------------------------------------------------------------------------------- /rust/iterator.md: -------------------------------------------------------------------------------- 1 | # 迭代器 -------------------------------------------------------------------------------- /rust/lifetime.md: -------------------------------------------------------------------------------- 1 | # 生命周期 -------------------------------------------------------------------------------- /rust/macros.md: -------------------------------------------------------------------------------- 1 | # 宏 -------------------------------------------------------------------------------- /rust/match.md: -------------------------------------------------------------------------------- 1 | # 模式匹配 -------------------------------------------------------------------------------- /rust/ownership.md: -------------------------------------------------------------------------------- 1 | # 所有权 2 | 3 | 所有权(ownership)是rust最与众不同的特性,它让rust无需垃圾回收(gc)机制即可保证内存安全。 4 | 5 | ### 所有权规则 6 | 7 | * rust中每个值都有一个所有者(owner)。 8 | * 值在任一时刻只有一个owner。 9 | * 当所有者(变量)离开作用域,这个值会被释放回收。 10 | 11 | ### 变量作用域 12 | 13 | ```rust 14 | //未进入作用域,s变量无效 15 | { 16 | let s = "hello"; //从此处起,s变量是有效的 17 | //使用s变量 18 | } 19 | //作用域结束,s变量不在有效 20 | ``` -------------------------------------------------------------------------------- /rust/referencs.md: -------------------------------------------------------------------------------- 1 | # 引用 2 | -------------------------------------------------------------------------------- /rust/refers.md: -------------------------------------------------------------------------------- 1 | # 参考 2 | 3 | * [Rust 程序设计语言 简体中文版](https://kaisery.github.io/trpl-zh-cn/) 4 | * [Rust语言圣经(Rust Course)](https://course.rs/about-book.html) -------------------------------------------------------------------------------- /rust/slice.md: -------------------------------------------------------------------------------- 1 | # 切片 2 | 3 | -------------------------------------------------------------------------------- /rust/smart_pointer.md: -------------------------------------------------------------------------------- 1 | # 智能指针 -------------------------------------------------------------------------------- /rust/structs.md: -------------------------------------------------------------------------------- 1 | # 结构体 2 | 3 | -------------------------------------------------------------------------------- /rust/traits.md: -------------------------------------------------------------------------------- 1 | # trait 2 | 3 | trait类似于其他语言中的`接口(interface)`。 -------------------------------------------------------------------------------- /rust/tuple.md: -------------------------------------------------------------------------------- 1 | # 元组 2 | 3 | 元组是一个将多个其他类型的值组合进一个复合类型的主要方式。 4 | 5 | 元组长度固定:一旦声明,其长度不会增大或缩小。 6 | 7 | ```rust 8 | let tup: (i32, f64, u8) = (500, 6.4, 1); 9 | ``` 10 | 11 | 元组解构 12 | 13 | ```rust 14 | let tup = (500, 6.4, 1); 15 | let (x, y, z) = tup; 16 | println!("The value of y is: {y}"); 17 | ``` -------------------------------------------------------------------------------- /rust/varialbles.md: -------------------------------------------------------------------------------- 1 | # 变量 2 | 3 | ```rust 4 | let a = "hello world"; 5 | ``` 6 | rust的变量也有类型推导,当然也可以显示标注变量类型,也是用`:`符号后置标注法。 7 | 8 | ```rust 9 | let a: &str= "hello world"; 10 | ``` 11 | 12 | rust变量默认是不可变的,使用`mut`关键字让变量变为可变的。 13 | 14 | ```rust 15 | let mut a = "hello world"; 16 | ``` 17 | 18 | 可以使用`下划线`开头忽略未使用的变量 19 | 20 | ```rust 21 | let _x = 5; 22 | let y = 6;//未使用变量在编译时会给出警告 23 | ``` 24 | 25 | 变量解构 26 | 27 | ```rust 28 | let (a, mut b): (bool, bool) = (true, false); 29 | ``` 30 | 31 | `变量遮蔽(shadowing)` 32 | 33 | ```rust 34 | let x = 5; 35 | let x = x + 1; 36 | ``` -------------------------------------------------------------------------------- /shell/_sidebar.md: -------------------------------------------------------------------------------- 1 | - Shell 2 | - [简介](shell/intro.md) 3 | - [注释](shell/comment.md) 4 | - [变量](shell/var.md) 5 | - [字符串](shell/string.md) 6 | - [数组](shell/array.md) 7 | - [运算符](shell/operator.md) 8 | - [流程控制](shell/expression.md) 9 | - [函数](shell/func.md) 10 | - [输入输出](shell/io.md) 11 | - [传递参数](shell/arguments.md) 12 | - [文件包含](shell/include_file.md) 13 | - [工具](shell/tools.md) 14 | - [参考](shell/reference.md) -------------------------------------------------------------------------------- /shell/arguments.md: -------------------------------------------------------------------------------- 1 | # 传递参数 2 | 3 | 我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:`$n`或`${n}`。 4 | 5 | `n` 代表一个数字,0为执行的文件名,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 6 | 7 | ```shell 8 | #! /bin/bash 9 | 10 | echo "执行文件名 = $0" 11 | echo "执行文件名 = ${0}" 12 | 13 | echo "第一个参数 = $1" 14 | echo "第一个参数 = ${1}" 15 | ``` 16 | 17 | > ./shell_arg.sh l f 18 | > 19 | > 执行文件名 = ./shell_arg.sh 20 | > 执行文件名 = ./shell_arg.sh 21 | > 第一个参数 = l 22 | > 第一个参数 = l 23 | 24 | -------------------------------------------------------------------------------- /shell/array.md: -------------------------------------------------------------------------------- 1 | # 数组 2 | 3 | * Bash Shell只有一维数组 4 | * 初始化时不需要定义数组大小 5 | * 数组元素的下标由0开始 6 | * 数组中可以同时存在不同类型的元素 7 | 8 | Shell 数组用`括号 ()`来表示,元素用`空格 `符号分割开 9 | 10 | ```shell 11 | 数组名=(值1 ‘值',“值2”) 12 | ``` 13 | 14 | ### 获取数组中的元素 15 | 16 | ```shell 17 | ${array_name[index]} 18 | ``` 19 | 20 | ### 获取数组所有元素 21 | 22 | 使用`@` 或` *` 可以获取数组中的所有元素 23 | 24 | ```shell 25 | ${array_name[@]} 26 | ${array_name[*]} 27 | ``` 28 | 29 | ### 获取数组值的个数 30 | 31 | 获取数组长度的方法与获取字符串长度的方法相同,都是使用`#`运算符 32 | 33 | ```shell 34 | ${#array_name[@]} 35 | ``` 36 | 37 | ### 实例 38 | 39 | ```shell 40 | #!/bin/bash 41 | 42 | arr=(1 2 3 'a' "b") 43 | # 获取数组中的元素 44 | echo ${arr[0]} 45 | echo ${arr[3]} 46 | # 获取数组所有元素 47 | echo ${arr[@]} 48 | echo ${arr[*]} 49 | # 获取数组值的个数 50 | echo ${#arr[@]} 51 | echo ${#arr[*]} 52 | ``` 53 | 54 | > 1 55 | > a 56 | > 1 2 3 a b 57 | > 1 2 3 a b 58 | > 5 59 | > 5 -------------------------------------------------------------------------------- /shell/comment.md: -------------------------------------------------------------------------------- 1 | # 注释 2 | 3 | 以`#`开头的行就是注释,会被解释器忽略。 4 | 5 | sh 里没有多行注释,只能每一行加一个`#`号。 -------------------------------------------------------------------------------- /shell/expression.md: -------------------------------------------------------------------------------- 1 | # 流程控制 2 | 3 | 与其他语言不同,Shell的流程控制块不能为空。 4 | 5 | 比如其他语言可以在`else`代码块中不写逻辑,但是`sh/bash`里不能这么写。 6 | 7 | ## 逻辑控制-if 8 | 9 | ```shell 10 | if 表达式 11 | then 12 | ... 13 | elif 表达式 14 | then 15 | ... 16 | else 17 | ... 18 | fi 19 | ``` 20 | 21 | ```shell 22 | #! /bin/bash 23 | 24 | a=1 25 | b=2 26 | c=1 27 | 28 | if [ $a == $b ] 29 | then 30 | echo "a = b" 31 | elif [ $a = $c ] 32 | then 33 | echo "a == 1" 34 | else 35 | echo "a != b" 36 | fi 37 | 38 | val=`expr $a != $b` 39 | if [ val ] 40 | then 41 | echo "a != b" 42 | else 43 | echo "a == b" 44 | fi 45 | ``` 46 | 47 | > a == 1 48 | > a != b 49 | 50 | ## 循环-for 51 | 52 | ```shell 53 | for 变量 in 集合 54 | do 55 | ... 56 | done 57 | ``` 58 | 59 | ```shell 60 | #! /bin/bash 61 | 62 | for i in 1 2 3 4 63 | do 64 | echo "value == ${i}" 65 | done 66 | ``` 67 | 68 | > value == 1 69 | > value == 2 70 | > value == 3 71 | > value == 4 72 | 73 | ## 循环-while 74 | 75 | ```shell 76 | while 表达式 77 | do 78 | ... 79 | done 80 | ``` 81 | 82 | ## 无线循环 83 | 84 | ```shell 85 | while : 86 | do 87 | command 88 | done 89 | ``` 90 | 91 | 或者 92 | 93 | ```shell 94 | while true 95 | do 96 | command 97 | done 98 | ``` 99 | 100 | ## 循环-until 101 | 102 | until 循环执行一系列命令直至条件为 true 时停止。 103 | 104 | until 循环与 while 循环在处理方式上刚好相反。 105 | 106 | 一般 while 循环优于 until 循环,但在某些时候—也只是极少数情况下,until 循环更加有用。 107 | 108 | ```shell 109 | until 条件表达式 110 | do 111 | ... 112 | done 113 | ``` 114 | 115 | ## 匹配多值-case 116 | 117 | 类似于其他语言的switch-case语句 118 | 119 | ```shell 120 | case 值 in 121 | 模式1) 122 | ... 123 | ;; 124 | 模式2) 125 | ... 126 | ;; 127 | ... 128 | ... 129 | *) 130 | ;; 131 | esac 132 | ``` 133 | 134 | ```shell 135 | #! /bin/bash 136 | 137 | a=5 138 | case $a in 139 | 1) 140 | echo "a == 1" 141 | ;; 142 | 2) 143 | echo "a == 2" 144 | ;; 145 | *) 146 | echo "a不等于以上任何数" 147 | ;; 148 | esac 149 | ``` 150 | 151 | > a不等于以上任何数 152 | 153 | ## 跳出循环-break,continue 154 | 155 | `break`命令直接跳出所有循环 156 | 157 | `continue`命令跳出本次循环,执行下一次循环 158 | 159 | ```shell 160 | for i in 1 2 3 4 161 | do 162 | if [ $i == 1 ] 163 | then 164 | continue 165 | elif [ $i == 3 ] 166 | then 167 | break 168 | fi 169 | echo "i == $i" 170 | done 171 | ``` 172 | 173 | > i == 2 -------------------------------------------------------------------------------- /shell/func.md: -------------------------------------------------------------------------------- 1 | # 函数 2 | 3 | ## 函数定义 4 | 5 | ```shell 6 | [ function ] 函数名 [()] 7 | { 8 | ... 9 | [return int;] 10 | } 11 | ``` 12 | 13 | 上面的`[]`代表可选 14 | 15 | 函数定义必须在函数调用之前、 16 | 17 | ```shell 18 | #! /bin/bash 19 | 20 | function fun1 21 | { 22 | echo "这是函数----fun1" 23 | } 24 | 25 | function fun2() 26 | { 27 | echo "这是函数----fun2" 28 | } 29 | 30 | fun3() 31 | { 32 | echo "这是函数----fun3" 33 | } 34 | 35 | echo "执行函数-开始" 36 | fun1 37 | fun2 38 | fun3 39 | echo "执行函数-结束" 40 | ``` 41 | 42 | ## 函数返回值 43 | 44 | 可以显示加上`return`关键字返回参数,如果不加,将以最后一条命令运行结果,作为返回值。 45 | 46 | `return`的返回值为(0-255)的整数 47 | 48 | 函数返回值在调用该函数后通过 `$? `来获得。 49 | 50 | ```shell 51 | fun_return() 52 | { 53 | echo "函数 fun_return 执行" 54 | return 0 55 | } 56 | 57 | fun_return 58 | echo "函数返回值 == $?" 59 | ``` 60 | 61 | > 函数 fun_return 执行 62 | > 函数返回值 == 0 63 | 64 | 返回大于255的数 65 | 66 | ```shell 67 | fun_return() 68 | { 69 | echo "函数 fun_return 执行" 70 | return 257 71 | } 72 | 73 | fun_return 74 | echo "函数返回值 == $?" 75 | ``` 76 | 77 | > 函数 fun_return 执行 78 | > 函数返回值 == 1 79 | 80 | **注意:**可以看到上面返回大于255的整数又重新从0开始计数,所以256=1,257=2 81 | 82 | ## 函数参数 83 | 84 | 在Shell中,调用函数时可以向其传递参数。在函数体内部,通过 `$n` 的形式来获取参数的值。 85 | 86 | `$*` 取出所有参数 87 | 88 | `$0`取出的是文件名 89 | 90 | 例如,`$1`表示第一个参数,`$2`表示第二个参数... 91 | 92 | ```shell 93 | #! /bin/bash 94 | 95 | fun_arg() 96 | { 97 | echo "第0个参数 == $0 " 98 | echo "第1个参数 == $1 " 99 | echo "第2个参数 == $2 " 100 | echo "所有参数 == $* " 101 | } 102 | 103 | fun_arg 1 2 3 4 5 104 | ``` 105 | 106 | > 第0个参数 == fun_arg.sh 107 | > 第1个参数 == 1 108 | > 第2个参数 == 2 109 | > 所有参数 == 1 2 3 4 5 110 | 111 | **注意:**\$10 不能获取第十个参数,获取第十个参数需要\${10}。 112 | 113 | ​ 当n>=10时,需要使用`${n}`来获取参数。 114 | 115 | | 参数处理 | 说明 | 116 | | -------- | ------------------------------------------------------------ | 117 | | $# | 传递到脚本的参数个数 | 118 | | $* | 以一个单字符串显示所有向脚本传递的参数 | 119 | | $$ | 脚本运行的当前进程ID号 | 120 | | $! | 后台运行的最后一个进程的ID号 | 121 | | $@ | 与$*相同,但是使用时加引号,并在引号中返回每个参数。 | 122 | | $- | 显示Shell使用的当前选项,与set命令功能相同。 | 123 | | $? | 显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误。 | 124 | 125 | ## 系统函数 126 | 127 | ### basename函数 128 | 129 | 语法:basename \[string/ pathname] [suffix] 130 | 131 | 描述:basename命令会删除所有的前缀包括最好一个`/`字符,然后将字符串显示出来 132 | 133 | 选项:suffix为后缀,如果suffix被指定,basename会将pathname或string中的suffix去掉。 134 | 135 | ```shell 136 | basename /home/shell.txt 137 | basename /home/shell.txt .txt 138 | ``` 139 | 140 | > shell.txt 141 | > 142 | > shell 143 | 144 | ### dirname函数 145 | 146 | 语法:dirname 文件绝对路径 147 | 148 | 描述:从给定的包含绝对路径的文件名中去除文件名(非目录部分),然后返回剩下的路径(目录的部分) 149 | 150 | ```shell 151 | dirname /home/simple/shell.txt 152 | ``` 153 | 154 | > /home/simple 155 | 156 | -------------------------------------------------------------------------------- /shell/include_file.md: -------------------------------------------------------------------------------- 1 | # 文件包含 2 | 3 | ## 语法定义 4 | 5 | 和其他语言一样,Shell 也可以包含外部脚本。这样可以很方便的封装一些公用的代码作为一个独立的文件。 6 | 7 | ```shell 8 | . filename # 注意点号(.)和文件名中间有一空格 9 | 或 10 | source filename 11 | ``` 12 | 13 | ## 实例 14 | 15 | include1.sh 16 | 17 | ```shell 18 | #!/bin/bash 19 | 20 | url="www.simplepeng.com" 21 | ``` 22 | 23 | include2.sh 24 | 25 | ```shell 26 | #!/bin/bash 27 | 28 | #. include1.sh 29 | #. ./include.sh 30 | 31 | source include1.sh 32 | #source ./include1.sh 33 | 34 | echo "网址 == $url" 35 | ``` 36 | 37 | > 网址 == www.simplepeng.com 38 | 39 | -------------------------------------------------------------------------------- /shell/intro.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | 3 | Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。 4 | 5 | Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。 6 | 7 | Ken Thompson 的 sh 是第一种 Unix Shell,Windows Explorer 是一个典型的图形界面 Shell。 8 | 9 | ## Shell 脚本 10 | 11 | Shell 脚本(shell script),是一种为 shell 编写的脚本程序。 12 | 13 | 业界所说的 shell 通常都是指 shell 脚本,但读者朋友要知道,shell 和 shell script 是两个不同的概念。 14 | 15 | 由于习惯的原因,简洁起见,本文出现的 "shell编程" 都是指 shell 脚本编程,不是指开发 shell 自身。 16 | 17 | Linux Shell 脚本以`.sh`结尾 18 | 19 | ## Hello World 20 | 21 | ```shell 22 | #!/bin/bash 23 | 24 | echo "hello world" 25 | ``` 26 | 27 | > 执行shell脚本首先要使脚本拥有可执行权限 28 | > 29 | > sudo chmod 775 helloworld.sh 30 | > 31 | > 执行shell脚本 32 | > 33 | > ./helloworld.sh 34 | > 35 | > 或者 36 | > 37 | > sh helloworld.sh //这种方式不需要修改可执行权限 38 | 39 | `#!`是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行,即使用哪一种 Shell 执行该脚本。 40 | 41 | `echo`命令用于向窗口输出文本。 -------------------------------------------------------------------------------- /shell/io.md: -------------------------------------------------------------------------------- 1 | # 输入和输出 2 | 3 | ## echo命令 4 | 5 | `echo`指令用于输出字符串 6 | 7 | ```shell 8 | echo string 9 | ``` 10 | 11 | ### 显示普通字符串 12 | 13 | ```shell 14 | echo "hello world" 15 | ``` 16 | 17 | 这里的双引号可以省略 18 | 19 | > hello world 20 | 21 | ### 显示转义字符串 22 | 23 | ```shell 24 | echo "\"hello world\" 25 | ``` 26 | 27 | > "hello world" 28 | 29 | ### 显示变量 30 | 31 | `read `命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量 32 | 33 | ```shell 34 | #! /bin/bash 35 | 36 | read var 37 | echo "var == ${var}" 38 | ``` 39 | 40 | > sh read.sh 41 | > hello # 标准输入 42 | > var == hello # 输出 43 | 44 | ### 换行\不换行 45 | 46 | ```shell 47 | echo "hello \n" 48 | echo "world" 49 | 50 | echo "hello \c" 51 | echo "world" 52 | 53 | echo "" 54 | echo "hello" 55 | echo "world" 56 | ``` 57 | 58 | > hello 59 | > 60 | > world 61 | > hello world 62 | > 63 | > hello 64 | > world 65 | 66 | ### 输出结果重定向到文件 67 | 68 | ```shell 69 | echo "hello world" > filename 70 | ``` 71 | 72 | ### 原样输出字符串,不转义 73 | 74 | 使用单引号 75 | 76 | ```shell 77 | echo '$name\"' 78 | ``` 79 | 80 | > $name\\" 81 | 82 | ### 显示命令执行结果 83 | 84 | ```shell 85 | echo `date` 86 | ``` 87 | 88 | > 2018年10月22日 星期一 15时26分29秒 CST 89 | 90 | **注意:**执行命令用的反引号,不是单引号 91 | 92 | ## printf命令 93 | 94 | printf 命令模仿 C 程序库(library)里的 printf() 程序。 95 | 96 | printf 由 POSIX 标准所定义,因此使用 printf 的脚本比使用 echo 移植性好。 97 | 98 | 默认 printf 不会像 echo 自动添加换行符,我们可以手动添加 \n。 99 | 100 | ```shell 101 | printf format-string [arguments...] 102 | ``` 103 | 104 | - **format-string:** 为格式控制字符串 105 | - **arguments:** 为参数列表。 106 | 107 | ```shell 108 | #! /bin/bash 109 | 110 | printf "%s\n" "hello" 111 | printf "%d\n" 10 112 | printf "%c\n" 'a' 113 | printf "%f\n" 11.11 114 | ``` 115 | 116 | > hello 117 | > 10 118 | > a 119 | > 11.110000 120 | 121 | ## 重定向 122 | 123 | | 命令 | 说明 | 124 | | --------------- | -------------------------------------------------- | 125 | | command > file | 将输出重定向到 file。 | 126 | | command < file | 将输入重定向到 file。 | 127 | | command >> file | 将输出以追加的方式重定向到 file。 | 128 | | n > file | 将文件描述符为 n 的文件重定向到 file。 | 129 | | n >> file | 将文件描述符为 n 的文件以追加的方式重定向到 file。 | 130 | | n >& m | 将输出文件 m 和 n 合并。 | 131 | | n <& m | 将输入文件 m 和 n 合并。 | 132 | | << tag | 将开始标记 tag 和结束标记 tag 之间的内容作为输入。 | 133 | 134 | **注意:**文件描述符 `0 `通常是`标准输入(STDIN)`,`1` 是`标准输出(STDOUT`),`2 `是`标准错误输出(STDERR)` 135 | 136 | ### /dev/null 文件 137 | 138 | 如果希望执行某个命令,但又不希望在屏幕上显示输出结果,那么可以将输出重定向到 /dev/null 139 | 140 | ```shell 141 | $ command > /dev/null 142 | ``` 143 | 144 | /dev/null 是一个特殊的文件,写入到它的内容都会被丢弃。 145 | 146 | 如果尝试从该文件读取内容,那么什么也读不到。 147 | 148 | 但是 /dev/null 文件非常有用,将命令的输出重定向到它,会起到"禁止输出"的效果。如果希望屏蔽 stdout 和 stderr,可以这样写: 149 | 150 | ```shell 151 | # 如果希望屏蔽 stdout 和 stderr,可以这样写: 152 | command > /dev/null 2>&1 153 | # 0 是标准输入(STDIN), 154 | # 1 是标准输出(STDOUT), 155 | # 2 是标准错误输出(STDERR) 156 | ``` 157 | 158 | -------------------------------------------------------------------------------- /shell/reference.md: -------------------------------------------------------------------------------- 1 | ## 参考 2 | 3 | * [菜鸟教程](https://www.runoob.com/linux/linux-shell.html) -------------------------------------------------------------------------------- /shell/string.md: -------------------------------------------------------------------------------- 1 | # 字符串 2 | 3 | ## 单引号 4 | 5 | ```shell 6 | str='hello world' 7 | ``` 8 | 9 | * 单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的 10 | * 单引号字串中不能出现单独一个的单引号(对单引号使用转义符后也不行),但可成对出现,作为字符串拼接使用。 11 | 12 | ## 双引号 13 | 14 | ```shell 15 | s='xx' 16 | str="hello \"${s}\" world" 17 | ``` 18 | 19 | * 双引号里可以有变量 20 | * 双引号里可以出现转义字符 21 | 22 | ## 字符串拼接 23 | 24 | ```shell 25 | #!/bin/bash 26 | 27 | str="world" 28 | # 使用双引号拼接 29 | str1="hello, "$str" !" 30 | str2="hello, ${str} !" 31 | echo $str1 $str2 32 | # 使用单引号拼接 33 | str3='hello, '$str' !' 34 | str4='hello, ${str} !' 35 | echo $str3 $str4 36 | # 新字符串为拼接的字符串 37 | str5=$str1$str4 38 | echo $str5 39 | ``` 40 | 41 | ```shell 42 | hello, world ! hello, world ! 43 | hello, world ! hello, ${str} ! 44 | hello, world !hello, ${str} ! 45 | ``` 46 | 47 | ## 获取字符串长度 48 | 49 | ```shell 50 | #!/bin/bash 51 | str="hello world" 52 | echo ${#str} 53 | ``` 54 | 55 | > 11 56 | 57 | ## 提取子字符串 58 | 59 | ```shell 60 | #!/bin/bash 61 | str="hello world" 62 | echo ${str:1:4} # 输出 ello 63 | ``` 64 | 65 | ## 查找子字符串 66 | 67 | 查找字符 **i** 或 **o** 的位置(哪个字母先出现就计算哪个) 68 | 69 | ```shell 70 | string="runoob is a great site" 71 | echo `expr index "$string" io` # 输出 4 72 | ``` 73 | 74 | **注意:** 以上脚本中 `` `是反引号,而不是单引号` '` -------------------------------------------------------------------------------- /shell/tools.md: -------------------------------------------------------------------------------- 1 | # Shell工具 2 | 3 | ## cut 4 | 5 | cut命令从文件的每一行剪切字节、字符和字段并将这些字节、字符和字段输出。 6 | 7 | 基本用法:cut [选项参数] filename 8 | 9 | 说明:默认分隔符是制表符 10 | 11 | 选项参数说明: 12 | 13 | | 选项参数 | 功能 | 14 | | -------- | ---------------------------- | 15 | | -f | 列号,提取第几列 | 16 | | -d | 分隔符,按照指定分隔符分割列 | 17 | 18 | ```shell 19 | //cut.txt 20 | dong shen 21 | guan zhen 22 | wo wo 23 | lai lai 24 | le le 25 | ``` 26 | 27 | ```shell 28 | cut -d " " -f 1 cut.txt 29 | ``` 30 | 31 | > dong 32 | > 33 | > guan 34 | > 35 | > wo 36 | > 37 | > lai 38 | > 39 | > le 40 | 41 | ## sed 42 | 43 | sed是一种`流`编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”,接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。**文件内容并没有改变**,除非你使用重定向存储输出。 44 | 45 | 基本用法:sed [选项参数] ‘command’ filename 46 | 47 | 选项参数说明: 48 | 49 | | 选项参数 | 功能 | 50 | | -------- | ----------------------------------- | 51 | | -e | 直接在指令列模式上进行sed的动作编辑 | 52 | 53 | 命令功能描述: 54 | 55 | | 命令 | 功能描述 | 56 | | ---- | --------------------------------------- | 57 | | a | 新增,a的后面可以接字符串,在下一行出现 | 58 | | d | 删除 | 59 | | s | 查找并替换 | 60 | 61 | -------------------------------------------------------------------------------- /shell/var.md: -------------------------------------------------------------------------------- 1 | # 变量 2 | 3 | ## 变量类型 4 | 5 | 1. 局部变量: 局部变量在脚本或命令中定义,仅在当前shell实例中有效,其他shell启动的程序不能访问局部变量。 6 | 2. 环境变量:所有的程序,包括shell启动的程序,都能访问环境变量,有些程序需要环境变量来保证其正常运行。必要的时候shell脚本也可以定义环境变量。 7 | 3. shell变量:shell变量是由shell程序设置的特殊变量。shell变量中有一部分是环境变量,有一部分是局部变量,这些变量保证了shell的正常运行 8 | 9 | ## 定义变量 10 | 11 | ```shell 12 | 变量名=变量值 13 | ``` 14 | 15 | * 变量名和值之前不能有空格 16 | * 不用分号结尾 17 | * 命名只能使用英文字母,数字和下划线,首个字符不能以数字开头 18 | * 中间不能有空格,可以使用下划线(_) 19 | * 不能使用标点符号 20 | * 不能使用bash里的关键字(可用help命令查看保留关键字) 21 | 22 | ## 使用变量 23 | 24 | 使用一个定义过的变量,只要在变量名前面加美元符号`$`即可 25 | 26 | ```shell 27 | echo $变量名 28 | echo ${变量名} 29 | ``` 30 | 31 | 变量名外面的花括号是可选的,加不加都行,加花括号是为了帮助解释器识别变量的边界 32 | 33 | ## 只读变量 34 | 35 | 使用 `readonly` 命令可以将变量定义为只读变量,只读变量的值不能被改变。 36 | 37 | ```shell 38 | 变量名=变量值 39 | readonly 变量名 40 | ``` 41 | 42 | ## 删除变量 43 | 44 | 使用 `unset` 命令可以删除变量。 45 | 46 | ```shell 47 | unset 变量名 48 | ``` 49 | 50 | ```shell 51 | #!/bin/bash 52 | 53 | a=1 54 | b="b" 55 | readonly c=3 56 | 57 | echo $a 58 | echo ${b} 59 | echo $c 60 | c=4 61 | ``` 62 | 63 | > 1 64 | > b 65 | > 3 66 | > ./var.sh: line 10: c: readonly variable 67 | 68 | ## 系统变量 69 | 70 | ### 常用系统变量 71 | 72 | `$HOME`、`$PWD`、`$SHELL`、`$USER`等 73 | 74 | ```shell 75 | #!/bin/bash 76 | 77 | echo $HOME 78 | echo $PWD 79 | echo $SHELL 80 | echo $USER 81 | ``` 82 | 83 | > /Users/simple 84 | > /Users/simple/Desktop/WorkSpace/KeepLearning/Shell/3.变量 85 | > /bin/zsh 86 | > simple 87 | 88 | ### 显示当前Shell中的所有变量:`set` 89 | 90 | ```shell 91 | $ set 92 | '!'=0 93 | '#'=0 94 | '$'=1104 95 | '*'=( ) 96 | -=569JNRXZghiklms 97 | 0=-zsh 98 | ``` 99 | 100 | ## 特殊变量 101 | 102 | ### $n 103 | 104 | 描述:n为数字,`$0`代表该脚本名称,`$1-$9`代表第一到第九个参数,十以上的参数需要用大括号包含,`${10}` 105 | 106 | ### $# 107 | 108 | 描述:获取所有输入参数的个数,常用于循环。 109 | 110 | ### `$*`,`$@` 111 | 112 | `$*`:这个变量代表命令行中所有的参数,`$*`把所有参数看成一个整体。 113 | 114 | `$@`:这个变量也代表命令行中所有的参数,`$@`把每个参数区分对待。 115 | 116 | ### $? 117 | 118 | 描述:最后一次执行的命令的返回状态,如果这个变量的值为0,证明上一次命令正确执行。如果这个变量的值为非0(具体是哪个数,由命令自己来决定),则证明上一个命令执行不正确了。 119 | 120 | --------------------------------------------------------------------------------