Showing preview only (1,159K chars total). Download the full file or copy to clipboard to get everything.
Repository: suoyuesmile/full-stack-developer
Branch: master
Commit: 6068b6934e0b
Files: 389
Total size: 14.3 MB
Directory structure:
gitextract_o3sr3lo_/
├── .gitattributes
├── .gitignore
├── .vscode/
│ └── launch.json
├── README.md
├── articals/
│ ├── c/
│ │ ├── Demo/
│ │ │ ├── argv[2]
│ │ │ ├── bug1.c
│ │ │ ├── mywords
│ │ │ ├── test.c
│ │ │ ├── test10.c
│ │ │ ├── test11.c
│ │ │ ├── test12.c
│ │ │ ├── test13.c
│ │ │ ├── test14.c
│ │ │ ├── test15.c
│ │ │ ├── test16.c
│ │ │ ├── test17.c
│ │ │ ├── test18.c
│ │ │ ├── test19.c
│ │ │ ├── test2.c
│ │ │ ├── test20.c
│ │ │ ├── test21.c
│ │ │ ├── test22.c
│ │ │ ├── test23.c
│ │ │ ├── test24.c
│ │ │ ├── test25.c
│ │ │ ├── test26.c
│ │ │ ├── test27.c
│ │ │ ├── test28.c
│ │ │ ├── test29.c
│ │ │ ├── test3.c
│ │ │ ├── test30.c
│ │ │ ├── test31.c
│ │ │ ├── test32.c
│ │ │ ├── test33.c
│ │ │ ├── test34.c
│ │ │ ├── test35.c
│ │ │ ├── test36.c
│ │ │ ├── test37.c
│ │ │ ├── test38.c
│ │ │ ├── test39.c
│ │ │ ├── test4.c
│ │ │ ├── test40.c
│ │ │ ├── test41.c
│ │ │ ├── test42.c
│ │ │ ├── test43.c
│ │ │ ├── test44.c
│ │ │ ├── test45.c
│ │ │ ├── test46.c
│ │ │ ├── test47.c
│ │ │ ├── test48.c
│ │ │ ├── test49.c
│ │ │ ├── test5.c
│ │ │ ├── test50.c
│ │ │ ├── test51.c
│ │ │ ├── test52.c
│ │ │ ├── test53.c
│ │ │ ├── test54.c
│ │ │ ├── test55.c
│ │ │ ├── test56.c
│ │ │ ├── test57.c
│ │ │ ├── test58.c
│ │ │ ├── test59.c
│ │ │ ├── test6.c
│ │ │ ├── test60.c
│ │ │ ├── test61.c
│ │ │ ├── test62.c
│ │ │ ├── test63.c
│ │ │ ├── test64.c
│ │ │ ├── test65.c
│ │ │ ├── test66.c
│ │ │ ├── test67.c
│ │ │ ├── test68.c
│ │ │ ├── test69.c
│ │ │ ├── test7.c
│ │ │ ├── test70.c
│ │ │ ├── test71.c
│ │ │ ├── test72.c
│ │ │ ├── test73.c
│ │ │ ├── test74.c
│ │ │ ├── test75.c
│ │ │ ├── test76.c
│ │ │ ├── test77.c
│ │ │ ├── test78.c
│ │ │ ├── test79.c
│ │ │ ├── test8.c
│ │ │ ├── test80.c
│ │ │ ├── test81.c
│ │ │ ├── test82.c
│ │ │ ├── test83.c
│ │ │ ├── test84.c
│ │ │ ├── test85.c
│ │ │ ├── test86.c
│ │ │ ├── test87.c
│ │ │ ├── test88.c
│ │ │ ├── test89.c
│ │ │ ├── test9.c
│ │ │ ├── test90.c
│ │ │ ├── test91.c
│ │ │ ├── test91.h
│ │ │ ├── test92.c
│ │ │ ├── test93.c
│ │ │ ├── test94.c
│ │ │ ├── test95.c
│ │ │ ├── test96.c
│ │ │ ├── test97.c
│ │ │ ├── test98.c
│ │ │ ├── test99.c
│ │ │ ├── testDice_d.c
│ │ │ ├── testFgets.c
│ │ │ ├── testFgets2.c
│ │ │ ├── testFgets3.c
│ │ │ ├── testFileIO.c
│ │ │ ├── testGets.c
│ │ │ ├── testIO.c
│ │ │ ├── testP02.c
│ │ │ ├── testPntAdd.c
│ │ │ ├── testPo.c
│ │ │ ├── testPoint.c
│ │ │ ├── testPrintfScanf.c
│ │ │ ├── testR_d.c
│ │ │ ├── testRand.c
│ │ │ ├── testRandom.c
│ │ │ ├── testRecursion.c
│ │ │ ├── testReducto.c
│ │ │ ├── testScope.c
│ │ │ ├── testStrSort.c
│ │ │ ├── testSwap.c
│ │ │ ├── testToBinary.c
│ │ │ ├── words
│ │ │ ├── words.red
│ │ │ └── wordscp
│ │ ├── array.md
│ │ ├── data.md
│ │ ├── fileIO.md
│ │ ├── function.md
│ │ ├── memory.md
│ │ └── string.md
│ ├── c++/
│ │ ├── class.md
│ │ ├── function.md
│ │ ├── oop.md
│ │ ├── reload.md
│ │ ├── str_map_arr.md
│ │ └── var.md
│ ├── h5/
│ │ ├── 0001.md
│ │ ├── 0002.md
│ │ └── 0003.md
│ ├── interview/
│ │ └── 0001.md
│ ├── js/
│ │ ├── 0001.md
│ │ └── 0002.md
│ ├── react/
│ │ └── 0001.md
│ └── vue/
│ ├── 0001.md
│ └── 0002.md
├── booknotes/
│ ├── bst.md
│ ├── compute.md
│ ├── demo/
│ │ ├── AVL.class.cpp
│ │ ├── BST.class.cpp
│ │ ├── BTNode.h
│ │ ├── BTree.class.cpp
│ │ ├── BinNode.h
│ │ ├── BinTree.class.cpp
│ │ ├── Edge.h
│ │ ├── Graph.class.cpp
│ │ ├── GraphMatrix.class.cpp
│ │ ├── Lcs.cpp
│ │ ├── List.class.cpp
│ │ ├── ListNode.h
│ │ ├── Node.h
│ │ ├── PQ.class.cpp
│ │ ├── PQ_ComplHeap.class.cpp
│ │ ├── Queue.class.cpp
│ │ ├── RedBlack.class.cpp
│ │ ├── SList.class.cpp
│ │ ├── Splay.class.cpp
│ │ ├── Stack.class.cpp
│ │ ├── Vector.class.cpp
│ │ ├── VectorTest.cpp
│ │ ├── Vertex.h
│ │ ├── a_bubbleSort.cpp
│ │ ├── a_convert.cpp
│ │ ├── a_evaluate.cpp
│ │ ├── a_fib.cpp
│ │ ├── a_hailstone.cpp
│ │ ├── a_paren.cpp
│ │ ├── a_sum.cpp
│ │ ├── a_vector.cpp
│ │ └── sort.cpp
│ ├── graph.md
│ ├── hash.md
│ ├── list.md
│ ├── proqueue.md
│ ├── sort.md
│ ├── string.md
│ ├── sum.md
│ ├── superBST.md
│ ├── tree.md
│ └── vector.md
├── package.json
├── public/
│ └── html/
│ ├── demo-box-model.html
│ ├── demo-display.html
│ ├── demo-float.html
│ ├── demo-position.html
│ └── layout.css
├── src/
│ ├── README.md
│ ├── algorithm/
│ │ ├── array/
│ │ │ ├── insert.js
│ │ │ └── searchInsert.js
│ │ ├── search/
│ │ │ └── binsearch.js
│ │ ├── sort/
│ │ │ ├── bubblesort.js
│ │ │ └── quicksort.js
│ │ └── string/
│ │ └── repeat.js
│ ├── babel/
│ │ └── tiny-compiler/
│ │ └── index.js
│ ├── cryto/
│ │ └── sha256.js
│ ├── css/
│ │ ├── box-model.html
│ │ ├── center.html
│ │ ├── flex.html
│ │ ├── float.html
│ │ ├── hairline.html
│ │ ├── layout.html
│ │ ├── three-layout.html
│ │ ├── two-layout.html
│ │ └── var.html
│ ├── data-structure/
│ │ ├── linklist-circle.js
│ │ ├── linklist-curd.js
│ │ ├── linklist.js
│ │ └── list.js
│ ├── javascript/
│ │ ├── array.js
│ │ ├── async_sync.js
│ │ ├── block-scope.js
│ │ ├── call.js
│ │ ├── callback.js
│ │ ├── class/
│ │ │ └── construct.js
│ │ ├── class.js
│ │ ├── closure/
│ │ │ ├── closure-circle.js
│ │ │ └── proxy.js
│ │ ├── code/
│ │ │ ├── huiwen-longest-str.js
│ │ │ ├── is-huiwen-num.js
│ │ │ ├── is-huiwen-string.js
│ │ │ ├── longest-asc-str.js
│ │ │ ├── longest-norepeat-str.js
│ │ │ ├── merge-two-array.js
│ │ │ ├── merge-two-lists.js
│ │ │ ├── two-nums-2.js
│ │ │ ├── two-nums-add.js
│ │ │ ├── two-nums.js
│ │ │ └── valid-parent.js
│ │ ├── curry.js
│ │ ├── debounce.js
│ │ ├── dom.js
│ │ ├── event-loop.js
│ │ ├── event.js
│ │ ├── flat.js
│ │ ├── function-scope.js
│ │ ├── function-this.js
│ │ ├── hoisting.js
│ │ ├── implement/
│ │ │ ├── apply.js
│ │ │ ├── async.js
│ │ │ ├── bind.js
│ │ │ ├── class.js
│ │ │ ├── compose.js
│ │ │ ├── copy.js
│ │ │ ├── inherit.js
│ │ │ ├── new.js
│ │ │ ├── pipe.js
│ │ │ ├── promise.js
│ │ │ ├── reduce.js
│ │ │ └── sleep.js
│ │ ├── inherit.js
│ │ ├── map.js
│ │ ├── new.js
│ │ ├── object/
│ │ │ ├── copy.js
│ │ │ ├── enum.js
│ │ │ ├── exist.js
│ │ │ ├── get-set.js
│ │ │ ├── iterator.js
│ │ │ ├── property-desciptor.js
│ │ │ └── traverse.js
│ │ ├── promise.js
│ │ ├── proto.js
│ │ ├── proxy/
│ │ │ └── base.js
│ │ ├── recursion/
│ │ │ └── base.js
│ │ ├── regExp.js
│ │ ├── scope.js
│ │ ├── set/
│ │ │ └── set.js
│ │ ├── set.js
│ │ ├── sleep.js
│ │ ├── string.js
│ │ ├── this.js
│ │ ├── throttle.js
│ │ ├── type.js
│ │ └── uniqu.js
│ ├── json/
│ │ ├── data.json
│ │ ├── distinct_data.json
│ │ ├── manage__origin_data.json
│ │ ├── manage_cata_data.js
│ │ └── manage_cata_data.json
│ ├── koa/
│ │ ├── db/
│ │ │ └── index.js
│ │ └── index.js
│ ├── leetcode/
│ │ ├── 1.两数之和.js
│ │ ├── 13.罗马数字转整数.js
│ │ ├── 14.最长公共前缀.js
│ │ ├── 165.比较版本号.js
│ │ ├── 2.两数相加.js
│ │ ├── 20.有效的括号.js
│ │ ├── 21.合并两个有序链表.js
│ │ ├── 26.删除排序数组中的重复项.js
│ │ ├── 27.移除元素.js
│ │ ├── 28.实现-str-str.js
│ │ ├── 3.无重复字符的最长子串.js
│ │ ├── 341.扁平化嵌套列表迭代器.js
│ │ ├── 35.搜索插入位置.js
│ │ ├── 38.外观数列.js
│ │ ├── 53.最大子序和.js
│ │ ├── 58.最后一个单词的长度.js
│ │ ├── 66.加一.js
│ │ ├── 67.二进制求和.js
│ │ ├── 69.x-的平方根.js
│ │ ├── 7.整数反转.js
│ │ └── 9.回文数.js
│ ├── linux/
│ │ └── process_manage.sh
│ ├── node/
│ │ ├── api-test/
│ │ │ └── image.js
│ │ ├── app/
│ │ │ ├── index.js
│ │ │ ├── requestHandles.js
│ │ │ ├── router.js
│ │ │ └── server.js
│ │ ├── file/
│ │ │ ├── file-download.js
│ │ │ └── file-read.js
│ │ └── node-fetch/
│ │ └── index.js
│ ├── question/
│ │ └── interserction.js
│ ├── react/
│ │ ├── app/
│ │ │ ├── .gitignore
│ │ │ ├── README.md
│ │ │ ├── package.json
│ │ │ ├── public/
│ │ │ │ ├── index.html
│ │ │ │ ├── manifest.json
│ │ │ │ └── robots.txt
│ │ │ └── src/
│ │ │ ├── antd/
│ │ │ │ ├── searchDemo.js
│ │ │ │ └── upload.js
│ │ │ ├── antd-mobile/
│ │ │ │ ├── input.js
│ │ │ │ ├── picker-demo.js
│ │ │ │ ├── steps-demo.js
│ │ │ │ └── steps-demo.scss
│ │ │ ├── assets/
│ │ │ │ ├── font/
│ │ │ │ │ └── PingFangSC-Regular.fft
│ │ │ │ └── scss/
│ │ │ │ └── font.scss
│ │ │ ├── components/
│ │ │ │ ├── count-down.js
│ │ │ │ ├── steps-hooks.js
│ │ │ │ ├── steps.js
│ │ │ │ └── steps.scss
│ │ │ ├── examples/
│ │ │ │ └── steps-demo.js
│ │ │ ├── font/
│ │ │ │ └── pingfangsc-demo.js
│ │ │ ├── index.js
│ │ │ ├── paratice/
│ │ │ │ ├── hook.js
│ │ │ │ ├── index.css
│ │ │ │ ├── index.js
│ │ │ │ └── lasy-compontent.js
│ │ │ ├── redux.js
│ │ │ ├── router/
│ │ │ │ ├── index.js
│ │ │ │ └── index.scss
│ │ │ ├── serviceWorker.js
│ │ │ └── setupTests.js
│ │ ├── demo.html
│ │ └── demo.jsx
│ ├── shell/
│ │ └── image_filter.sh
│ ├── typescript/
│ │ ├── js/
│ │ │ ├── class-demo.js
│ │ │ ├── decorators-demo.js
│ │ │ ├── demo.js
│ │ │ ├── fn-demo.js
│ │ │ ├── function-demo.js
│ │ │ ├── generics-demo.js
│ │ │ ├── interface-demo.js
│ │ │ ├── overload-demo.js
│ │ │ ├── type-advanced-demo.js
│ │ │ ├── type-demo.js
│ │ │ └── type-inference-demo.js
│ │ └── ts/
│ │ ├── class-demo.ts
│ │ ├── decorators-demo.ts
│ │ ├── demo.ts
│ │ ├── function-demo.ts
│ │ ├── generics-demo.ts
│ │ ├── interface-demo.ts
│ │ ├── overload-demo.ts
│ │ ├── tsconfig.json
│ │ ├── type-advanced-demo.ts
│ │ ├── type-demo.ts
│ │ └── type-inference-demo.ts
│ ├── web-api/
│ │ ├── localstorage.js
│ │ └── sessionstorage.js
│ └── webpack/
│ └── simple-webpack/
│ ├── buddle.js
│ └── example/
│ ├── entry.js
│ ├── message.js
│ └── name.js
└── yarn-error.log
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
*.js linguist-language=JavaScript
*.css linguist-language=JavaScript
*.html linguist-language=JavaScript
*.c linguist-language=JavaScript
*.c++ linguist-language=JavaScript
*.php linguist-language=JavaScript
*.python linguist-language=JavaScript
*.scss linguist-language=JavaScript
================================================
FILE: .gitignore
================================================
/node_modules
/json
private-*
================================================
FILE: .vscode/launch.json
================================================
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}"
}
]
}
================================================
FILE: README.md
================================================
:rocket: _It's my records of the journey from phper to fronter, now sharing to you and hoping that these make sence for you. if you like it, please star it! Thank You!_
本博客将持续更新,喜欢请收藏STAR一下,更多内容在[suosmile](https://github.com/suoyuesmile)关注一下,谢谢~:yum:
<p align="center">
<a href="https://juejin.im/user/59a3e1de51882524401237cf/posts"><img src="https://img.shields.io/badge/小锁君少-掘金-blue.svg" alt="微信群"></a>
<a href="#公众号"><img src="https://img.shields.io/badge/%E5%85%AC%E4%BC%97%E5%8F%B7-前端攻城狗-green.svg" alt="公众号"></a>
</p>
文章将优先发布于掘金平台,点击关注掘金账号哦。如果需要接受通知请关注微信公众号@前端攻城狗!
<p align="center">
<img src="https://wx3.sinaimg.cn/mw690/3d9aebf7ly1gedb5v23swj20by0by753.jpg" alt="公众号">
</p>
## 前端技术实战、研究总结
### 个人技术博客文章列表
| 编号 | 名称 | 状态 |
| ---- | ---------------------------------------------------------------------------------------- | ---- |
| 0001 | [记一次忏悔的前端面试经验(Vue 双向绑定原理)](articals/vue/0001.md) | 完成 |
| 0002 | [关于这些天杭州各厂面试汇总(从JavaScript各种原理到框架源码](articals/interview/0001.md) | 完成 |
| 0003 | [3个小时能把 React 学到哪种程度?](articals/react/0001.md) | 完成 |
| 0004 | [如何让 Promise 控制业务流程(Re 同步异步 开始一步一步深入)](articals/js/0001.md) | 完成 |
| 0005 | [理解promise、 generator 、async & await 之间的联系](articals/js/0002.md) | 完成 |
| 0006 | [吃透移动端 1px](articals/h5/0001.md) | 完成 |
| 0007 | [吃透移动端 H5 响应式布局](articals/h5/0002.md) | 完成 |
| 0008 | [吃透移动端 H5 与 hybrid](articals/h5/0003.md) | 完成 |
| 0009 | [吃透 Vue 项目开发实践|16个方面深入前端工程化开发技巧《上》](articals/vue/0002.md) | 完成 |
| 0010 | [吃透 Vue 项目开发实践|16个方面深入前端工程化开发技巧《中》](https://juejin.im/post/5e15932ee51d4540f02fae27) | 完成 |
| 0011 | [吃透 Vue 项目开发实践|16个方面深入前端工程化开发技巧《下》](https://juejin.im/post/5e1eb1dff265da3e354ea2d0) | 完成 |
| 0012 | [杭州前端面试通关新手入门指南](https://juejin.im/user/59a3e1de51882524401237cf) | 完成 |
| 0013 | [TypeScript 语言精髓与项目实战]() | 10月计划 |
| 0014 | [Vue 到 React 全面比较与上手指南]() | 10月计划 |
| 0015 | [Node 入门练习]() | 10月计划 |
| 0016 | [前端技术框架与架构的思索与探索]() | 10月计划 |
### 每日一个编程小题
| 编号 | 名称 | 状态 | 难度 |
| ---- | ------------------------------------------------------ | ---- | ---- |
| 0001 | [1.两数相加](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/1.两数之和.js) | 完成 | 简单 |
| 0002 | [7.整数反转](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/7.整数反转.js) | 完成 | 简单 |
| 0003 | [9.回文数](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/9.回文数.js) | 完成 | 简单 |
| 0004 | [13.罗马数字转整数](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/13.罗马数字转整数.js) | 完成 | 简单 |
| 0005 | [14.最长公共前缀](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/14.最长公共前缀.js) | 完成 | 简单 |
| 0006 | [20.有效的括号](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/20.有效的括号.js) | 完成 | 简单 |
| 0007 | [26.删除排序数组中的重复项](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/26.删除排序数组中的重复项.js) | 完成 | 简单 |
| 0008 | [27.移除元素](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/27.移除元素.js) | 完成 | 简单 |
| 0009 | [28.实现-str-str](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/28.实现-str-str.js) | 完成 | 简单 |
| 0010 | [35.搜索插入位置](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/35.搜索插入位置.js) | 完成 | 简单 |
| 0011 | [58.最后一个单词的长度](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/58.最后一个单词的长度.js) | 完成 | 简单 |
| 0012 | [66.加一](https://github.com/suoyuesmile/suo-blog/blob/master/src/leetcode/66.加一.js) | 完成 | 简单 |
### 前端开放研究点 todo
#### JavaScript
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [闭包](articals/js/0002.md) | 10月计划 |
| 0002 | [this](articals/js/0002.md) | 10月计划 |
| 0003 | [new](articals/js/0002.md) | 10月计划 |
| 0004 | [深浅拷贝](articals/js/0002.md) | 10月计划 |
| 0005 | [promise](articals/js/0002.md) | 计划 |
| 0006 | [async、await](articals/js/0002.md) | 计划 |
| 0007 | [原型与原型链](articals/js/0002.md) | 计划 |
| 0008 | [继承](articals/js/0002.md) | 计划 |
| 0009 | [防抖与节流](articals/js/0002.md) | 计划 |
| 0010 | [类型判断](articals/js/0002.md) | 计划 |
| 0011 | [运行机制](articals/js/0002.md) | 计划 |
#### CSS
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [常用开发技巧](articals/js/0002.md) | 10月计划 |
| 0002 | [BFC](articals/js/0002.md) | 10月计划 |
| 0003 | [布局](articals/js/0002.md) | 10月计划 |
| 0004 | [flexbox](articals/js/0002.md) | 10月计划 |
| 0005 | [计量单位](articals/js/0002.md) | 计划 |
| 0006 | [提升UI效果](articals/js/0002.md) | 计划 |
| 0007 | [对齐](articals/js/0002.md) | 计划 |
| 0008 | [过渡与动画](articals/js/0002.md) | 计划 |
| 0009 | [预编译](articals/js/0002.md) | 计划 |
| 0010 | [高级用法](articals/js/0002.md) | 计划 |
#### HTML
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [常用开发技巧](articals/js/0002.md) | 10月计划 |
| 0002 | [语义化开发](articals/js/0002.md) | 10月计划 |
| 0003 | [块级与内联](articals/js/0002.md) | 10月计划 |
| 0004 | [DOM 树分析](articals/js/0002.md) | 10月计划 |
| 0004 | [PUG 相关](articals/js/0002.md) | 10月计划 |
#### TypeScript
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [常用开发技巧](articals/js/0002.md) | 10月计划 |
| 0002 | [类型增强与推断](articals/js/0002.md) | 10月计划 |
| 0003 | [面向对象开发](articals/js/0002.md) | 10月计划 |
| 0004 | [高级技巧](articals/js/0002.md) | 10月计划 |
| 0004 | [装饰器](articals/js/0002.md) | 10月计划 |
#### Node
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [常用开发技巧](articals/js/0002.md) | 10月计划 |
| 0002 | [服务提供](articals/js/0002.md) | 10月计划 |
| 0003 | [面向对象开发](articals/js/0002.md) | 10月计划 |
| 0004 | [高级技巧](articals/js/0002.md) | 10月计划 |
| 0004 | [装饰器](articals/js/0002.md) | 10月计划 |
#### Vue
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [常用开发技巧](articals/js/0002.md) | 10月计划 |
| 0002 | [服务提供](articals/js/0002.md) | 10月计划 |
| 0003 | [面向对象开发](articals/js/0002.md) | 10月计划 |
| 0004 | [高级技巧](articals/js/0002.md) | 10月计划 |
| 0004 | [装饰器](articals/js/0002.md) | 10月计划 |
#### React
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [常用开发技巧](articals/js/0002.md) | 10月计划 |
| 0002 | [服务提供](articals/js/0002.md) | 10月计划 |
| 0003 | [面向对象开发](articals/js/0002.md) | 10月计划 |
| 0004 | [高级技巧](articals/js/0002.md) | 10月计划 |
| 0004 | [装饰器](articals/js/0002.md) | 10月计划 |
#### Webpack
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [常用开发技巧](articals/js/0002.md) | 10月计划 |
| 0002 | [服务提供](articals/js/0002.md) | 10月计划 |
| 0003 | [面向对象开发](articals/js/0002.md) | 10月计划 |
| 0004 | [高级技巧](articals/js/0002.md) | 10月计划 |
| 0004 | [装饰器](articals/js/0002.md) | 10月计划 |
#### 浏览器
| 编号 | 名称 | 状态 |
| ---- | ----------------------------------- | ---- |
| 0001 | [常用开发技巧](articals/js/0002.md) | 10月计划 |
| 0002 | [服务提供](articals/js/0002.md) | 10月计划 |
| 0003 | [面向对象开发](articals/js/0002.md) | 10月计划 |
| 0004 | [高级技巧](articals/js/0002.md) | 10月计划 |
| 0004 | [装饰器](articals/js/0002.md) | 10月计划 |
## 编程基础笔记
### c & c++
| c | c++ |
| ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| [c语言基础之数据类型](articals/c/data.md) | [c++变量解析](articals/c++/var.md) |
| [c数组](articals/c/array.md) | [c++数组、向量、字符串](articals/c++/str_map_arr.md) |
| [c函数](articals/c/function.md) | [c++函数](articals/c++/function.md) |
| [c字符串](articals/c/string.md) | [c++类](articals/c++/class.md) |
| [c内存管理](articals/c/memory.md) | [c++面向对象](articals/c++/oop.md) |
| [c文件IO](articals/c/fileIO.md) | [c++操作符重载](articals/c++/reload.md) |
| **Reference** | **Reference** |
| [c/c++ 中文参考手册](http://zh.cppreference.com/) | [c 语言编程透视](https://www.gitbook.com/book/tinylab/cbook/details) |
| [c++ 并发编程指南](https://github.com/forhappy/Cplusplus-Concurrency-In-Practice) | [Linux C编程一站式学习](http://akaedu.github.io/book/) |
| [100个gdb小技巧](https://github.com/hellogcc/100-gdb-tips/blob/master/src/index.md) | [100个gcc小技巧](https://github.com/hellogcc/100-gcc-tips/blob/master/src/index.md) |
| [c/c++ Primer](https://github.com/andycai/cprimer) | [C++ Primer 5th Answers](https://github.com/Mooophy/Cpp-Primer) |
| [---------------表格内容填充物----------------]() | [---------------表格内容填充物----------------]() |
### 数据结构 & 算法
| 数据结构 | 算法 |
| ------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [数据结构之向量](src/note/vector.md) | [算法与数据结构知识归纳整理](src/note/sum.md) |
| [数据结构之列表](src/note/list.md) | [用来度量算法好坏的方法](src/note/computer.md) |
| [数据结构之二叉树](src/note/tree.md) | [算法之排序](http://blog.csdn.net/hguisu/article/details/7776068) |
| [数据结构之图](src/note/graph.md) | [以串为基础的算法](src/note/string.md) |
| [数据结构之二叉搜索树](src/note/bst.md) | [算法之递归](http://www.cnblogs.com/xiaoliu66007/p/3927111.html) |
| [数据结构之高级搜索树](src/note/superBST.md) | [算法之迭代](http://blog.csdn.net/l979951191/article/details/47659777) |
| [数据结构之优先级队列](src/note/proqueue.md) | [算法之动态规划](https://www.zhihu.com/question/23995189) |
| [数据结构之散列表](src/note/hash.md) | [算法之贪心算法](http://blog.csdn.net/effective_coder/article/details/8736718) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### 编译原理相关
| 编译原理 | |
| ------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [数据结构之向量](src/note/vector.md) | [算法与数据结构知识归纳整理](src/note/sum.md) |
| [数据结构之列表](src/note/list.md) | [用来度量算法好坏的方法](src/note/computer.md) |
| [数据结构之二叉树](src/note/tree.md) | [算法之排序](http://blog.csdn.net/hguisu/article/details/7776068) |
| [数据结构之图](src/note/graph.md) | [以串为基础的算法](src/note/string.md) |
| [数据结构之二叉搜索树](src/note/bst.md) | [算法之递归](http://www.cnblogs.com/xiaoliu66007/p/3927111.html) |
| [数据结构之高级搜索树](src/note/superBST.md) | [算法之迭代](http://blog.csdn.net/l979951191/article/details/47659777) |
| [数据结构之优先级队列](src/note/proqueue.md) | [算法之动态规划](https://www.zhihu.com/question/23995189) |
| [数据结构之散列表](src/note/hash.md) | [算法之贪心算法](http://blog.csdn.net/effective_coder/article/details/8736718) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
## 入门资料收集
### HTML & CSS 简单入门
| Reference | Reference |
| ---------------------------------------------------------------------- | ----------------------------------------------------------- |
| [W3C入门手册教程]() | [CSS语法参考](http://tympanus.net/codrops/css_reference) |
| [MDN HTML 中文文档](https://developer.mozilla.org/zh-CN/docs/Web/HTML) | [CSS3动画手册](http://isux.tencent.com/css3/index.html) |
| [HTML和CSS编码规范](http://codeguide.bootcss.com/) | [CSS3动画制作工具](http://isux.tencent.com/css3/tools.html) |
| [学习CSS布局](http://zh.learnlayout.com/) | [Emmet 文档](http://yanxyz.github.io/emmet-docs/) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### JavaScript & jQuery 基础入门
| Article | Article |
| -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [JavaScript继承设计机制](https://github.com/suoyuesmile/full-stack-developer/issues/14) | [JavaScript同源策略与规避](https://github.com/suoyuesmile/full-stack-developer/issues/15) |
| [jQuery设计思想](https://github.com/suoyuesmile/full-stack-developer/issues/12) | [jQuery最佳实践](https://github.com/suoyuesmile/full-stack-developer/issues/13) |
| [JavaScript严格模式](https://github.com/suoyuesmile/full-stack-developer/issues/10) | [JavaScript快速排序](https://github.com/suoyuesmile/full-stack-developer/issues/11) |
| [JavaScript模块化编程](https://github.com/suoyuesmile/full-stack-developer/issues/8) | [JavaScript异步编程 ](https://github.com/suoyuesmile/full-stack-developer/issues/9) |
| [JavaScript的this用法](https://github.com/suoyuesmile/full-stack-developer/issues/6) | [JavaScript定义类的方法](https://github.com/suoyuesmile/full-stack-developer/issues/7) |
| [JavaScript面向对象编程](https://github.com/suoyuesmile/full-stack-developer/issues/4) | [JavaScript闭包原理与分析](https://github.com/suoyuesmile/full-stack-developer/issues/5) |
| Reference | Reference |
| [廖雪峰JavaScript全栈教程](http://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000) | [jQuery 解构](http://www.cn-cuckoo.com/deconstructed/jquery.html) |
| [阮一峰 JavaScript基础教程](http://javascript.ruanyifeng.com) | [简单易懂的JQuery魔法](http://www.nowamagic.net/librarys/books/contents/jquery) |
| [JavaScript中的this陷阱的最全收集](https://segmentfault.com/a/1190000002640298) | [How to write jQuery plugin](http://i5ting.github.io/How-to-write-jQuery-plugin/build/jquery.plugin.html) |
| [Promise迷你书(中文版](http://liubin.github.io/promises-book) | [You Don't Need jQuery](https://github.com/oneuijs/You-Dont-Need-jQuery/blob/master/README.zh-CN.md) |
| [前端框架最新排名 TOP 100](https://www.awesomes.cn/rank) | [如何实现一个类jQuery?](https://github.com/MeCKodo/forchange) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### PHP 基础入门
| Reference | Reference |
| ------------------------------------------------------- | --------------------------------------------------------- |
| [w3c中php快速入门手册](http://www.w3school.com.cn/php/) | [ThinkPHP 入门视频教程(网盘)]() |
| [学习php的正确道路 ](http://www.phptherightway.com/) | [PHP 官方手册](http://php.net/manual/zh/) |
| [php官方组成员鸟哥的博客](http://www.laruence.com/ ) | [深入理解PHP内核](https://github.com/reeze/tipi) |
| [最热门php开发社区:phpchina](http://www.phpchina.com/) | [PHP扩展开发及内核应用](http://www.walu.cc/phpbook/) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### MySQL & Web Server 基础入门
| Reference | Reference |
| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [21分钟MySQL入门教程](http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html) | [Apache Spark 设计与实现](https://github.com/JerryLead/SparkInternals/tree/master/markdown) |
| [MySQL慕课网中免费进阶教程]() | [Nginx开发从入门到精通](http://tengine.taobao.org/book/index.html) | [Nginx教程从入门到精通](http://www.ttlsa.com/nginx/nginx-stu-pdf/) |
| [常用sql语句大集合]() | [OpenResty最佳实践](https://www.gitbook.com/book/moonbingbing/openresty-best-practices/details) |
| [MySQL索引数据结构及算法原理](http://blog.codinglabs.org/articles/theory-of-mysql-index.html) | [Apache 中文手册](http://works.jinbuguo.com/apache/menu22/index.html) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### Laravel & Yii 基础入门
| Reference | Reference |
| -------------------------------------------------------- | --------------------------------------------------------- |
| [Laravel5.1 中文文档](http://laravel-china.org/docs/5.1) | [YiiBook几本Yii框架的在线教程](http://yiibook.com//doc) |
| [Laravel 5.1 LTS 速查表](https://cs.phphub.org/) | [深入理解 Yii 2.0](http://www.digpage.com/) |
| [Laravel 最大的中国开发者社区]() | [Yii 框架中文文檔](http://www.yiichina.com/) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### Linux & Git 基础入门
| Reference | Reference |
| ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [Linux安装镜像(Unbutu16)]() | [Git window安装包]() |
| [鸟哥的Linux私房菜](http://vbird.dic.ksu.edu.tw/) | [Pro Git 中文版](https://www.gitbook.com/book/0532/progit/details) |
| [The Linux Command Line](http://billie66.github.io/TLCL/index.html) | [猴子都能懂的GIT入门](http://backlogtool.com/git-guide/cn/) |
| [UNIX TOOLBOX](http://cb.vu/unixtoolbox_zh_CN.xhtml) | [廖雪峰Git教程](http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### Sublime & Vim 简单使用
| Reference | Reference |
| ----------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| [Sublime使用技巧之快捷键](http://www.jb51.net/softjc/180873.html) | [exvim--vim 改良成IDE项目](http://exvim.github.io/docs-zh/intro/) |
| [Sublime插件大全](http://www.oschina.net/translate/20-powerful-sublimetext-plugins) | [Vim中文文档](https://github.com/vimcn/vimcdoc) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### Markdown 简单使用
| Reference | Reference |
| -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| [Markdown 语法说明 (简体中文版)](http://wowubuntu.com/markdown) | [Markdown入门参考](https://github.com/LearnShare/Learning-Markdown/blob/master/README.md) |
| [Mdeditor(国内在线markdown编辑器)](https://www.zybuluo.com/mdeditor) | [Stackedit(国外markdown编辑器)](https://stackedit.io) |
| [Mditor轻量级的markdown编辑器](http://bh-lay.github.io/mditor) | [lepture-editor](https://github.com/lepture/editor) |
| [Markdown-editor](https://github.com/jbt/markdown-editor) | |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### Weapp 基础教程
| Reference | Reference |
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- |
| [微信小程序简易教程](https://mp.weixin.qq.com/debug/wxadoc/dev/index.html?t=2017621) | [微信小程序官方组件库](https://mp.weixin.qq.com/debug/wxadoc/dev/component/text.html) |
| [微信小程序入门教程(视频)](http://pan.baidu.com/s/1c1OdUQc) | [有赞小程序ui组件](https://github.com/youzan/zanui-weapp) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### NodeJS & AngularJS 基础入门
| Reference | Reference |
| ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
| [Node.js 看了就懂系列](https://github.com/alsotang/node-lessons) | [AngularJS最佳实践和风格指南](https://github.com/mgechev/angularjs-style-guide/blob/master/README-zh-cn.md) |
| [你信不信5天学会NodeJS](http://nqdeng.github.io/7-days-nodejs/) | [AngularJS中译本](https://github.com/peiransun/angularjs-cn) |
| [从零开始的nodejs世界生活](http://blog.fens.me/series-nodejs) | [AngularJS入门教程](https://github.com/zensh/AngularjsTutorial_cn) |
| [赶紧的Node.js入门系列](http://www.nodebeginner.org/index-zh-cn.html) | [构建自己的AngularJS](https://github.com/xufei/Make-Your-Own-AngularJS/blob/master/01.md) |
| [Node初学者入门,NodeJS教程](http://ourjs.com/detail/529ca5950cb6498814000005) | [在Windows环境下构建AngularJS项目](http://www.waylau.com/build-angularjs-app-with-yeoman-in-windows/) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### React & Vue 文档
| Reference | Reference |
| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
| [React教程 我是菜鸟系列](http://www.runoob.com/react/react-tutorial.html) | [Vue官网](http://cn.vuejs.org) |
| [React.js快速开始系列](http://www.phperz.com/article/15/0712/140537.html#) | [Awesome-vue这是啥很厉害的样子](https://github.com/vuejs/awesome-vue) |
| [轻松入门React和Webpack](https://segmentfault.com/a/1190000002767365) | [Vue开发这论坛](http://forum.vuejs.org) |
| [Redux 中文文档](http://cn.redux.js.org/) | [移动端Vue组件集合](https://github.com/ElemeFE/mint-ui ) |
| [React介绍及实践教程](http://www.ibm.com/developerworks/cn/web/1509_dongyue_react/index.html) | [桌面端Vue集合](https://github.com/ElemeFE/element) |
| [React.js amazeui UI](http://amazeui.org/react) | [Vue菜鸟教程](http://www.runoob.com/w3cnote/vue2-start-coding.html) |
| [React Native 中文版](http://wiki.jikexueyuan.com/project/react-native) | [Vue快速入门](http://www.cnblogs.com/rik28/p/6024425.html) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### Front-end 整理一些资料
| Reference | Reference |
| --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| [前端知识汇总](https://github.com/JacksonTian/fks) | [前端开发大系概览图](https://github.com/unruledboy/WebFrontEndStack) |
| [免费的编程中文书籍索](https://github.com/justjavac/free-programming-books-zh_CN) | [前端书籍大全](https://github.com/dypsilon/frontend-dev-bookmarks) |
| [前端免费书籍大全](https://github.com/vhf/free-programming-books) | [重新介绍JavaScript(JS教程)](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/A_re-introduction_to_JavaScript) |
| [Gitbook](https://www.gitbook.com) | [Front-End-Develop 前端开发指南](https://github.com/Front-End-Developers-Hunan/Front-End-Develop-Guide) |
| [前端开发笔记本](https://li-xinyang.gitbooks.io/frontend-notebook/content) | [大前端工具集](https://github.com/nieweidong/fetool) |
| [前端开发者手册](https://dwqs.gitbooks.io/frontenddevhandbook/content) | [结合个人经历总结的前端入门方法](https://github.com/qiu-deqing/FE-learning) |
| [前端学习计划](http://blog.csdn.net/qq_25827845/article/details/53079094) | [前端知识体系图](img/qian.jpg) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### Front-end 规范相关
| Reference | Reference |
| ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [github工程师代码书写习惯](http://alloyteam.github.io/CodeGuide/) | [HTML&CSS编码规范 by @mdo](http://codeguide.bootcss.com) |
| [前端编码规范之js - by yuwenhui](http://yuwenhui.github.io) | [前端编码规范之js - by 李靖](http://www.cnblogs.com/hustskyking/p/javascript-spec.html) |
| [Airbnb JavaScript 编码规范](https://github.com/yuche/javascript#table-of-contents) | [AMD与CMD规范的区别](http://www.zhihu.com/question/20351507) |
| [AMD与CMD规范的区别](http://www.cnblogs.com/tugenhua0707/p/3507957.html) | [KISSY 源码规范](http://docs.kissyui.com/1.4/docs/html/tutorials/style-guide/kissy-source-style.html) |
| [前端代码规范及最佳实践](http://blog.jobbole.com/79075) | [百度前端规范](http://coderlmn.github.io/code-standards) |
| [JavaScript风格指南/编码规范](http://blog.jobbole.com/79484) | [网易前端开发规范](http://nec.netease.com/standard) |
| [前端规范资源列表](https://github.com/ecomfe/spec) | [Web 前端开发规范文档](http://codecloud.net/5622.html) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
### 性能优化相关
| Reference | Reference |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| [性能优化页面渲染](http://www.infoq.com/cn/articles/javascript-high-performance-animation-and-page-rendering) | [移动前端性能优化指南](http://isux.tencent.com/h5-performance.html) |
| [前端开发者必看的看的前端性能优化](http://www.uisdc.com/front-end-performance-for-web-designers-and-front-end-developers) | [前端性能再优化](http://www.zhangxinxu.com/wordpress/tag/%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD/) |
| [前端性能优化进阶大道](http://www.aliued.cn/2013/01/20/web%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E8%BF%9B%E9%98%B6%E8%B7%AF.html) | [前端性能指导书](http://www.feelcss.com/tag/%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD) |
| [YSLOW中文介绍](http://www.cnblogs.com/yslow) | [Yahoo团队实践分享:网站性能](http://www.360doc.com/content/10/0928/09/2588264_56971287.shtml) |
| [加载,不只是少一点点](http://tgideas.qq.com/webplat/info/news_version3/804/808/811/m579/201109/41355.shtml) | [12306谈谈网站前端性能](http://coolshell.cn/articles/6470.html) |
| [【高性能前端1】高性能HTML](http://www.alloyteam.com/2012/10/high-performance-html) | [【高性能前端2】高性能CSS](http://www.alloyteam.com/2012/10/high-performance-css) |
| [静态资源版本更新与缓存](http://www.infoq.com/cn/articles/front-end-engineering-and-performance-optimization-part1) | [静态资源管理与模板框架](http://www.infoq.com/cn/articles/front-end-engineering-and-performance-optimization-part2) |
| [HTTPS连接的前几毫秒发生了什么](http://blog.jobbole.com/48369) | [Yslow](http://uicss.cn/yslow/#more-12319) |
| [阿里无线前端Pt.1 加载期优化)](https://github.com/amfe/article/issues/1) | [前端网页性能最佳实践](http://www.cnblogs.com/developersupport/p/3248695.html) |
| [---------------------------------------------------]() | [-----------------------------------------------------]() |
================================================
FILE: articals/c/Demo/bug1.c
================================================
#include <stdio.h>
int alpha(char);
int main(){
char ch;
while( (ch = getchar()) != EOF ) {
printf("location: %d\n", alpha(ch) );
while( getchar() != '\n')
continue;
}
return 0;
}
int alpha(char ch){
if(ch >= 65 && ch <= 90)
{
printf("%c is upper alpha\n", ch);
ch -= 64;
}
else if(ch >=97 && ch <= 122)
{
ch -= 96;
printf("%c is lower alpha\n", ch);
}
else{
ch = -1;
printf("%c is not alpha\n", ch);
}
return ch;
}
================================================
FILE: articals/c/Demo/mywords
================================================
5.3 6.2 3.6 5.6 7.9
5.6 3.9 1.5 6.9 4.8
4.1 56.6 23.7 56.1 18.6
================================================
FILE: articals/c/Demo/test.c
================================================
#include <stdio.h>
/**
* @return
* @Author Suoyue
* @DateTime 2017-08-21
*/
int main(){
printf("shao suo\n");
printf("shao\nsuo\n");
printf("shao ");
printf("suo\n");
return 0;
}
//anything be careful
================================================
FILE: articals/c/Demo/test10.c
================================================
#include <stdio.h>
int main(){
int a = 66;
printf("ASCII = %c\n", a);
return 0;
}
================================================
FILE: articals/c/Demo/test11.c
================================================
#include <stdio.h>
int main(){
printf("\aStartled by the sudden sound, Sally shouted,\n\"By the Great Pumpkin, what was that!\"\n");
return 0;
}
================================================
FILE: articals/c/Demo/test12.c
================================================
#include <stdio.h>
int main(){
float f;
printf("Enter a floating-point value:");
scanf("%f", &f);
printf("fixed-point natation:%f\n", f);
printf("exponential natation:%e\n", f);
printf("p natation:%.2a\n", f);
return 0;
}
================================================
FILE: articals/c/Demo/test13.c
================================================
#include <stdio.h>
#define YEAR_S 3.156e+7
int main(){
float age;
printf("please input your age:");
scanf("%f", &age);
printf("your live for %.0f second \n", age * YEAR_S);
return 0;
}
================================================
FILE: articals/c/Demo/test14.c
================================================
#include <stdio.h>
#define WATER_W 3.0e-23
#define KATUO_W 950
int main(){
float n;
printf("please input kuatu num:");
scanf("%f", &n);
printf("water num: %e", n * KATUO_W / WATER_W);
return 0;
}
================================================
FILE: articals/c/Demo/test15.c
================================================
#include <stdio.h>
#define YIN_CM 2.54
int main(){
float h;
printf("please input your height:");
scanf("%f", &h);
printf("%f\n", h * YIN_CM);
return 0;
}
================================================
FILE: articals/c/Demo/test16.c
================================================
#include <stdio.h>
#define PIN_CUP 2
#define CUP_YAS 8
#define YAS_SOU 2
#define SOU_CHA 3
int main(){
float cup;
printf("please input cup:");
scanf("%f", &cup);
printf("pin=%f,yas=%f,sou=%f,cha=%f\n", cup*PIN_CUP, cup/CUP_YAS, cup/CUP_YAS/YAS_SOU, cup/CUP_YAS/YAS_SOU/SOU_CHA);
return 0;
}
================================================
FILE: articals/c/Demo/test17.c
================================================
#include <stdio.h>
#include <string.h>
int main(){
char fname[30];
char sname[30];
printf("please input your first name:");
scanf("%s", fname);
printf("please input your second name:");
scanf("%s", sname);
printf("%s,%s\n", sname, fname);
return 0;
}
================================================
FILE: articals/c/Demo/test18.c
================================================
#include <stdio.h>
int main(){
char fname[30], sname[30], tip[10] = "name:";
printf("please input your first name:");
scanf("%s", fname);
printf("please input your second name:");
scanf("%s", sname);
printf("\"%s %s\"\n", sname, fname);
printf("%-20s\"%s %s\"\n", tip, sname, fname);
printf("\"%s %s\"%20s\n", sname, fname, tip);
return 0;
}
================================================
FILE: articals/c/Demo/test19.c
================================================
#include <stdio.h>
int main(){
float f;
scanf("%f", &f);
printf("%.1f\n", f);
printf("%.1e\n", f);
return 0;
}
================================================
FILE: articals/c/Demo/test2.c
================================================
#include <stdio.h>
int main(){
char* name = "shaosuo";
char* address = "wuhan";
printf("name = %s, address = %s\n", name, address);
return 0;
}
================================================
FILE: articals/c/Demo/test20.c
================================================
#include <stdio.h>
int main(){
float h;
printf("please input your height(cm):");
scanf("%f", &h);
printf("Dabbey, your are %.3f (m)\n", h/100);
return 0;
}
================================================
FILE: articals/c/Demo/test21.c
================================================
#include <stdio.h>
int main(){
float speed, fsize;
printf("please input download speed, file size:");
scanf("%f%f", &speed, &fsize);
printf("At %.2f megabits per second, a file of %.2f megabytes downloads in %.2f seconds\n", speed, fsize, fsize/speed);
return 0;
}
================================================
FILE: articals/c/Demo/test22.c
================================================
#include <stdio.h>
#include <string.h>
int main(){
char fname[30], sname[30];
int flen, slen;
printf("please input your first name:");
scanf("%s", fname);
printf("please input your second name:");
scanf("%s", sname);
flen = strlen(fname);
slen = strlen(sname);
printf("%6s %6s\n", fname, sname);
printf("%6d %6d\n", flen, slen);
printf("%-6s %-6s\n", fname, sname);
printf("%-6d %-6d\n", flen, slen);
return 0;
}
================================================
FILE: articals/c/Demo/test23.c
================================================
#include <stdio.h>
#include <float.h>
int main(){
double d = 1.0/3.0;
float f = 1.0/3.0;
printf("%.6Lf, %.12Lf, %.18Lf\n", d, d, d);
printf("%.18Lf\n", DBL_DIG);
printf("%.6f, %.12f, %.18f\n", f, f, f);
printf("%.18f\n", FLT_DIG);
return 0;
}
================================================
FILE: articals/c/Demo/test24.c
================================================
#include <stdio.h>
#define JIA_S 3.785
#define YIN_KM 1.609
int main(){
float s, fule;
printf("please input s(yinli), fule(jialu):");
scanf("%f%f", &s, &fule);
printf("result:%.1f(KM/SHENG)\n", (s/YIN_KM)/(fule*JIA_S));
return 0;
}
================================================
FILE: articals/c/Demo/test25.c
================================================
#include <stdio.h>
#define ROUND 60
int main(){
int min = 1;
while(min > 0){
printf("please input a min:");
scanf("%d", &min);
printf("time: %d hours %d min\n", min/60, min%60);
}
return 0;
}
================================================
FILE: articals/c/Demo/test26.c
================================================
#include <stdio.h>
int main(){
int n, max;
printf("please input a intege:");
scanf("%d", &n);
max = n + 10;
while( n++ < max ){
printf("%d ", n);
}
return 0;
}
================================================
FILE: articals/c/Demo/test27.c
================================================
#include <stdio.h>
int main(){
int days = 1;
while(days){
printf("please input days:");
scanf("%d", &days);
printf("%d days are %d weeks, %d days\n", days, days/7, days%7);
}
return 0;
}
================================================
FILE: articals/c/Demo/test28.c
================================================
#include <stdio.h>
#define CM_INCHES 0.393701
#define CM_FEET 0.032808
int main(){
float height = 1.0;
while(height){
printf("Enter a height in centimeters:");
scanf("%f", &height);
printf("%.2f cm = %.0f feet, %.2f inches\n", height, height*CM_FEET, height*CM_INCHES);
}
return 0;
}
================================================
FILE: articals/c/Demo/test29.c
================================================
#include <stdio.h>
int main(){
int n, count = 0, sum = 0;
printf("please input n:");
scanf("%d" ,&n);
while( count++ < n){
sum += count;
}
printf("sum = %d\n", sum);
return 0;
}
================================================
FILE: articals/c/Demo/test3.c
================================================
#include <stdio.h>
void jolly();
void deny();
int main(){
jolly();
jolly();
jolly();
deny();
return 0;
}
void jolly(){
printf("For he's a jolly good fellow!\n");
}
void deny(){
printf("Which nobody can deny!\n");
}
================================================
FILE: articals/c/Demo/test30.c
================================================
#include <stdio.h>
int main(){
int n, count = 0, sum = 0;
printf("please input n:");
scanf("%d" ,&n);
while( count++ < n){
sum += count * count;
}
printf("sum = %d\n", sum);
return 0;
}
================================================
FILE: articals/c/Demo/test31.c
================================================
#include <stdio.h>
void thr(int n);
int main(){
int n;
scanf("%d", &n);
thr(n);
return 0;
}
void thr(int n){
printf("%d\n", n*n*n);
}
================================================
FILE: articals/c/Demo/test32.c
================================================
#include <stdio.h>
void resmode();
int main(){
int first, second;
printf("start!\n");
printf("input second operand\n");
scanf("%d", &second);
printf("input first operand\n");
scanf("%d", &first);
resmode(first, second);
printf("done!\n");
}
void resmode(int first, int second){
printf("%d %% %d is %d\n", first, second, first%second);
}
================================================
FILE: articals/c/Demo/test33.c
================================================
#include <stdio.h>
int main(){
char a[27] = "abcdefghijklmnopqrstuvwxyz";
int i = 0;
while( i++ < 26){
printf("%c\n", a[i-1]); //前面+1 ,-1即为真实元素
}
return 0;
}
================================================
FILE: articals/c/Demo/test34.c
================================================
#include <stdio.h>
int main(){
int i, j;
char ch = '$';
for(i = 0; i < 5; ++i){
for (j = 0; j <= i; ++j)
{
printf("%c", ch);
}
printf("\n");
}
return 0;
}
================================================
FILE: articals/c/Demo/test35.c
================================================
#include <stdio.h>
int main(){
char lets[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i, j;
for (i = 0; i < 6; ++i)
{
for (j = 0; j <= i; j++)
{
printf("%c", lets[5-j]);
}
printf("\n");
}
return 0;
}
================================================
FILE: articals/c/Demo/test36.c
================================================
#include <stdio.h>
int main(){
char lets[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i, j;
for (i = 0; i < 6; i++)
{
for (j = 0; j <= i; j++)
{
printf("%c", lets[i*(i+1)/2+j]);
}
printf("\n");
}
return 0;
}
================================================
FILE: articals/c/Demo/test37.c
================================================
#include <stdio.h>
#define START 64
int main(){
char ch;
int i, j;
scanf("%c", &ch);
for (j = 0; j < ch - START; ++j)
{
for (i = 0; i < ch - START - j - 1; ++i)
{
printf(" ");
}
for (i = 0; i < j ; ++i)
{
printf("%c", START + 1 + i);
}
printf("%c", START + j + 1);
for (i = j; i > 0; --i)
{
printf("%c", START + i);
}
printf("\n");
}
return 0;
}
================================================
FILE: articals/c/Demo/test38.c
================================================
#include <stdio.h>
int main(){
int i, start, end;
printf("start,end\n");
scanf("%d,%d",&start, &end);
for (i = start; i <= end; ++i)
{
printf("------------------------------\n");
printf("|%-9d|%-9d|%-9d|\n", i, i*i, i*i*i);
}
printf("------------------------------\n");
return 0;
}
================================================
FILE: articals/c/Demo/test39.c
================================================
#include <stdio.h>
#include <string.h>
int main(){
char w[50];
scanf("%s", w);
int len = strlen(w);
while(len-- >= 0){
printf("%c", w[len]);
}
return 0;
}
================================================
FILE: articals/c/Demo/test4.c
================================================
#include <stdio.h>
void br();
void ic();
int main(){
br();
printf(", ");
ic();
printf("\n");
ic();
printf(",\n");
br();
return 0;
}
void br(){
printf("Brazil, Russia");
}
void ic(){
printf("India, China");
}
================================================
FILE: articals/c/Demo/test40.c
================================================
#include <stdio.h>
int main(){
float num1, num2;
while (scanf("%f%f", &num1, &num2) != 2){
printf("please input correct digit!\n");
}
printf("%f\n", (num1-num2)/(num1*num2));
return 0;
}
//??????????????????????????????????
================================================
FILE: articals/c/Demo/test41.c
================================================
#include <stdio.h>
float addff(float f1, float f2);
int main(){
float num1, num2;
while ( scanf("%f%f", &num1, &num2) != 2 ){
printf("please input correct digit!\n");
}
printf("%f\n", addff(num1, num2));
return 0;
}
float addff(float f1, float f2){
return (f1-f2)/(f1*f2);
}
================================================
FILE: articals/c/Demo/test42.c
================================================
#include <stdio.h>
int main(){
int a, b;
printf("Enter lower and upper integer limits:");
scanf("%d%d", &a, &b);
while( a < b ){
printf("The sums of the squares from %d to %d is %d\n", a*a, b*b, a*a+b*b);
printf("Enter next set of limits:");
scanf("%d%d", &a, &b);
}
printf("done!\n");
return 0;
}
================================================
FILE: articals/c/Demo/test43.c
================================================
#include <stdio.h>
#define LEN 8
void swap(int *a, int *b);
int main()
{
int i, j, a[LEN];
for (i = 0; i < LEN; ++i)
{
scanf("%d", &a[i]);
}
for (i = 0; i < LEN -1; ++i)
{
for (j = 0; j < LEN - i - 1; ++j)
{
if(a[j] < a[j+1])
{
swap(&a[j], &a[j+1]);
}
}
}
for (i = 0; i < LEN; ++i)
{
printf("%d ", a[i]);
}
}
void swap(int *a, int *b)
{
int t = *a;
*a = *b;
*b = t;
}
================================================
FILE: articals/c/Demo/test44.c
================================================
#include <stdio.h>
int main(){
float f1 = 1.0, f2 = 1.0, sum1 = 0, sum2 = 0;
int i, n;
scanf("%d", &n);
while( n > 0){
f1 = 1.0, f2 = 1.0, sum1 = 0, sum2 = 0;
for (i = 0; i < n; ++i)
{
sum1 += f1/f2;
if( (i+1)%2 == 0 ) {
sum2 -= f1/f2;
}else{
sum2 += f1/f2;
}
f2++;
}
printf("sum1 = %f, sum2 = %f\n", sum1, sum2);
scanf("%d", &n);
}
return 0;
}
================================================
FILE: articals/c/Demo/test45.c
================================================
#include <stdio.h>
#define LEN 8
int main(){
int arr[LEN];
int i, tem = 1;
for (i = 0; i < LEN; ++i)
{
tem *= 2;
arr[i] = tem;
}
i = 0;
do{
printf("%d ", arr[i]);
i++;
}while (i < LEN);
return 0;
}
================================================
FILE: articals/c/Demo/test46.c
================================================
#include <stdio.h>
#define LEN 8
int main(){
double a[LEN], b[LEN], tem = 0;
int i;
for (i = 0; i < LEN; ++i)
{
printf("Enter a double is NO%d:", i+1);
scanf("%lf", &a[i]);
tem += a[i];
b[i] = tem; //灵活使用临时变量
}
i = 0;
while(i++ < LEN)
{
printf("%.2lf ", a[i-1]);
}
i = 0;
printf("\n");
while(i++ < LEN)
{
printf("%.2lf ", b[i-1]);
}
printf("\n");
return 0;
}
================================================
FILE: articals/c/Demo/test47.c
================================================
#include <stdio.h>
#include <string.h>
#define MAX_LEN 255
int main(){
char a[MAX_LEN];
scanf("%s", a);
int len = strlen(a);
while(len-- > 0){
printf("%c", a[len]);
}
return 0;
}
================================================
FILE: articals/c/Demo/test48.c
================================================
#include <stdio.h>
int main(){
int start = 5, week, weekfds, i = 0;
printf("start friends is %d\n", start);
scanf("%d", &week);
while(i++ < week){
weekfds= (start-i) * 2;
printf("week%d friends is %d\n", i, weekfds);
start = weekfds;
}
return 0;
}
================================================
FILE: articals/c/Demo/test49.c
================================================
#include <stdio.h>
#include <ctype.h>
int main(){
char ch;
int nblank = 0, nt = 0, n = 0;
while( (ch = getchar()) != '#' ){
if(ch == '\n')
nt++;
else if(isblank(ch))
nblank++;
else
n++;
}
printf("nblank = %d, nt = %d, n = %d\n", nblank, nt, n);
return 0;
}
================================================
FILE: articals/c/Demo/test5.c
================================================
#include <stdio.h>
int main(){
int toes = 10;
printf("toes*2 = %d, toes^2 = %d\n", toes * 2, toes * toes);
return 0;
}
================================================
FILE: articals/c/Demo/test50.c
================================================
#include <stdio.h>
int main(){
char ch;
int n = 0;
while( (ch = getchar()) != '#' ){
putchar(ch);
printf(" %d ", ch);
n++;
if(n % 8 == 0){
putchar('\n');
}
}
return 0;
}
================================================
FILE: articals/c/Demo/test51.c
================================================
#include <stdio.h>
int main(){
char ch, pre;
int n = 0;
while( (ch = getchar()) != '#' ){
if(pre == 'e' && ch == 'i')
n++;
pre = ch;
}
printf("%d\n", n);
return 0;
}
================================================
FILE: articals/c/Demo/test52.c
================================================
#include <stdio.h>
#define BASIC_SALARY 10.00
#define LOVER_RATE 0.15
#define MIDDLE_RATE 0.2
#define HIGH_RATE 0.25
int main(){
float work_hours, salary, tax, income;
printf("Enter your work hours:");
scanf("%f", &work_hours);
if(work_hours > 40){
work_hours= 40 + (work_hours-40) * 1.5;
}
salary = work_hours * BASIC_SALARY;
if(salary <= 300)
tax = salary * LOVER_RATE;
else if(salary <= 450)
tax = 300 * LOVER_RATE + (salary-300) * MIDDLE_RATE;
else
tax = 300 * LOVER_RATE + 150 * MIDDLE_RATE + (salary-450) * HIGH_RATE ;
income = salary - tax;
printf("his salary, tax, income are %.2f, %.2f, %.2f\n", salary, tax, income);
return 0;
}
================================================
FILE: articals/c/Demo/test53.c
================================================
#include <stdio.h>
#define LOVER_RATE 0.15
#define MIDDLE_RATE 0.2
#define HIGH_RATE 0.25
int main(){
float work_hours, basic, salary, tax, income;
int choice;
printf("Enter your work hours:");
scanf("%f", &work_hours);
printf("*******************************************************************\n");
printf("Enter the number corresponding to the desired pay rate or action:\n");
printf("1) $8.75/hr");
printf("\t\t\t2) $9.33/hr\n");
printf("3) $10.00/hr");
printf("\t\t\t4) $11.2/hr\n");
printf("5) quit!\n");
printf("*******************************************************************\n");
while ( scanf("%d", &choice) == 1){
switch (choice){
case 1: basic = 8.75; break;
case 2: basic = 9.33; break;
case 3: basic = 10.00; break;
case 4: basic = 11.2; break;
default: break;
}
}
if(work_hours > 40){
work_hours= 40 + (work_hours-40) * 1.5;
}
salary = work_hours * basic;
if(salary <= 300)
tax = salary * LOVER_RATE;
else if(salary <= 450)
tax = 300 * LOVER_RATE + (salary-300) * MIDDLE_RATE;
else
tax = 300 * LOVER_RATE + 150 * MIDDLE_RATE + (salary-450) * HIGH_RATE ;
income = salary - tax;
printf("his salary, tax, income are %.2f, %.2f, %.2f\n", salary, tax, income);
return 0;
}
================================================
FILE: articals/c/Demo/test54.c
================================================
#include <stdio.h>
#include <math.h>
#include <ctype.h>
_Bool isPrime(int n);
int main(){
unsigned a, i;
printf("Enter a integer n(n>0):");
if ( scanf("%u", &a) != 1 ) //not match but return 1
printf("enter a integer must more than 0");
else
for (i = 2; i <= a; ++i)
if(isPrime(i))
printf("%d ", i);
printf("\n");
return 0;
}
_Bool isPrime(int n){
_Bool res = 1;
int i, j;
for (i = 1; i <= sqrt(n); ++i)
for (j = sqrt(n); j < n; ++j)
if(i * j == n)
res = 0;
return res;
}
================================================
FILE: articals/c/Demo/test55.c
================================================
#include <stdio.h>
#define NORMAL_TAX 0.15
#define EXT_TAX 0.28
void menu();
int main(){
int choice;
float salary, ext_line, tax;
printf("enter your salary:\n");
scanf("%f", &salary);
menu();
while( scanf("%d", &choice) == 1){
switch (choice){
case 1: ext_line = 17850;break;
case 2: ext_line = 23900;break;
case 3: ext_line = 29750;break;
case 4: ext_line = 14875;break;
default: printf("bye\n");break;
}
tax = ( salary <= ext_line ? salary*NORMAL_TAX : ext_line*NORMAL_TAX + (salary-ext_line)*EXT_TAX );
printf("%.2f\n", tax);
}
return 0;
}
void menu(){
printf("enter a status choice:");
printf("**********status************\n");
printf(" 1) single\n");
printf(" 2) host\n");
printf(" 3) married\n");
printf(" 4) divorce\n");
printf(" 5) input 'q' eixt\n");
printf("****************************\n");
}
================================================
FILE: articals/c/Demo/test56.c
================================================
#include <stdio.h>
int main(){
char choice;
float fweight = 0, sweight = 0, tweight = 0;
float fcharge = 0, scharge = 0, tcharge = 0;
float weight, price, charge, orderCharge, orderWeight, account, extCharge, pay;
printf("enter a, b, c chooce your goods, q is quit:\n");
while ( (choice = getchar()) != 'q' )
{
if('\n' == choice)
continue;
if( choice == 'a' || choice == 'b' || choice == 'c' )
{
switch (choice)
{
case 'a':
price = 2.05;
printf("please enter want to buy yangli weight:\n");
scanf("%f", &weight); ;
fweight += weight;
fcharge += fweight * price;
printf("%.2f\n", fweight);
break;
case 'b':
price = 1.15;
printf("please enter want to buy taincai weight:\n");
scanf("%f", &weight);
sweight += weight;
scharge += sweight * price;
printf("%.2f\n", sweight);
break;
case 'c':
price = 1.09;
printf("please enter want to buy hulubo weight:\n");
scanf("%f", &weight);
tweight += weight;
tcharge += tweight * price;
printf("%.2f\n", tweight);
break;
default: ;
}
}
else
{
printf("pleae enter 'a', 'b', 'c' !\n");
}
printf("enter a, b, c chooce your goods, q is quit:\n");
}
orderWeight = fweight + sweight + tweight;
orderCharge = fcharge + scharge + tcharge;
account = orderCharge > 100 ? orderCharge * 0.05 : 0;
if( orderWeight <= 5 )
extCharge = 6.5;
else if( orderWeight <= 20)
extCharge = 14;
else
extCharge = 14 + (orderWeight-14) * 0.5;
pay = orderCharge + extCharge - account;
printf("******************* order ******************\n");
printf("*name-------price------weight-------charge*\n");
printf("*yang-------$2.05--------%9.2f---------$%9.2f*\n", fweight, fcharge);
printf("*tian-------$1.15--------%9.2f---------$%9.2f*\n", sweight, scharge);
printf("*hulobo-----$1.09--------%9.2f---------$%9.2f*\n", tweight, tcharge);
printf("totalWeight:%.2f, orderCharge:$%.2f", orderWeight, orderCharge);
printf("account:$%.2f, extCharge:$%.2f, pay:$%.2f\n", account, extCharge, pay);
printf("*************************************************\n");
return 0;
}
================================================
FILE: articals/c/Demo/test57.c
================================================
#include <stdio.h>
#include <ctype.h>
int main(){
char ch;
int count = 0;
while( (ch = getchar()) != EOF )
{
if(isblank(ch) || ch == '\n')
continue;
count++;
}
printf("count : %d\n", count);
return 0;
}
================================================
FILE: articals/c/Demo/test58.c
================================================
#include <stdio.h>
void dealSpecial(char sp);
int main(){
char ch;
while( (ch = getchar()) != EOF ){
// if( ch == '\n' )
// continue;
dealSpecial(ch);
// putchar(ch);
// while(getchar() != '\n')
// continue;
}
return 0;
}
void dealSpecial(char sp){
switch (sp){
case '\n': printf("\\n %d", sp); break;
case '\t': printf("\\t %d", sp); break;
case ' ': printf("\\ %d", sp); break;
}
}
================================================
FILE: articals/c/Demo/test59.c
================================================
#include <stdio.h>
#include <ctype.h>
int main(){
char ch;
int lower = 0, upper = 0;
while( (ch = getchar()) != EOF ){
if( ch == '\n' )
continue;
if(islower(ch))
lower++;
if(isupper(ch))
upper++;
}
printf("lower= %d, upper= %d\n", lower, upper);
return 0;
}
================================================
FILE: articals/c/Demo/test6.c
================================================
#include <stdio.h>
int main(){
int age = 23;
printf("my day in life:%d\n", age*365);
return 0;
}
================================================
FILE: articals/c/Demo/test60.c
================================================
#include <stdio.h>
int main(){
char ch;
int count = 0;
while( (ch = getchar()) != EOF ){
count++;
if(ch == ' ' || ch == '\n'){
printf("%d ", count - 1);
count = 0;
}
}
return 0;
}
================================================
FILE: articals/c/Demo/test61.c
================================================
#include <stdio.h>
int main(){
int ran, lower = 1, upper = 100, i = 0;
int smart = (lower + upper) / 2;
printf("please enter 1 ~ 100 a integer:");
scanf("%d", &ran);
while( ran != smart){
if(ran < smart)
upper = smart;
else
lower = smart;
i++;
printf("though %d times = %d\n", i, smart);
smart = (lower + upper) / 2;
}
printf("though %d times = %d\n", i+1, smart);
return 0;
}
================================================
FILE: articals/c/Demo/test62.c
================================================
#include <stdio.h>
void count();
int get_int();
char get_first();
char get_choice();
int main(){
char choice;
count();
while( (choice = get_choice()) != 'q' ){
switch (choice){
case 'a':
printf("buy low, sell high\n");
break;
case 'b':
printf("\a\n");
break;
case 'c':
count();
break;
default:
printf("error!!!\n");
break;
}
}
return 0;
}
//计数
void count(){
int n, i;
printf("Count how far?\n");
n = get_int();
for (int i = 0; i <= n; ++i)
{
printf("%d\n", i);
}
while( getchar() != '\n' )
continue;
}
//异常处理
int get_int(){
int n;
char ch;
while( scanf("%d", &n) != 1 ){
while( getchar() != '\n')
putchar(ch);
printf("is not a integer!!!\n");
}
return n;
}
//过滤换行符
char get_first(){
char choice;
choice = getchar();
while( getchar() != '\n' )
continue;
return choice;
}
//删选合适的字符
char get_choice(){
char choice;
printf("please enter a, b, c\n");
choice = get_first();
while( (choice < 'a' || choice > 'c') && choice != 'q'){
printf("please enter correct code!!\n");
choice = get_first();
}
return choice;
}
================================================
FILE: articals/c/Demo/test63.c
================================================
#include <stdio.h>
int main(){
return 0;
}
================================================
FILE: articals/c/Demo/test64.c
================================================
#include <stdio.h>
int main(){
return 0;
}
================================================
FILE: articals/c/Demo/test65.c
================================================
#include <stdio.h>
void show(char, int, int);
int main(void){
char a;
int b, c;
scanf("%c%d%d", &a, &b, &c);
show(a, b ,c);
return 0;
}
void show(char a, int b, int c) {
int i, j;
for (int i = 0; i < c; ++i)
{
for (int j = 0; j < b; ++j)
{
putchar(a);
}
putchar('\n');
}
}
================================================
FILE: articals/c/Demo/test66.c
================================================
#include <stdio.h>
double avg(double, double);
int main(){
double a, b;
scanf("%lf%lf", &a, &b);
printf("%.2lf", avg(a, b) );
return 0;
}
double avg(double a, double b){
return 1./( (1./a + 1./b)/2. );
}
================================================
FILE: articals/c/Demo/test67.c
================================================
#include <stdio.h>
void large_of(double *, double *);
int main(void){
double a, b;
scanf("%lf%lf", &a, &b);
large_of(&a, &b);
printf("%.2lf, %.2lf\n", a, b);
return 0;
}
void large_of(double *a, double *b){
// *a > *b ? *b = *a : *a = *b ; ??????
if( *a > *b )
*b = *a;
else
*a = *b;
}
================================================
FILE: articals/c/Demo/test68.c
================================================
#include <stdio.h>
void order(double *, double *, double *);
void swap(double *, double *);
int main(void){
double a, b, c;
scanf("%lf%lf%lf", &a, &b, &c);
order(&a, &b, &c);
printf("%.2lf, %.2lf, %.2lf\n", a, b, c);
return 0;
}
void order(double *a, double *b, double *c){
if(*a > *b)
swap(a, b);
if(*b > *c)
swap(b, c);
}
void swap(double *m, double *n){
double tem;
tem = *m;
*m = *n;
*n = tem;
}
================================================
FILE: articals/c/Demo/test69.c
================================================
#include <stdio.h>
double power(double, int);
int main(){
double n;
int c;
scanf("%lf%d", &n, &c);
printf("%.2lf\n", power(n, c));
return 0;
}
double power(double n, int c){
int i, pow = 1;
if( n == 0 )
return 0;
if( c == 0 )
return 1;
for (i = 1; i <= c; ++i)
pow *= n;
return pow;
}
================================================
FILE: articals/c/Demo/test7.c
================================================
#include <stdio.h>
void smile();
int main(){
int i, j;
for(i = 3; i > 0; i--)
{
for(j = i; j > 0; j--)
smile();
printf("\n");
}
return 0;
}
void smile(){
printf("Smile!");
}
================================================
FILE: articals/c/Demo/test70.c
================================================
#include <stdio.h>
double power(double, int);
int main(){
double n;
int c;
scanf("%lf%d", &n, &c);
printf("%.2lf\n", power(n, c));
return 0;
}
double power(double n, int c){
if( n == 0 )
return 0;
if( c == 0 )
return 1;
return n*power(n, c-1);
}
================================================
FILE: articals/c/Demo/test71.c
================================================
#include <stdio.h>
void to_base_n(int, int);
int main(void){
int x, n;
scanf("%d%d", &x, &n);
to_base_n(x, n);
return 0;
}
void to_base_n(int x, int n){
int r;
r = x%n;
if(x >= n)
to_base_n(x/n, n);
printf("%d", r );
}
================================================
FILE: articals/c/Demo/test72.c
================================================
#include <stdio.h>
int fibonacciRec(int); //递归
int fibonacci(int); //非递归
int main(void){
int n;
scanf("%d", &n);
printf("%d\n", fibonacciRec(n) );
printf("%d\n", fibonacci(n) );
return 0;
}
int fibonacciRec(int n){
if(n == 1 || n == 2)
return 1;
else
return fibonacciRec(n-1) + fibonacciRec(n-2);
}
int fibonacci(int n){
int i, fib1 = 1, fib2 = 1;
if( n == 1 || n == 2)
return 1;
for(i = 3 ; i <= n; i++){
fib2 = fib1 + fib2;
fib1 = fib2 - fib1;
}
return fib2;
}
================================================
FILE: articals/c/Demo/test73.c
================================================
#include <stdio.h>
#define N 5
void cp_arr(double [], const double [], int);
void cp_ptr(double [], const double *, int);
void cp_ptrs(double *, const double *, const double *);
void show_arr(double [], int);
int main(void){
double source[N] = {1, 2, 3, 4, 5};
double target1[N], target2[N], target3[N];
cp_arr(target1, source, N);
cp_ptr(target2, source, N);
cp_ptrs(target3, source, source+N);
show_arr(target1, N);
putchar('\n');
show_arr(target2, N);
putchar('\n');
show_arr(target3, N);
putchar('\n');
return 0;
}
void cp_arr(double target[], const double source[], int n){
int i;
for (i = 0; i < n; ++i)
{
target[i] = source[i];
}
}
void cp_ptr(double target[], const double *source, int n){
int i;
for (i = 0; i < n; ++i)
{
target[i] = *(source+i);
}
}
void cp_ptrs(double target[], const double *source_start, const double *source_end){
while(source_start < source_end){
*target = *source_start++;
target++;
}
}
void show_arr(double a[], int n){
int i;
for (i = 0; i < n; ++i)
{
printf("%.2lf ", a[i]);
}
}
================================================
FILE: articals/c/Demo/test74.c
================================================
#include <stdio.h>
#define SIZE 10
void sort(double [], int);
void swap(double *, double *);
void show_arr(const double [], int);
int main(void){
double a[] = {2,4,6,7,8,3,5,1,10,9};
sort(a, SIZE);
show_arr(a, SIZE);
return 0;
}
void sort(double a[], int n){
int i, j;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n - i; ++j)
if(a[j+1] > a[j])
swap(&a[j+1], &a[j]);
}
void swap(double *p, double *q){
double temp = *p;
*p = *q;
*q = temp;
}
void show_arr(const double a[], int n){
int i;
for (i = 0; i < n; ++i)
{
printf("%.2lf ", a[i]);
}
}
================================================
FILE: articals/c/Demo/test75.c
================================================
#include <stdio.h>
#define COLS 3
#define ROWS 2
void cp_arr(double [], const double [], int);
void cp2_arr2(double [][COLS], const double [][COLS], int);
void show_arr2(const double [][COLS], int);
int main(void){
double arr1[ROWS][COLS] = { {1,2,3}, {4,5,6} };
double arr2[ROWS][COLS];
cp2_arr2(arr2, arr1, ROWS);
show_arr2(arr2, ROWS);
return 0;
}
void cp_arr(double target[], const double source[], int n){
int i;
for (i = 0; i < n; ++i)
{
target[i] = source[i];
}
}
void cp2_arr2(double tgt[][COLS], const double src[][COLS], int rows){
int i;
for (i = 0; i < rows; ++i)
cp_arr(tgt[i], src[i], COLS);
}
void show_arr2(const double a[][COLS], int rows){
int i, j;
for (i = 0; i < rows; ++i)
{
for (j = 0; j < COLS; ++j)
printf("%.2lf ", a[i][j]);
printf("\n");
}
}
================================================
FILE: articals/c/Demo/test76.c
================================================
#include <stdio.h>
#define N 7
#define M 3
void cp_arr(double [], const double [], int);
void cp_ptr(double [], const double *, int);
void cp_ptrs(double *, const double *, const double *);
void show_arr(double [], int);
int main(void){
double source[N] = {1, 2, 3, 4, 5, 6, 7};
double target1[M], target2[M], target3[M];
cp_arr(target1, source, M);
cp_ptr(target2, source, M);
cp_ptrs(target3, source+2, source+5);
show_arr(target1, M);
putchar('\n');
show_arr(target2, M);
putchar('\n');
show_arr(target3, M);
putchar('\n');
return 0;
}
void cp_arr(double target[], const double source[], int m){
int i;
for (i = 2; i < 2+m; ++i)
{
target[i-2] = source[i];
}
}
void cp_ptr(double target[], const double *source, int m){
int i;
for (i = 2; i < 2+m; ++i)
{
target[i-2] = *(source+i);
}
}
void cp_ptrs(double target[], const double *source_start, const double *source_end){
while(source_start < source_end){
*target = *source_start++;
target++;
}
}
void show_arr(double a[], int n){
int i;
for (i = 0; i < n; ++i)
{
printf("%.2lf ", a[i]);
}
}
================================================
FILE: articals/c/Demo/test77.c
================================================
#include <stdio.h>
void show_vla(int, int, double [*][*]);
int main(void){
int i, j;
const int rows = 3;
const int cols = 5;
double arr[rows][cols] = {{1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15}};
double arr2[rows][cols];
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
arr2[i][j] = arr[i][j];
show_vla(rows, cols, arr2[rows][cols]);
return 0;
}
void show_vla(int rows, int cols, double arr[rows][cols]){
int i, j;
for (i = 0; i < rows; ++i)
for(j = 0; j< cols; ++j)
printf("%lf ", arr[i][j]);
}
//不能使用可变长数组
================================================
FILE: articals/c/Demo/test78.c
================================================
#include <stdio.h>
#define YEAR 5
#define MONTH 12
void perYearFall(const double [][MONTH], int);
void perMonthFall(const double [][MONTH], int);
int main(void){
const double a[YEAR][MONTH] = {
{4.3, 4.3, 4.3, 3.0, 2.0, 1.2, 0.2, 0.2, 0.4, 2.4, 3.5, 6.6},
{8.5, 8.2, 1.2, 1.6, 2.4, 0.0, 5.2, 0.9, 0.3, 0.9, 1.4, 7.3},
{9.1, 8.5, 6.7, 4.3, 2.1, 0.8, 0.2, 0.2, 1.1, 2.3, 6.1, 8.4},
{7.2, 9.9, 8.4, 3.3, 1.2, 0.8, 1.4, 0.0, 0.6, 1.7, 4.3, 6.2},
{7.6, 5.6, 3.8, 2.8, 3.8, 0.2, 0.0, 0.0, 0.0, 1.3, 2.6, 5.2}
};
perYearFall(a, YEAR);
perMonthFall(a, YEAR);
return 0;
}
void perYearFall(const double a[][MONTH], int year){
int i, j;
double yearFall, sumYearFall;
for(i = 0; i < year; i++)
{
yearFall = 0;
for(j = 0; j < MONTH; j++)
yearFall += a[i][j];
printf("%dyear\t\t%.2lf(inches)\n", i+2010, yearFall);
sumYearFall += yearFall;
}
printf("\nthe yearly average is %.2lf\n\n", sumYearFall/year);
}
void perMonthFall(const double a[][MONTH], int year){
int i, j;
double monthFall;
for (i = 0; i < MONTH; ++i)
{
monthFall = 0;
for (j = 0; j < year; ++j)
monthFall += a[j][i];
printf("%.2lf ", monthFall/5);
}
}
================================================
FILE: articals/c/Demo/test79.c
================================================
#include <stdio.h>
#define ROWS 3
#define COLS 5
void getArr(double [][COLS], int);
void averageGroup(double [], const double [][COLS], int);
double average(const double [][COLS], int);
double max(double [][COLS], int);
void swap(double *, double *);
void show(double [], int, double, double);
int main(void){
double arr[ROWS][COLS] = {0};
double aveGroup[ROWS] = {0}; //注意初始化
double ave = 0;
double m = 0;
getArr(arr, ROWS);
averageGroup(aveGroup, arr, ROWS);
ave = average(arr, ROWS);
m = max(arr, ROWS);
show(aveGroup, ROWS, ave, m);
return 0;
}
void getArr(double a[][COLS], int rows){
int i, j;
for (i = 0; i < rows; ++i)
for (j = 0; j < COLS; ++j)
scanf("%lf", &a[i][j]);
}
void averageGroup(double b[], const double a[][COLS], int rows){
int i, j;
double sum = 0;
for (i = 0; i < rows; ++i){
for (j = 0; j < COLS; ++j)
sum += a[i][j];
b[i] = sum/rows;
}
}
double average(const double a[][COLS], int rows){
int i, j;
double sum = 0;
for (i = 0; i < rows; ++i)
for (j = 0; j < COLS; ++j)
sum += a[i][j];
return sum/(COLS*rows);
}
double max(double a[][COLS], int rows){
int i, j;
for (i = 0; i < rows; ++i)
{
for (j = 0; j < COLS; ++j)
if(a[i][j] > a[i][j+1])
swap(&a[i][j], &a[i][j+1]);
if(a[i][j] > a[i+1][j])
swap(&a[i][j], &a[i+1][j]);
}
return a[i][j];
}
void show(double a[], int size, double av, double m){
int i;
for(i = 0; i < size; i++){
printf("%.2lf ", a[i]);
}
printf("\naverage = %.2lf\n", av);
printf("max = %.2lf\n", m);
}
void swap(double *p, double *q){
double temp = *p;
*p = *q;
*q = temp;
}
================================================
FILE: articals/c/Demo/test8.c
================================================
#include <stdio.h>
void one_three();
void two();
int main(){
printf("starting now:\n");
one_three();
printf("done\n");
return 0;
}
void one_three(){
printf("one\n");
two();
printf("three\n");
}
void two(){
printf("two\n");
}
================================================
FILE: articals/c/Demo/test80.c
================================================
#include <stdio.h>
int main(void){
return 0;
}
================================================
FILE: articals/c/Demo/test81.c
================================================
#include <stdio.h>
#define N 50
void getStr(char *, int );
int main(void){
char a[N];
getStr(a, N);
puts(a);
return 0;
}
void getStr(char * a, int n){
while( n-- > 0){
a[n] = getchar();
}
}
================================================
FILE: articals/c/Demo/test82.c
================================================
#include <stdio.h>
#define N 50
void getStr(char *, int );
int main(void){
char a[N];;
getStr(a, N);
puts(a);
return 0;
}
void getStr(char * a, int n) {
int i = 0;
while( i++ < n){
a[i] = getchar();
if(a[i] == '\n' || a[i] == '\t' || a[i] == '\0') {
break;
}
}
}
================================================
FILE: articals/c/Demo/test83.c
================================================
#include <stdio.h>
#include <string.h>
void reStr(char *, int);
int main(void){
char str[20];
while( fgets(str, 20, stdin) ){
reStr(str, strlen(str));
fputs(str, stdout);
}
return 0;
}
void reStr(char * a, int n){
int i = 0;
char b[n];
while(i++ < n)
b[i] = a[i-1];
i = 0;
while(n-- >= 0){
a[i] = b[n];
i++;
}
}
================================================
FILE: articals/c/Demo/test84.c
================================================
#include <stdio.h>
int main(void){
return 0;
}
================================================
FILE: articals/c/Demo/test85.c
================================================
#include <stdio.h>
#include <ctype.h>
#define N 10
int main(void){
char a[N];
int i, word, up, low, num, pun;
int countWord, countUp, countLow, countNum, countPun;
while( fgets(a, N, stdin) != NULL && a[0] != '\n'){
i = 0, num=0, low=0, up=0, pun=0, word=0;
if(a[i] == '\n')
a[i] == ' ';
if(isblank(a[i]))
word++;
else if(isdigit(a[i]))
num++;
else if(islower(a[i]))
low++;
else if(isupper(a[i]))
up++;
else
pun++;
}
return 0;
}
================================================
FILE: articals/c/Demo/test86.c
================================================
#include <stdio.h>
int main(int argc, char * argv[]){
int i = argc;
printf("%d\n", argc);
while( i-- > 1 )
puts(argv[i]);
}
// --i情况 (没想到argc = 4) (- -)
// test86 see you later 0 1 2 3
// 1) (i = 4- 1 = 3, i > 0) -> a[3]
// 2) (i = 3- 1 = 2, i > 0) -> a[2]
// i--情况
// 1) (i = 4 > 0, i = 3 - 1 = 2) -> a[3]
// 2) (i = 3 > 0, i = 2 - 1 = 2) -> a[2]
// 3) (i = 2 > 0, i = 1 - 1 = 1) -> a[1]
================================================
FILE: articals/c/Demo/test87.c
================================================
================================================
FILE: articals/c/Demo/test88.c
================================================
#include <stdio.h>
#include <ctype.h>
#define N 10
void pf(char * , int);
void toUpper(char * , int);
void toLower(char * , int);
int main(int argc, char * argv[]){
char a[N];
switch (argv[1][1]){
case 'p': pf(a, N); break;
case 'u': toUpper(a, N); break;
case 'l': toLower(a, N); break;
default : puts("enter error!"); break;
}
return 0;
}
//原样输出
void pf(char * a, int n){
while( fgets(a, n, stdin) != NULL && a[0] != '\n'){
fputs(a, stdout);
}
}
//输出大写
void toLower(char * a, int n){
int i;
while( fgets(a, n, stdin) != NULL && a[0] != '\n'){
i = 0;
while(i++ < n-1){ // i=0<9 i=1 a[0], i=1<9 i=2 a[1] ---> i=8<9 i=9 a[8]
if(isupper(a[i-1]))
a[i-1] = tolower(a[i-1]);
}
fputs(a, stdout);
}
}
//输出小写
void toUpper(char * a, int n){
int i;
while( fgets(a, n, stdin) != NULL && a[0] != '\n'){
i = 0;
while(i++ < n-1){
if(islower(a[i-1]))
a[i-1] = toupper(a[i-1]);
}
fputs(a, stdout);
}
}
================================================
FILE: articals/c/Demo/test89.c
================================================
#include <stdio.h>
// int units = 0;
void critic(int );
int main(){
int units = 0;
scanf("%d", &units);
if(units != 56)
critic(units);
return 0;
}
void critic(int u){
printf("%d\n", u);
}
================================================
FILE: articals/c/Demo/test9.c
================================================
#include <stdio.h>
int main(){
int n = 2147483647;
float f = 1e+20;
float f1 = -f;
printf("n = %d, n+1 = %d\n", n, n+1);
printf("f = %f, f+1 = %f\n", f, f+1);
printf("f1 = %f, f1+1 = %f\n", f1, f1-1);
return 0;
}
================================================
FILE: articals/c/Demo/test90.c
================================================
#include <stdio.h>
int main(void){
int mode;
printf("enter 0 for metric, 1 for Us mode:\n");
while(scanf("%d", &mode) == 1 && mode >= 0){
set_mode(mode);
get_info();
show_info();
printf("enter 0 for metric, 1 for Us mode:\n");
printf("-1 to quit:");
}
return 0;
}
================================================
FILE: articals/c/Demo/test91.c
================================================
#include "test91.h"
void set_mode(int mode){
if(mode == 0)
fule = distance/kalub;
if(mode == 1)
fule = distance/kalub*100;
}
void get_info(void){
printf("enter a kalub, distance, fule:");
scanf("%lf%lf%lf", kalub, distance, fule);
}
void show_info(void){
printf("%d\n", fule);
}
================================================
FILE: articals/c/Demo/test91.h
================================================
#include <stdio.h>
double kalub;
double distance;
double fule;
void set_mode(int);
void show_info(void);
void get_info(void);
================================================
FILE: articals/c/Demo/test92.c
================================================
#include <stdio.h>
static int i = 0;
int a(void);
int main(){
int n = 10;
while( n-- )
printf("%d\n", a());
}
int a(void){
return ++i;
}
================================================
FILE: articals/c/Demo/test93.c
================================================
================================================
FILE: articals/c/Demo/test94.c
================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 1000
int rand1(int);
void count(const int *, int);
int main(){
int a[N] = {0};
srand( (unsigned int) time(0) );
for (int i = 0; i < N; ++i)
{
a[i] = rand1(10);
}
count(a, N);
}
//产生随机数
int rand1(int n){
return rand() % n + 1;
}
//计算每个数产生的个数
void count( const int *a, int n){
int b[10] = {0};
for(int j = 0; j < 10; ++j)
for(int i = 0; i < n; ++i)
if(a[i] == j+1)
b[j]++;
for (int i = 0; i < 10; ++i)
printf("%d\n", b[i]);
}
================================================
FILE: articals/c/Demo/test95.c
================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 100
int rand1(int);
void sort(int *, int);
void show(const int *, int);
int main(){
int a[N] = {0};
srand( (unsigned int) time(0) );
for (int i = 0; i < N; ++i)
{
a[i] = rand1(10);
}
show(a, N);
sort(a, N);
putchar('\n');
show(a, N);
}
//产生随机数
int rand1(int n){
return rand() % n + 1;
}
//选择排序
void sort(int *a, int n){
for (int top = 0; top < n - 1; ++top)
for (int seek = top + 1; seek < n; ++seek)
if( a[top] < a[seek]){
int tmp = a[top];
a[top] = a[seek];
a[seek] = tmp;
}
}
//打印数组
void show( const int *a, int n){
for (int i = 0; i < n; ++i)
{
printf("%d ", a[i]);
}
}
================================================
FILE: articals/c/Demo/test96.c
================================================
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
int get_n(){
int words;
if(scanf("%d", &words) == 1 && words > 0)
return words;
else
printf("enter error!!!\n");
}
void show(char * a[], int n){
int i = 0;
while( i++ < n ){
puts(a[i-1]);
}
}
int main(void){
int words, i = 0, j = 0;
char ch;
printf("how many words do you wish to enter:");
words = get_n(); //处理输入的单词数
// char * q [5] = (char (*) [5])malloc( SIZE * 5 * sizeof(char) );
//动态创建
printf("enter %d words:", words);
while( (ch = getchar()) != '\n' ){
if(ch == ' ')
{
char * p = (char *)malloc( i * sizeof(char) );
q[j] = p;
free( p );
j++;
i = 0;
continue;
}
i++;
}
show(q, words);
free( q );
return 0;
}
================================================
FILE: articals/c/Demo/test97.c
================================================
#include <stdio.h>
#include <stdlib.h>
#define SIZE 512
int main(int argc, char * argv[]){
FILE *in, *out;
char buff[SIZE];
//读文件到缓冲区
if( (in = fopen(argv[1], "r")) == NULL ){
fputs("error", stderr);
exit(EXIT_FAILURE);
}
fread(buff, SIZE, 1, in);
//从缓冲区写文件
if( (out = fopen(argv[2], "w")) == NULL ) {
fputs("error", stderr);
exit(EXIT_FAILURE);
}
fwrite(buff, SIZE, 1, out);
//关闭文件
if( fclose(in) != 0 || fclose(out) != 0 )
fputs("not close", stderr);
return 0;
}
================================================
FILE: articals/c/Demo/test98.c
================================================
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define SIZE 512
int main(){
char *infile, *outfile;
FILE *in, *out;
char buff[SIZE];
//输入到缓冲区
printf("enter a in file:");
scanf("%s", &infile);
if( (in = fopen(infile, "r") ) == NULL ){
fputs("std in eror", stderr);
exit(EXIT_FAILURE);
}
fgets(buff, in);
//从缓冲区输出到文件
printf("enter a out file:");
scanf("%s", &outfile);
if( (out = fopen(outfile, "w") ) == NULL ){
fputs("std out eror", stderr);
exit(EXIT_FAILURE);
}
fputs(buff, out);
return 0;
}
================================================
FILE: articals/c/Demo/test99.c
================================================
#include <stdio.h>
================================================
FILE: articals/c/Demo/testDice_d.c
================================================
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "testRandom.c"
int main(void){
int dice, roll;
int sides, status;
srand((unsigned int) time(0));
printf("enter a number of sides:\n");
while(scanf("%d", &sides) == 1 && sides > 0){
printf("how many dice\n");
//检查输入部分
if(status = scanf("%d", &dice) != 1){
if(status == EOF) //检查是否有文件终止符
break;
else{
while(getchar() != '\n') //去掉换行符
continue;
continue;
}
}
//开始计算骰子总和
roll = roll_n_dice(dice, sides);
//打印结果
printf("total %d , using %d times, %d-sides\n", roll, dice, sides);
}
printf("function called : %d\n", roll_count);
return 0;
}
================================================
FILE: articals/c/Demo/testFgets.c
================================================
#include <stdio.h>
int main(void){
char a[10];
fgets(a, 7, stdin); //读了dsfdsf个字符+'\0'
fputs(a, stdout); //输出dsfdsf\0 没有+'\n'
return 0;
}
//dsfdsfsdgfdgdffdg
//dsfdsf
================================================
FILE: articals/c/Demo/testFgets2.c
================================================
#include <stdio.h>
#define N 10
int main(void){
char word[N];
while( fgets(word, N, stdin) != NULL && word[0] != '\n' ){
fputs(word, stdout);
}
return 0;
}
================================================
FILE: articals/c/Demo/testFgets3.c
================================================
#include <stdio.h>
#define N 10
int main(){
char word[N];
int i;
while( fgets(word, N, stdin) != NULL && word[0] != '\n'){
i = 0;
while(word[i] != '\n' && word[i] != '\0')
i++; //不是换行符或者空字符跳过
if(word[i] == '\n')
word[i] = '\0'; //遇到换行符,转空字符
else
while(getchar() != '\n') //读到空字符,丢弃剩余
continue;
fputs(word, stdout);
}
return 0;
}
================================================
FILE: articals/c/Demo/testFileIO.c
================================================
#include <stdio.h>
int main(){
char ch;
while( (ch = getchar()) != EOF){
putchar(ch);
}
return 0;
}
================================================
FILE: articals/c/Demo/testGets.c
================================================
#include <stdio.h>
int main(void){
char name[10];
gets(name);
puts(name);
return 0;
}
//fgdfgdfgdfgfdgfdg
//fgdfgdfgdfgfdgfdg
================================================
FILE: articals/c/Demo/testIO.c
================================================
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[]){
int ch; //读取文件,存储每个字符的地方
FILE *fp; //文件指针
unsigned long count = 0;
if(argc != 2){
printf("Usage: %s filename \n", argv[0]);
}
if( (fp = fopen(argv[1], "r")) == NULL ){
printf("can't open %s\n", argv[1]);
exit(EXIT_FAILURE);
}
while( (ch = getc(fp)) != EOF ){
putc(ch, stdout);
count++;
}
fclose(fp);
printf("File %s has %lu characters\n", argv[1], count);
return 0;
}
================================================
FILE: articals/c/Demo/testP02.c
================================================
#include <stdio.h>
int a[2] = {1, 2};
int main(){
int *p1, *p2, *p3;
p1 = p2 = p3 = a;
printf("%d,%d,%d\n", *p1, *p1++, *p1);
//分析: 函数中参数的传递的顺序是从右往左传递
// 1.*p1 = 1 ==> no3 = 1
// 2.*p1++ ==> *p1 = 1 , p1 += 1; ==> no2 = 1
// 3.*p1 ==> a[1] ==> no3 = 2
printf("%d,%d,%d\n", *p2, (*p2)++, *p2);
// 1.*p2 = 1 ==> no3 = 1
// 2.(*p2)++ ==> *p2 = a[0], no2 = 1, a[0] = 2
// 3.*p2 = a[0] = 2 ==> no1 = 2;
printf("%d,%d,%d\n", *p3, *++p3, *p3);
// 1.*p3 = a[0] ==> no3 = 2
// 2.*++p3 ==> p3= p3+1 = &a[1] => no2 = *&a[1] = 2
// 3.*p3 = a[1] = 2 ==> no1 = 2;
return 0;
}
// 2 1 1
// 2 1 1
// 2 2 2
================================================
FILE: articals/c/Demo/testPntAdd.c
================================================
#include <stdio.h>
#define SIZE 10
int main(){
short a[SIZE] = {1,2,3,4,5,6,7,8,9,10};
double b[SIZE] = {1,2,3,4,5,6,7,8,9,10};
short i, *pa = a;
double *pb = b;
for (i = 0; i < 2; ++i)
{
printf("pa%d point %p\n", i, pa++);
}
for (i = 0; i < 2; ++i)
{
printf("pb%d point %p\n", i, pb++);
}
}
// pa0 point 0060FF00
// pa1 point 0060FF02
// pb0 point 0060FEB0
// pb1 point 0060FEB8
================================================
FILE: articals/c/Demo/testPo.c
================================================
#include <stdio.h>
#define SIZE 4
int sum(int * start, int * end){
int sum = 0;
while(start < end){
sum += *start++;
//分析 * ++(后缀) 同优先级右结合
//步骤分解 1. start先使用用 sum = sum + *start;
// 2. start = start + 1;
}
return sum;
}
int main(void){
int a[SIZE] = {1, 2 , 3, 4};
printf("%d", sum(a, a+SIZE));
return 0;
}
// 10 正确
================================================
FILE: articals/c/Demo/testPoint.c
================================================
#include <stdio.h>
int arr(int);
int main(void){
int (* p)(int);
p = arr;
printf("%p,%p\n", p, arr);
return 0;
}
int arr(int n){
return n;
}
//00401499,00401499
================================================
FILE: articals/c/Demo/testPrintfScanf.c
================================================
#include <stdio.h>
int main(){
int a = 0, b =0;
int pn1 = printf("ok!\n"); // pn1 = 4
int pn2 = printf("ok!,%d,%d\n",a, b); // pn2 = 8
int sn1 = scanf("%d", &a, &b); // sn1 = 1
int sn2 = scanf("%d%d", &a, &b); // sn2 = 2
printf("pn1=%d, sn1=%d, pn2=%d, sn2=%d\n", pn1, sn1, pn2, sn2);
return 0;
}
================================================
FILE: articals/c/Demo/testR_d.c
================================================
#include <stdio.h>
extern unsigned int rand0(void);
extern void changeNext(unsigned int);
int main(void){
unsigned int seed;
while( scanf("%u", &seed) == 1 ){
changeNext(seed);
for (int i = 0; i < 5; ++i)
printf("%d\n", rand0());
}
return 0;
}
================================================
FILE: articals/c/Demo/testRand.c
================================================
#include <stdio.h>
static unsigned long int next = 1; //种子
unsigned int rand0(void){
next = next * 1103515245 + 12345;
return (unsigned int) (next / 65536) % 32768;
}
void changeNext(unsigned int seed){
next = seed;
}
================================================
FILE: articals/c/Demo/testRandom.c
================================================
#include <stdio.h>
#include <stdlib.h>
int roll_count = 0;
int roll_n_dice(int, int);
int rollem(int);
// int main(void){
// for (int i = 0; i < 10; ++i)
// {
// printf("%d\n", rollem(6));
// }
// return 0;
// }
//生成1 - 6 之间的随机数
int rollem(int sides){
int roll;
roll = rand() % sides + 1;
roll_count++;
return roll;
}
int roll_n_dice(int dice, int sides){
int d;
int total = 0;
if(sides < 2)
return -2;
if(sides < 1)
return -1;
for (d = 0; d < dice; ++d)
total += rollem(sides);
return total;
}
================================================
FILE: articals/c/Demo/testRecursion.c
================================================
#include <stdio.h>
int up_and_down(int);
int main(void){
up_and_down( 1 );
return 0;
}
int up_and_down(int n){
printf("%d, %p\n", n, &n);
if(n < 4)
up_and_down( n + 1 );
printf("%d, %p\n", n, &n);
}
// 1, 0060FF20
// 2, 0060FF00
// 3, 0060FEE0
// 4, 0060FEC0
// 4, 0060FEC0
// 3, 0060FEE0
// 2, 0060FF00
// 1, 0060FF20
================================================
FILE: articals/c/Demo/testReducto.c
================================================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 40
int main(int argc, char * argv[]){
FILE *in, *out;
int ch;
char name[N];
int count;
//检查命令行参数
if(argc < 2){
fprintf(stderr, "Usage:%s filename\n", argv[0]);
exit(EXIT_FAILURE);
}
//设置输入
if( (in = fopen(argv[1], "r")) == NULL){
fprintf(stderr, "I could not open this file\" %s \" \n ", argv[1]);
exit(EXIT_FAILURE);
}
//设置输出
strncpy(name, argv[1], N - 5);
name[N -5] = '\0';
strcat(name, ".red");
if( (out = fopen(name, "w")) == NULL ){
fprintf(stderr, "I could not open this file");
exit(3);
}
//拷贝
while( (ch = getc(in)) != EOF ){
if (count++ % 3 == 0)
putc(ch, out);
}
//关闭文件
if( fclose(in) != 0 || fclose(out) != 0 )
fprintf(stderr, "Error in closing files\n");
return 0;
}
================================================
FILE: articals/c/Demo/testScope.c
================================================
#include <stdio.h>
int main(void){
int i = 1 ;
// for (int i = 0; i < 10; ++i)
// {
// // int i = 6;
// printf("%d ", i);
// }
printf("block:%d\n", i);
return 0;
}
// 0 1 2 3 4 5 6 7 8 9 file:3
================================================
FILE: articals/c/Demo/testStrSort.c
================================================
#include <stdio.h>
#include <string.h>
#define SIZE 81 //字符串长度
#define LIM 20 //最大行数
#define HALT "" //读到空字符结束
void strSort(char * str [], int num); //排序函数
char * strGets(char * , int ); //输入字符串函数
int main(void){
char in[LIM][SIZE];
char * pstr[LIM];
int ct = 0, k = 0; //输入输出计数
while(ct < LIM && strGets(in[ct], SIZE) != NULL && in[ct][0] != '\0'){
pstr[ct] = in[ct];
ct++; //输入字符串
}
strSort(pstr, ct); //排序字符串
for(k = 0; k < ct; k++)
puts(pstr[k]); //输出字符串
return 0;
}
//选择排序
void strSort(char * str [], int num){
char *temp;
int top, seek;
for (top = 0; top < num-1; ++top)
{
for (seek = top + 1; seek < num; ++seek)
{
if( strcmp(str[top], str[seek]) > 0 )
temp = str[top];
str[top] = str[seek];
str[seek] = temp;
}
}
}
//自定义输入函数
char * strGets(char * str, int n){
char * ret_val;
int i = 0;
ret_val = fgets(str, n, stdin);
if(ret_val){
while(str[i] != '\n' && str[i] != '\0')
i++;
if(str[i] == '\n')
str[i] = '\0';
else
while(getchar() != '\n')
continue;
}
return ret_val;
}
================================================
FILE: articals/c/Demo/testSwap.c
================================================
#include <stdio.h>
void swap(int *, int *);
int main(void){
int a = 1, b =2;
swap(&a, &b);
printf("%d, %d\n", a, b);
return 0;
}
void swap(int *p, int * q){
int temp;
temp = *p;
*p = *q;
*q = temp;
}
================================================
FILE: articals/c/Demo/testToBinary.c
================================================
#include <stdio.h>
void to_binary(int);
int main(void){
int n;
scanf("%d", &n);
to_binary(n);
return 0;
}
void to_binary(int n){
int r;
r = n % 2;
if( n >= 2 )
to_binary( n/2 );
printf("%d", r==0 ? 0 : 1);
}
================================================
FILE: articals/c/Demo/words
================================================
Apple Banana
Orager HongKong
SHANGHAI wuhan
================================================
FILE: articals/c/Demo/words.red
================================================
AlBa
aroKgHGIun
================================================
FILE: articals/c/array.md
================================================
# 数组
### 一维数组
- 声明:和声明变量一样,但是数组不能直接赋值给它,可以初始化
```
int a[10];
```
- 初始化:声明并初始化并非赋值,不允许先声明后直接赋值
```
int a[10] = {1,2,3,4,5,6,6,7,7,8}; //可读可写
const int b[10] = = {1,2,3,4,5,6,6,7,7,8};//只读数组
```
- 未完全初始化:**不初始化,数组里面同变量一样全是垃圾值,如果部分初始化,其余值为0**
- 指定初始化器:C99增加的特性,可以指定某个位置的值
```
int a[10] = {1, 2, 3, [4] = 10, 5, 6, [9] = 20};
// 1, 2, 3, 0, 0, 10, 5, 6, 0, 20
//直接到指定的值给其赋值,中间未赋值的设置为0
```
- 赋值:通过循环依次给数组赋值,**不允许作为单元给数组赋值**
```
for(i=0; i<SIZE; i++)
a[i] = i;
```
- 边界:使用时要防止下标越界,gcc编译器允许编译,但是越界的值是垃圾值
> 编译器是相信程序员的,程序员最好声明数组时,用符号常量来表示数组大小
- 变长数组(VLA):c90不允许,c99允许,c11可选(不是必备)
```
int a = 5;
int a[a]; //a为变量,非常量
```
### 多维数组
- 申明:第一个是行,第二个是列
```
int a[3][4];
```
- 初始化:2种方式
```
int a[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
int a[3][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
// 3行4列
```
- 赋值:使用双重循环进行赋值
```
for(a = 0; a < ROWS; a++)
for( b = 0 ; b < COLS; b++)
arr[a][b] = a + b;
```
### 指针和数组
- 指针与数组的联系:数组名是数组首元素的地址,首地址加1是下一个元素的地址
```
int a[3]; // a == &a[0];
```
```
#include <stdio.h>
#define SIZE 10
int main(){
short a[SIZE] = {1,2,3,4,5,6,7,8,9,10};
double b[SIZE] = {1,2,3,4,5,6,7,8,9,10};
short i, *pa = a;
double *pb = b;
for (i = 0; i < 2; ++i)
{
printf("pa%d point %p\n", i, pa++);
}
for (i = 0; i < 2; ++i)
{
printf("pb%d point %p\n", i, pb++);
}
}
// pa0 point 0060FF00
// pa1 point 0060FF02
// pb0 point 0060FEB0
// pb1 point 0060FEB8
```
> 系统中,地址是按字节编址,而在c语言中指针加1是指增加一个存储单元,而不是固定的字节
```
a[SIZE]; // a+5 == &a[0+5] *(a+5) == a[5]
*a+1 ==> (*a)+1 ==> a[0]+1
*(a+1) ==> a[1]
```
### 数组的传递
- 函数原型与定义(数组):**通过传指针的方式,传数组**
```
int sum(int *, int); //通过指针传递(数组首地址)
int sum(int [], int); //等效1,提醒读者是数组
int sum(int * a, int n){}
int sum(int a[], int n){}
```
- 调用数组:**传递数组首地址**
```
sum(a, SIZE); //a为数组名, SZIE为数组大小
```
- 指针形参:传2个指针表示数组的开始和结束
```
int sum(int * start, int * end){
int sum = 0;
while(start < end){
sum += *start;
start++;
}
return sum;
}
```
**是否可以 sum += *start++ ? 答案是可以的**
```
#include <stdio.h>
#define SIZE 4
int sum(int * start, int * end){
int sum = 0;
while(start < end){
sum += *start++;
//分析 * ++(后缀) 同优先级右结合
//步骤分解 1. start先使用用 sum = sum + *start;
// 2. start = start + 1;
}
return sum;
}
int main(void){
int a[SIZE] = {1, 2 , 3, 4};
printf("%d", sum(a, a+SIZE));
return 0;
}
// 10 正确
```
** 另外两种形式又怎样呢? **
```
#include <stdio.h>
int a[2] = {1, 2};
int main(){
int *p1, *p2, *p3;
p1 = p2 = p3 = a;
printf("%d,%d,%d\n", *p1, *p1++, *p1);
//分析: 函数中参数的传递的顺序是从右往左传递
// 1.*p1 = 1 ==> no3 = 1
// 2.*p1++ ==> *p1 = 1 , p1 += 1 ==> no2 = 1
// 3.*p1 ==> a[1] ==> no3 = 2
printf("%d,%d,%d\n", *p2, (*p2)++, *p2);
// 1.*p2 = 1 ==> no3 = 1
// 2.(*p2)++ ==> *p2 = a[0], no2 = 1, a[0] = 2
// 3.*p2 = a[0] = 2 ==> no1 = 2;
printf("%d,%d,%d\n", *p3, *++p3, *p3);
// 1.*p3 = a[0] ==> no3 = 2
// 2.*++p3 ==> p3= p3+1 = &a[1] => no2 = *&a[1] = 2
// 3.*p3 = a[1] = 2 ==> no1 = 2
return 0;
}
// 2 1 1
// 2 1 1
// 2 2 2
```
> 函数中参数的传递的顺序是从右往左传递
### 指针操作
- 赋值
- 解引用
- 取地址
- 与整数相加
- 递增
- 与整数相减
- 递减
- 求差
- 比较
### 保护数组数据
- 原因:通过地址传的数组都是原始数据,可以改变
但有些时候不需要改变数组的原始数据
- 对形参使用const:不需要改变数组内容时,最好加上const
```
int sum(coust int *, int); //不能完全保护
int sum(const int [], int); //完全保护
```
- const其他内容:const比#define更加灵活,不应该把const数组作实参传递
```
const double PI = 3.14; //PI值不能被改变
const int a[SIZE] = {1,3,4}; //数组值不能被改变
const int *p = a; //将int类型声明为const,不能用p来改变a的值
//可以用数组改变其值,p也可以指向其他变量
int * const p = a; //常量指针不能指向其他地方
//可以修改指向的值
const int * const p = a; //不能指向其他地方,也不能通过p来改变变量的值
```
### 指针和多维数组
- 首地址之间的关系:a == a[0] == &a[0][0] 值虽然相同,但代表的含义不同
```
int a[3][4] = {
{1,2,3,4}
{5,6,7,8}
{7,8,9,1}
};
// a == &a[0][0]; 二维数组的首地址
// a[0] == &a[0][0]; 作为第一个数组名a[0]的首地址也为二维数组的首地址
// 即有 a == a[0] 值虽然相同,但代表的含义不同
```
- 解引用:
```
a &a[0][0] 二维数组首地址
a+2 &a[2] 二维数组第3个元素地址
*(a+2) &a[2][0] 二维数组第3个元素的首地址
*(a+2)+1 &a[2][1] 二维数组第3个元素的第二个元素的地址
*(*(a+2)+1) a[2][1] 二维数组第3个元素的第二个元素的值
```
- 地址步长:a + 1 跨一个数组元素, *a + 1 跨一个数元素
```
```
- 指向多维数组的指针:[]优先级高于*,所以一定要加()
```
int (*p) [2]; //声明含有两个int的数组
int a[2][3];
p = a; //指向二维数组a
int * p[2]; //声明一个含有两个指针的数组
```
- 指针兼容性:指针之间类型没有隐式转化,类型不匹配会编译出错
- 多维数组与函数:形参3种写法,指针式无法省略参数会引发歧义
```
int sum(int (*p)[COLS], int ROWS); //指针式
int sum(int a[][COLS], int ROWS); //数组式
int sum(int [][COLS], int ROWS); //数组略参式
```
- 变长数组:变长数组并不能改变大小,只是在初始化的时候可以用变量来初始化大小
```
int sum(int a[rows][cols], int rows, int cols); //无效顺序
int sum(int rows, int cols, int a[rows][cols]); //有效
int sum(int, int, int a[*][*]); //省略形参名
const int SIZE = 80;
int sum[SIZE]; c11允许 ,c90好像不允许
```
- 复合字面量:C99加入的 { 2,3,4,5,9 }
```
int a[2] = {10 ,20}; //初始化数组
(int [2]) {10, 20}; //初始化匿名数组,必须在创建的同时使用它
(int []) {10, 20}; //省略大小,编译器自动计算
int *p = (int []) {10, 20}; //首地址给指针p
sum( (int []){10, 20}, SIZE ); //用作实参
```
- 小训练:一维数组3种拷贝函数
```
#include <stdio.h>
#define N 5
void cp_arr(double [], const double [], int);
void cp_ptr(double [], const double *, int);
void cp_ptrs(double *, const double *, const double *);
void show_arr(double [], int);
int main(void){
double source[N] = {1, 2, 3, 4, 5};
double target1[N], target2[N], target3[N];
cp_arr(target1, source, N);
cp_ptr(target2, source, N);
cp_ptrs(target3, source, source+N);
show_arr(target1, N);
putchar('\n');
show_arr(target2, N);
putchar('\n');
show_arr(target3, N);
putchar('\n');
return 0;
}
void cp_arr(double target[], const double source[], int n){
int i;
for (i = 0; i < n; ++i)
{
target[i] = source[i];
}
}
void cp_ptr(double target[], const double *source, int n){
int i;
for (i = 0; i < n; ++i)
{
target[i] = *(source+i);
}
}
void cp_ptrs(double target[], const double *source_start, const double *source_end){
while(source_start < source_end){
*target = *source_start++;
target++;
}
}
void show_arr(double a[], int n){
int i;
for (i = 0; i < n; ++i)
{
printf("%.2lf ", a[i]);
}
}
```
- 小训练:二维数组处理函数
```
#include <stdio.h>
#define ROWS 3 //行数
#define COLS 5 //列数
void getArr(double [][COLS] ,int);
void averageGroup(double [], const double [][COLS], int);
double average(const double [][COLS], int);
double max(double [][COLS], int);
void swap(double *, double *);
void show(double [], int, double, double);
int main(void){
double arr[ROWS][COLS] = {0};
double aveGroup[ROWS] = {0}; //注意初始化
double ave = 0;
double m = 0;
getArr(arr, ROWS);
averageGroup(aveGroup, arr, ROWS);
ave = average(arr, ROWS);
m = max(arr, ROWS);
show(aveGroup, ROWS, ave, m);
return 0;
}
//给二维数组赋值
void getArr(double a[][COLS], int rows){
int i, j;
for (i = 0; i < rows; ++i)
for (j = 0; j < COLS; ++j)
scanf("%lf", &a[i][j]);
}
//求每行数据的平均值
void averageGroup(double b[], const double a[][COLS], int rows){
int i, j;
double sum = 0;
for (i = 0; i < rows; ++i){
for (j = 0; j < COLS; ++j)
sum += a[i][j];
b[i] = sum/rows;
}
}
//求所有数据的平均值
double average(const double a[][COLS], int rows){
int i, j;
double sum = 0;
for (i = 0; i < rows; ++i)
for (j = 0; j < COLS; ++j)
sum += a[i][j];
return sum/(COLS*rows);
}
//求二维数组的最大值
double max(double a[][COLS], int rows){
int i, j;
for (i = 0; i < rows; ++i)
{
for (j = 0; j < COLS; ++j)
if(a[i][j] > a[i][j+1])
swap(&a[i][j], &a[i][j+1]);
if(a[i][j] > a[i+1][j])
swap(&a[i][j], &a[i+1][j]);
}
return a[i][j];
}
//打印结果
void show(double a[], int size, double av, double m){
int i;
for(i = 0; i < size; i++){
printf("%.2lf ", a[i]);
}
printf("\naverage = %.2lf\n", av);
printf("max = %.2lf\n", m);
}
//交换两个变量值
void swap(double *p, double *q){
double temp = *p;
*p = *q;
*q = temp;
}
```
================================================
FILE: articals/c/data.md
================================================
# C与数据
### 11种数据类型
- 整型类:int,short(短整型),long(长整型),unsigned(无符号),char(字符整型)
- 浮点类:float(单精度),double(双精度)
- C90新增:signed(有符号),void(空)
- C99新增:*_Boo*l(布尔指)*,_Complex*(复数),*_Imaginary*(虚数)
### 存储单元
- 位:最小的存储单元,存储0或1
- 字节:常用存储单位,几乎所有机器有1字节等于8位,即1字节可以表示0-255之间的整数
- 字:自然存储单位:8位的微型计算机一字为8位,16,32位的为即一字为16位或32位
### 基本整型类型
1. int型:储存要占1个机器字长,16位机器,范围-32768 ~ 32767目前大多数机器32位,即占4个字节,存储数字范围为:-2147483648 ~ 2147483647
2. short型:存储小于等于int,-32768 ~ 32767
3. long型:储存大于等于int,-2147483648 ~ 2147483647
4. long long型:存储至少64位,即8个字节
5. unsigned型:无符号,只能存储正整数,能存储比signed更大的整数
6. 目前普遍设置:long long 64位8字节,long 32位4字节,short 16位2字节,int 16/32位 2/4字节
7. 常量:超出int范围,视为long,超出long范围,视为unsigned long,继续long long, unsigned long long
8. 用H/h作为short,用L/l作为long, 用LL/ll作为long long,用U/u作为unsigned,例如343H,3234L,35455LL,435345U,534546467ULL
9. char型:一个字节,-128 ~ 127,ASCII编码0~127,存储绰绰有余,C语言将字符常量视为int型非char型,是否有符号看编译器
10. 整型可以表示10,8,16进制,如32,032,0x32/0X32
### 基本浮点类型
- float:至少6位有效数字,取值至少10的-37到+37次方。通常浮点占32位,8位指数的值和符号,剩下的24位非指数的值和符号。
浮点最大:999999961690316250000000000000000000.000000
超过:*1.#INF00*
- double,至少13位有效数字。通常64位,剩下的32位给非指数部分。
- long double 更高的精确要求,至少比double精确
### 复数和虚数类型
- 复数:float_Complex,double_Complex,long double_Complex
- 虚数:float_Imaginary,double_Imaginary,long double_Imaginary
### 类型大小
sizeof()函数
sizeof(int),sizeof(char)等等……
### 问题
整型,浮点的上溢出,下溢出?
# 字符串与格式化输出输入
### 字符串 string
1. 字符串数组(变量)来存储,char name[40];
2. 输入scanf("%s",name) name是数组首地址
3. 输出printf("%s",name)
4. 数组大小sizeof(name) => 40,可以写成 sizeof name
5. 字符串长度 strlen(name) =>字符实际长度
6. 空字符结尾(\n)
### 预处理 define
- 格式 #define NAME 'shaosuo'
- 注意是简单的替换,没有其他操作
### 限定符 const
- 明示常量:limits.h float.h
- imits/h:包含*INT_MAX*, *INT_MIN* 等预处理常量数值h
- float.h:包含*FLT_MAX*, *FLT_MIN*..
### 输出函数 printf()
#### 转换格式
- %a/A 浮点,16进制,p计数
- %g/G 自动选择%f,%e
- %i 有符号10进制整数
- %u 无符号10进制整数
- %% 打印百分号
- %p 指针
- %o 无符号8进制
- %x 无符号16进制
#### 转换修饰符
- 标记:-(左对齐),+(添加符号),空格(空格覆盖正号),#(防止0被删除),0(0填充符号位)
- 宽度:数字(最小字段宽度)(用于字段对齐,右对齐)
- 精度:.数字
- 类型:h(short),hh(char),j,l,ll,L(long double),t,z
#### 返回值
```
#include <stdio.h>
int main(){
int a = 0, b =0;
int pn1 = printf("ok!\n"); // pn1 = 4
int pn2 = printf("ok!,%d,%d\n",a, b); // pn2 = 8
int sn1 = scanf("%d", &a, &b); // sn1 = 1
int sn2 = scanf("%d%d", &a, &b); // sn2 = 2
printf("pn1=%d, sn1=%d, pn2=%d, sn2=%d\n", pn1, sn1, pn2, sn2);
return 0;
}
```
- printf()返回正确按照格式变量个数,即打印字符的数
- scanf()返回正确按照指定格式接收的变量个数
# 运算符表达式和语句
### 基本运算符
- 算数:(),+(取正),-(取负),+,-,*,/,%(取模),=(赋值)
- sizeof:如果对象是类型,必须加括号,是变量可以不加,返回字节大小
- %取模运算符:如13%5=3,只能用于整数,不能用于浮点数
- 递增(减)运算符++(--):前缀与后缀区别,**i++ => 先使用 i,再递增,++ i => 先递增 i,再使用**
### 类型自动转换
- 普遍:**较小类型转换为较大类型**
- 运算时:两个值被分别两种;类型的更高级别
- 高低:long double,double,float,unsigned long long,long long,unsigned long, long,unsigned int,int(int和long大小可能相同
)
- 参数传递时,char,short转换成int,float转化成double
- **赋值语句可能导致类型的升级和降级**
### 类型强制转化
- 格式:(double)a = (double)1 + (double) 1;
- 显示使用类型转化比较好,避免不必要的错误
# 控制语句
### 循环
- 关系运算符,表达式:<,<=,==,>=,>,!=
- 真假:**非0 即为真**
- 注意:**= 赋值,== 比较**
- 优先级关系:x > y + 2 => x = ( y + 2 )
- while语句:非计数循环
```
#include <stdio.h>
int main(){
char a[27] = "abcdefghijklmnopqrstuvwxyz";
int i = 0;
while( i++ < 26){
printf("%c\n", a[i-1]); //前面+1 ,-1即为真实元素
}
return 0;
}
```
- for语句:计数循环
- 逗号运算符:结果为右边的值
- 入口,出口条件:while,do while
- 嵌套循环
```
#include <stdio.h>
int main(){
char lets[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i, j;
for (i = 0; i < 6; i++)
{
for (j = 0; j <= i; j++)
{
printf("%c", lets[i*(i+1)/2+j]);
}
printf("\n");
}
return 0;
}
```
- 示例:倒序打印(test47.c)
```
#include <stdio.h>
#include <string.h>
#define MAX_LEN 255
int main(){
char a[MAX_LEN];
scanf("%s", a);
int len = strlen(a);
while(len-- > 0){
printf("%c", a[len]);
}
return 0;
}
```
- 示例:冒泡排序(test43.c)
```
void bb(int a[]){
int i, j;
for (i = 0; i < LEN -1; ++i)
{
for (j = 0; j < LEN - i - 1; ++j)
{
if(a[j] < a[j+1])
{
swap(&a[j], &a[j+1]);
}
}
}
}
```
### 分支与跳转
- 选择语句 if……:**执行或者跳过这条语句**
- 双选语句 if ……else:**在两条语句中进行选择**
```
if(n == 0)
s = 1;
else
s = -1;
```
- 字符输入输出函数:getchar(),putchar(),它们是#include中的**预处理,不是真正的函数**
```
ch = getchar(); //scanf("%c", &ch);
putchar(ch); //printf("%c", ch);
```
- ctype.h系列的字符函数:**使用时别忘记头文件**
函数名 | 作用
---|---
isalnum() | 字母或数组
isalpha() | 字母
isblank() | 空白符
isdigit() | 数字
islower() | 小写字母
isupper() | 大写字母
isxdigit()| 16进制字母
tolower() | 返回小写字母
toupper() | 返回大写字母
- 多重选择if …… (else if) …… else:在多条语句中选择,**完全等价与if else多重嵌套模式**
```
if (score <= 60)
score = 6;
else if(score <= 70 )
score = 7;
else if(score <= 80)
score = 8;
else
score = 10;
```
- 逻辑运算符:&&(与), ||(或),!(非)
- 替代iso664.h:and,or,not
- 优先级:**!与递增运算符一样,&&大于||**
- 条件运算符: ?:
```
max = a > b ? a : b;
```
- 配对:else 与最近的 if 配对
- 循环辅助continue:程序循环到一部分,可以跳过剩余部分,进行下一轮循环
- 循环辅助break:程序循环到一部,直接跳出该层循环,进入下一阶段
- 多重选择switch ……break:可用来替代ifelse,使用break跳出,不往下继续执行
```
switch (整型表达式)
{
case 常量1:
语句
case 常量2:
语句
default:
语句
}
```
- 多重case标签
- 跳转语句goto:避免使用goto
- **注意:“==” 不要写成“=”,不要忘记打印结果**
```
#include <stdio.h>
int main(){
char ch, pre;
int n = 0;
while( (ch = getchar()) != '#' ){
if(pre == 'e' && ch == 'i') //切记
n++;
pre = ch;
}
printf("%d\n", n); //切记
return 0;
}
```
- 综合训练:**注意,getchar连续输入要去掉\n,菜单要过滤字符,退出写在循环条件中**
```
#include <stdio.h>
int main(){
char choice;
float fweight = 0, sweight = 0, tweight = 0;
float fcharge = 0, scharge = 0, tcharge = 0;
float weight, price, charge, orderCharge, orderWeight, account, extCharge, pay;
printf("enter a, b, c chooce your goods, q is quit:\n");
while ( (choice = getchar()) != 'q' )
{
if('\n' == choice)
continue;
if( choice == 'a' || choice == 'b' || choice == 'c' )
{
switch (choice)
{
case 'a':
price = 2.05;
printf("please enter want to buy yangli weight:\n");
scanf("%f", &weight); ;
fweight += weight;
fcharge += fweight * price;
printf("%.2f\n", fweight);
break;
case 'b':
price = 1.15;
printf("please enter want to buy taincai weight:\n");
scanf("%f", &weight);
sweight += weight;
scharge += sweight * price;
printf("%.2f\n", sweight);
break;
case 'c':
price = 1.09;
printf("please enter want to buy hulubo weight:\n");
scanf("%f", &weight);
tweight += weight;
tcharge += tweight * price;
printf("%.2f\n", tweight);
break;
default: ;
}
}
else
{
printf("pleae enter 'a', 'b', 'c' !\n");
}
printf("enter a, b, c chooce your goods, q is quit:\n");
}
orderWeight = fweight + sweight + tweight;
orderCharge = fcharge + scharge + tcharge;
account = orderCharge > 100 ? orderCharge * 0.05 : 0;
if( orderWeight <= 5 )
extCharge = 6.5;
else if( orderWeight <= 20)
extCharge = 14;
else
extCharge = 14 + (orderWeight-14) * 0.5;
pay = orderCharge + extCharge - account;
printf("******************* order ******************\n");
printf("*name-------price------weight-------charge*\n");
printf("*yang-------$2.05--------%9.2f---------$%9.2f*\n", fweight, fcharge);
printf("*tian-------$1.15--------%9.2f---------$%9.2f*\n", sweight, scharge);
printf("*hulobo-----$1.09--------%9.2f---------$%9.2f*\n", tweight, tcharge);
printf("totalWeight:%.2f, orderCharge:$%.2f", orderWeight, orderCharge);
printf("account:$%.2f, extCharge:$%.2f, pay:$%.2f\n", account, extCharge, pay);
printf("*************************************************\n");
return 0;
}
```
### 友好的交互
- 缓冲区:字符被收集存储的临时存储区(是否有无缓冲输入取决于系统)正常的都是有缓冲输入
```
graph LR
typeHI!-->|无缓冲区程序立即使用| HI!
typeHI!-->|缓冲区| HI!
```
- 结束键盘输入:文件,流,键盘输入
```
#include <stdio.h>
int main(){
char ch;
while( (ch =getchar()) != '#')
{
putchar(ch);
}
}
```
**使用的#字符可能会被我们用到,使用#退出并不一定起作用**
**c语言把输入输出设备,视为文件,stdin流表示键盘输入,stdout流表示显示输出**
**使用文件的形式来结束键盘的输入**
- 文件结尾:Ctrl+Z(曾经操作系统),存储文件大小信息,**EOF(C语言)**
```
#define EOF -1 //stdio.h定义的
```
```
while( (ch =getchar()) != EOF)
```
- - **getchar()返回int,可能会报信息,但不影响putchar()输出字符**
- - **正确的使用是找到操作系统,文件终止符识别方案,大多数是Ctrl+D,有些是Ctrl+Z**
- - **EOF不要加字符的‘’**
- 重定向和文件:把stdin流重新赋给文件,主要问题与操作系统有关
```
testFileIO < words // UNIX与DOS 输入重定向
testFileIO > mywords //输出重定向 DOS Ctrl+Z结束,UNIX Ctrl+D结束
testFileIO < words > mywords //组合重定向
```
**不能读多个文件,也不能写多个文件,空格不是必须的,写入的会把之前的覆盖掉**
- 友好的用户界面
**丢弃换行符两种方式比较**
```
if (ch == '\n') //当输入的字符为换行符时,直接跳入下一轮循环
continue;
```
```
while( getchar() != '\n' ) //只要输入的字符不为换行符进入下一轮循环
continue;
```
***问题来了?为什么用第二种不用第一种?***
- 混合字符数字输入:
**1.验证输入正确性2.丢弃换行符**
```
if(2 != scanf("%d%d", &a, &b))
break;
```
- 输入验证:
**事先预测可能输入,检测和处理**
```
while( scanf("%ld", &n) == 1 && n > 0 ) //验证正整数
```
- 模块化编程:**用单独的函数,验证输入和管理显示**
```
#include <stdio.h>
void count();
int get_int();
char get_first();
char get_choice();
int main(){
char choice;
count();
while( (choice = get_choice()) != 'q' ){
switch (choice){
case 'a':
printf("buy low, sell high\n");
break;
case 'b':
printf("\a\n");
break;
case 'c':
count();
break;
default:
printf("error!!!\n");
break;
}
}
return 0;
}
//计数
void count(){
int n, i;
printf("Count how far?\n");
n = get_int();
for (int i = 0; i <= n; ++i)
{
printf("%d\n", i);
}
while( getchar() != '\n' )
continue;
}
//异常处理
int get_int(){
int n;
char ch;
while( scanf("%d", &n) != 1 ){
while( getchar() != '\n')
putchar(ch);
printf("is not a integer!!!\n");
}
return n;
}
//过滤换行符
char get_first(){
char choice;
choice = getchar();
while( getchar() != '\n' )
continue;
return choice;
}
//删选合适的字符
char get_choice(){
char choice;
printf("please enter a, b, c\n");
choice = get_first();
while( (choice < 'a' || choice > 'c') && choice != 'q'){
printf("please enter correct code!!\n");
choice = get_first();
}
return choice;
}
```
- 实战例子(test57.c):统计文件字符数
```
#include <stdio.h>
#include <ctype.h>
int main(){
char ch;
int count = 0;
while( (ch = getchar()) != EOF )
{
if(isblank(ch) || ch == '\n')
continue;
count++;
}
printf("count : %d\n", count);
return 0;
}
```
- 实战例子(test61.c):二分查找找1-100中的数
```
#include <stdio.h>
int main(){
int ran, lower = 1, upper = 100, i = 0;
int smart = (lower + upper) / 2;
printf("please enter 1 ~ 100 a integer:");
scanf("%d", &ran);
while( ran != smart){
if(ran < smart)
upper = smart;
else
lower = smart;
i++;
printf("though %d times = %d\n", i, smart);
smart = (lower + upper) / 2;
}
printf("though %d times = %d\n", i+1, smart);
return 0;
}
```
================================================
FILE: articals/c/fileIO.md
================================================
# 文件输入输出
### 文件通信
- 重定向:books > bklist 可能会把不必要的东西输出到文件
- 文件:一系列连续的字节,文本模式,二进制模式
- 文件模式:所有文件内容都以二进制形式存储
- 文本文件:最初使用二进制编码的字符表示文本
- 二进制文件:二进制值代表机器语言代码或数值数据或图片或音乐编码
- 不同操作系统处理不同 MS-DOS读文件\r\n-->\n写文件\n-->\r\n
- I/O级别:底层I/O使用操作系统标准I/O,标准高级I/O使用stdio.h头文件的定义的(通用)
- 标准文件:C打开3个文件,标准输入(键盘),标准输出,标准准错误输出(显示器)
### 标准I/O
- 好处:可移植性强,专门函数简化了操作,输入输出优势缓冲的
- 演示:
```
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[]){
int ch; //读取文件,存储每个字符的地方
FILE *fp; //文件指针
unsigned long count = 0;
if(argc != 2){
printf("Usage: %s filename \n", argv[0]);
}
if( (fp = fopen(argv[1], "r")) == NULL ){
printf("can't open %s\n", argv[1]);
exit(EXIT_FAILURE);
}
while( (ch = getc(fp)) != EOF ){
putc(ch, stdout);
count++;
}
fclose(fp);
printf("File %s has %lu characters\n", argv[1], count);
return 0;
}
```
- 检查命令行参数:exit()关闭文件并结束程序(0或EXIT_SUCCESS结束成功,EXIT _FALLURE结束失败)
- fopen函数:打开文件,成功打开后返回文件指针(FILE*)
```
FILE * fp = fopen("words", "r");
```
模式 | 含义
---|---
r | 读模式
w | 写模式(文件长度截0,可以创建新文件)
a | 写模式(添加字符,可以创建新文件)
r+ | 更新模式(读写)
w+ | 更新模式(读写,截断,创新)
a+ | 更新模式(读写,添加,创新)
*b | 二进制文件用法同上
- getc和putc函数:与getchar,putchar类似
```
ch = getchar(); ch = getc(fp); //文件输入
ch = putchar(); ch = putc(fpout) //文件输出
```
- 文件结尾:避免读到空文件,使用入口循环
```
while( (ch = getc(fp)) != EOF) { putc(fpout); }
```
- fclose函数:关闭指定的文件,必要刷新缓冲取区
```
if (fclose(fp) != 0 ) //成功放回0,否则返回EOF
printf("error in closing file %s\n", argv[1]);
```
- 指向标准文件的指针
标准文件 | 文件指针 | 设备
---|---|---
标准输入 | stdin | 键盘
标准输出 | stdou | 显示器
标准错误 | stder | 显示器
### 文件压缩程序
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 40
int main(int argc, char * argv[]){
FILE *in, *out;
int ch;
char name[N];
int count;
//检查命令行参数
if(argc < 2){
fprintf(stderr, "Usage:%s filename\n", argv[0]);
exit(EXIT_FAILURE);
}
//设置输入
if( (in = fopen(argv[1], "r")) == NULL){
fprintf(stderr, "I could not open this file\" %s \" \n ", argv[1]);
exit(EXIT_FAILURE);
}
//设置输出
strncpy(name, argv[1], N - 5);
name[N -5] = '\0';
strcat(name, ".red");
if( (out = fopen(name, "w")) == NULL ){
fprintf(stderr, "I could not open this file");
exit(3);
}
//拷贝
while( (ch = getc(in)) != EOF ){
if (count++ % 3 == 0)
putc(ch, out);
}
//关闭文件
if( fclose(in) != 0 || fclose(out) != 0 )
fprintf(stderr, "Error in closing files\n");
return 0;
}
```
### 文件I/O
- fprinf和fscanf函数:与printf和scanf类似,区别在于,前面需要第一个参数待处理的文件。
```
fprintf(fp, "%s\n", words);
fscanf(fp, "%s\n", words);
```
- fgets和fputs函数:
```
fgets(buf, LEN, fp); // buf char型数组的名称,fp指针
fputs(buf, fp);
```
### 随机访问
- fseek() ftell()函数:文件看成数组,fseek返回int.ftell返回long
```
fseek(fp, 0L, SEEK_END); //定位到文件末尾
// 1)FILE指针,指向待查找的文件
// 2)偏移量,从起始点开始要移动的距离,正负0
// 3)模式,SEEK_SET文件开始, SEEK_CUR当前位置,SEEK_END文件末尾
// 正常返回0,c出现错误返回-1
ftell(fp) //返回当前位置
```
- 二进制模式和文本模式:
- - UNIX只有一种文件格式,不需要特殊转换,MS-DOS很多编辑器都是用ctrl+z来标记文件结尾的二进制文件和文本文件模式的另一个不同的地方,
- - MS_DOS用户\r\n来标识文件结尾,c程序会把\r\n看做成\n,对于ftell()返回值把\r\n当作一个字节来计数
- 可移植性:
- - 二进制模式中,实现不必支持SEEK_END模式,因此无法保证程序的可移植性,更好的办法是一个一个字节读取整个文件
- - 文本模式中,只有使用fseek才能保证其相应的行为
- fgetpos函数,fsetpos函数:新增的定位函数,突破long的限制
```
int fgetpos(FILE * restrict stream, fpos_t * restrict pos); // 成功返回0,失败返回非0
// 把fpos_t的值放在pos指向的位置
int fsetpos(FILE * stream, const fpos_t * pos); //成功返回0,失败返回非0
// 使用fpos_t设置文件指针指向该值指向的位置
```
### 标准IO机理
```
//第一步:调用fopen打开文件
//1)自动打开3个标准文件
//2)打开文件
//3)打开一个或者两个缓冲区以及其文件缓冲的数据结构
//4)返回一个指向该结构的指针
FILE * fp = fopen("words", "a+");
//第二步:调用stdio.h中的输入函数
//1)文件的数据块被拷贝至缓冲区
//2)设置缓冲区大小,设置fp所指向结构中的值(流中当前位置和拷贝进缓冲区的字节数)
```
### 其他标准IO函数
函数 | 作用
---|---
int ungetc(int, FILE*) | c指定的字符放回输入流
int fflush(FILE*) | 刷新缓冲区
int setcbuf(FILE*,char *, int, size_t) |创建一个供io替换的缓冲区
size_t fread() | 二进制out
size_t fwirte() | 二进制in
- size_t fwrite函数:返回sizeof运算后的类型
```
size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb, FILE * restrict fp);
// ptr 待写入的地址,size数据块的大小, nmemb带写入数据块的数量,fp待写入的文件
char buffer[256];
fwrite(buffer, 256, 1, fp);
double earnings[10];
fwrite(earings, sizeof(double), 10, fp);
```
- size_t fread函数:返回sizeof运算后的类型
```
size_t fwrite(void * restrict ptr, size_t size, size_t nmemb, FILE * restrict fp);
// ptr 待读取文件数据在内存中的地址,size数据块的大小, nmemb带写入数据块的数量,fp待读取的文件
char buffer[256];
fwrite(buffer, 256, 1, fp);
double earnings[10];
fwrite(earings, sizeof(double), 10, fp);
```
================================================
FILE: articals/c/function.md
================================================
# 函数
### 复习函数
- 什么是函数:完成特定任务的独立程序代码单元
- 函数的作用:省去重复多于代码,提高代码可读性,方便修改
- 函数的构成:
- - 函数原型:声明函数,告诉编译器函数的类型
- - 函数调用:使用函数
- - 函数定义:实现函数
```
int fun(char s); //申明函数
fun('a'); //调用函数
int fun(char s){
return s;
} //实现函数
```
- 函数形参:局部变量,内部私有,每个变量要求声明类型
```
void show(int, int); //也是合法的
```
- 函数实参:实参是具体的值, 会赋值给形参
- 返回值:测试函数的程序称为驱动程序,return语句会终止函数并把控制交给主调函数
- 无参数:注意加void
```
void show(void);
```
### 递归
- 定义:C允许函数调用自己,这种调用称为递归
- 演示:
```
#include <stdio.h>
int up_and_down(int);
int main(void){
up_and_down(1);
return 0;
}
int up_and_down(int n){
printf("%d, %p\n", n, &n);
if(n < 4)
up_and_down(n+1);
printf("%d, %p\n", n, &n);
}
// 1, 0060FF20
// 2, 0060FF00
// 3, 0060FEE0
// 4, 0060FEC0
// 4, 0060FEC0
// 3, 0060FEE0
// 2, 0060FF00
// 1, 0060FF20
```
- 原理:
- - 每次调用都有自己的变量,变量都是n但值不同
- - 每次调用完之后都会返回一次,逐级返回
- - 调用之前的顺序执行,调用之后的倒序返回
- - 没有拷贝函数代码,可以代替循环,可以被i循环代替
- - 必须包含让递归停止的语句
- 尾递归:递归调用置于函数的末尾,相当于循环,能使用选择循环,莫使用递归(速度,内存优势)
- 递归和倒序计算
- 整数化二进制
-
```
void to_binary(int n){
int r;
r = n % 2;
if( n >= 2 )
to_binary( n/2 );
printf("%d", r==0 ? 0 : 1);
}
```
- 递归优缺点:**为很多程序提供了简单的解决方案,但效率和消耗不令人满意**
### 多文件编译
- 预处理和申明函数放在头文件中
- 使用命令编译(linux)
```
gcc file1.c file2.c //一起编译
gcc file1.c file2.o
```
### 指针
- 本质:值为内存地址的变量
- 作用:存储变量的地址
- 取地址符&:得到变量的地址 &a 表示a的地址
- 解引用符*:找到存储在地址中的值 *&a ==> a
- 用%p打印地址
- 声明与赋值:严格区分开
```
int * pi; //声明int型指针
pi = &a; //给指针赋值
int *pi = &a; //上面两步合并成一步
b = *pi; //获取pi所指向地址中存储变量的值并赋值给b
```
- 使用指针在函数间通信:函数传值无法真正的改变实参的值,传地址可以改变实参的值。
- 交换两个整数值:
```
#include <stdio.h>
void swap(int *, int *);
int main(void){
int a = 1, b =2;
swap(&a, &b);
printf("%d, %d\n", a, b);
return 0;
}
void swap(int *p, int *q){
int temp;
temp = *p;
*p = *q;
*q = temp;
}
```
- 小训练1:10进制转任何进制
```
void to_base_n(int x, int n){
int r;
r = x%n;
if(x >= n)
to_base_n(x/n, n);
printf("%d", r );
}
```
- 小训练2:Fibonacci递归与非递归
```
#include <stdio.h>
int fibonacciRec(int); //递归
int fibonacci(int); //非递归
int main(void){
int n;
scanf("%d", &n);
printf("%d\n", fibonacciRec(n) );
printf("%d\n", fibonacci(n) );
return 0;
}
int fibonacciRec(int n){
if(n == 1 || n == 2)
return 1;
else
return fibonacciRec(n-1) + fibonacciRec(n-2);
}
int fibonacci(int n){
int i, fib1 = 1, fib2 = 1;
if( n == 1 || n == 2)
return 1;
for(i = 3 ; i <= n; i++){
fib2 = fib1 + fib2;
fib1 = fib2 - fib1;
}
return fib2;
}
```
================================================
FILE: articals/c/memory.md
================================================
# 内存管理
### 存储类别
- 对象(object):被存储的值占有一定的物理内存
> 此对象非面向对象中的对象
- 访问(access):声明变量来访问对象,也可以通过其他方式指定对象
```
int entity = 3; //声明变量访问
int * pt = &entity; //指针访问
int rank[10]; //数组访问
```
- 作用域(scope):
- - 块作用域:使用的局部变量(包含形参)都有块作用域 ,C99扩展了声明
- - 函数作用域:仅用于goto,延伸整个函数
- - 函数原型作用域:从形参定义到原型结束,形参名并不重要,仅变长数组需要
- - 文件作用域:定义在函数外面,从该定义至文件末尾均可见(全局变量)
```
double blocky(double a){
double b;
for(int c=0; c<10; c++){ ... }
} //a, b, c 都具备块作用域
```
- 链接(linkage):
- - 外部链接:全局作用域,在多个文件中使用的且具有文件作用域
- - 内部链接:文件作用域,在一个文件使用且具有文件作用域
- - 无链接:局部作用域,具有块,函数,原型作用域
```
static:
int giants = 5; //文件作用,外部
static int dodgers = 3; //文件作用,内部
```
- 存储期(storage duration):对象在内存中保留的时间
- - 静态存储期:执行期间一直存在,文件作用域变量具有静态存储期
- - 线程存储期:用于并发设计,从申明至线程结束
- - 自动存储期:块作用域变量通常具备自动存储期
- - 动态分配存储期:
- 存储类别:5种
存储类别 | 存储期 | 作用域 | 链接 | 声明
---|---|---|---|---
自动 | 自动 | 块 | 无 | 块内
寄存器 | 自动 | 块 | 无 | 块内 使用register
静态外部链接 | 静态 | 文件 | 外部 | 函数外
静态内部链接 | 静态 | 文件 | 内部 | 函数外 使用static
静态无链接 | 静态 | 文件 | 无 | 块内 使用static
- 自动变量:
- - 使用auto显示声明(不同于c++中auto)
- - 内层变量于外层同名:暂时隐藏外层变量,等运行完后回到原来作用域、
```
#include <stdio.h>
int main(void){
int i = 3;
for (int i = 0; i < 10; ++i)
printf("%d ", i);
printf("file:%d\n", i);
return 0;
}
// 0 1 2 3 4 5 6 7 8 9 file:3
```
- - 初始化:自动变量不会初始化除非显示初始化,未初始化会造成不可预期的异常
- 寄存器变量:存储在cpu中,处理速度更快的自动变量
- 静态内部链接变量:只能用于同一文件的函数中
```
static int a = 0;
int main(){}
```
- 静态外部链接变量:外部变量(external variable)
- - 使用其他文件的变量必须再次声明,函数内则可以不必声明
```
int a; //定义外部变量,给全局
extern char coal; //声明使用其他文件外部变量
int main(){
extern char coal; //再次声明变量,可以省略
char coal; //定义的自动变量,隐藏了外部变量
}
```
- - 初始化:可以显示初始化,也可以自动初始化为0,只能用常量表达式初始化
- - 使用:函数内使用时,可以声明加extern,也可以不申明
- - 定义和申明:**extern表明声明的变量定义在别处**
```
int tern = 1; //定义并初始化
extern int tern; //此文件声明,也可以不申明
extern int a; //必须有其他文件定义过a
extern int b = 0; //错误,extern只能申明不能初始化
```
存储类别说明符:auto, register,static,extern,_ Thread_local,typedef
存储类别与函数:外部函数(默认), 静态函数, 内联函数(C99)
```
double a(); //外部函数,其他文件可以使用
static double beta(); //静态函数,此文件使用
extern double c(); //内联函数,其他文件定义的函数
```
> 存储类别:按需使用
### 随机数函数和静态变量
```
#include <stdio.h>
static unsigned long int next = 1; //种子
unsigned int rand0(void){
next = next * 1103515245 + 12345;
return (unsigned int) (next / 65536) % 32768;
}
void changeNext(unsigned int seed){
next = seed;
}
```
### 掷色子
```
#include <stdio.h>
#include <stdlib.h>
int roll_count = 0;
int roll_n_dice(int, int);
int rollem(int);
// int main(void){
// for (int i = 0; i < 10; ++i)
// {
// printf("%d\n", rollem(6));
// }
// return 0;
// }
//生成1 - 6 之间的随机数
int rollem(int sides){
int roll;
roll = rand() % sides + 1;
roll_count++;
return roll;
}
int roll_n_dice(int dice, int sides){
int d;
int total = 0;
if(sides < 2)
return -2;
if(sides < 1)
return -1;
for (d = 0; d < dice; ++d)
total += rollem(sides);
return total;
}
```
```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "testRandom.c"
int main(void){
int dice, roll;
int sides, status;
srand((unsigned int) time(0));
printf("enter a number of sides:\n");
while(scanf("%d", &sides) == 1 && sides > 0){
printf("how many dice\n");
//检查输入部分
if(status = scanf("%d", &dice) != 1){
if(status == EOF) //检查是否有文件终止符
break;
else{
while(getchar() != '\n') //去掉换行符
continue;
continue;
}
}
//开始计算骰子总和
roll = roll_n_dice(dice, sides);
//打印结果
printf("total %d , using %d times, %d-sides\n", roll, dice, sides);
}
printf("function called : %d\n", roll_count);
return 0;
}
```
### 分配内存
- malloc与free函数:可以申请所需内存
```
#include <stdlib.h> //使用时声明
double *p;
p = (double *) malloc(30 * sizeof(double)); //申请内存块给指针
// p为内存的首地址,可以作为数组名使用,比变长数组更灵活
free(p); //回收内存,配套使用,如果不使用会造成内存泄露,即耗尽
//malloc 可能分配不到内存,放回空指针
if( p == NULL )
exit(EXIT_FALLURE);
```
- calloc与free函数:和malloc略有区别
```
double * p;
p = (double *) calloc(30 , sizeof(double)); //把块所有位置设置为0
free(p);
```
- 存储类别和动态内存分配:自动对象,静态对象,动态对象存储在不同区域
### 类型限定符
- 恒常性:const关键字申明的对象不能,赋值,递增或者递减来修改
- - 指针和形参中申明const
```
const float * p; //指向float类型的const值
float const * p; //同上
float * const p; //常量指针,不能指向其他值
const float * const p; //前面2个的结合
int sum(const int * p, const int p[]) //两个形参意义相同,表示数组数据不能更改
```
> const 放在*左边表示指针指的对象是const,放在*右边表示指针是const
- - 对全局使用const:避免数据被更改,2种策略
```
// 外部变量,给其他地方声明
const int a = 1; //file1.c
extern const int a; //file2.c
// 使用头文件
static const int a = 1; //file.h
#include "file.h" //file.c
```
- 易变形:volatile 涉及编译器(寄存器)的优化,const和volitile同时使用时顺序不重要
- 新增:restrict(c99表明指针是唯一访问,并初始的方式), _Atomic(c11并发程序中要用到的)
- 新位置:c99加入
```
int sum( int * const a, int * restrict b); //旧式
int sum( int a[const], int b[restrict]); //新式
```
- 小训练:动态分配字符(待调bug)
```
#include <stdio.h>
#include <stdlib.h>
#define SIZE 20
int get_n(){
int words;
if(scanf("%d", &words) == 1 && words > 0)
return words;
else
printf("enter error!!!\n");
}
void show(char * a[], int n){
int i = 0;
while( i++ < n ){
puts(a[i-1]);
}
}
int main(void){
int words, i = 0, j = 0;
char ch;
printf("how many words do you wish to enter:");
words = get_n(); //处理输入的单词数
// char * q [5] = (char (*) [5])malloc( SIZE * 5 * sizeof(char) );
//动态创建
printf("enter %d words:", words);
while( (ch = getchar()) != '\n' ){
if(ch == ' ')
{
char * p = (char *)malloc( i * sizeof(char) );
q[j] = p;
free( p );
j++;
i = 0;
continue;
}
i++;
}
show(q, words);
free( q );
return 0;
}
```
================================================
FILE: articals/c/string.md
================================================
# 字符串
### 表示字符串和字符串IO
```c
#define MSG = "hello world!";
char a[MAX] = "hello world!";
char * p = "hello world!";
puts(MSG);
puts(a);
puts(p);
```
### 定义字符串
- 字符串字面量:双引号括起来的内容,编译器会自动加入\n,双引号之间紧邻或者空格看作相连的
```c
char * a = "hello " "world!"; // hello world!
```
函数中使用字符串,只存储一次,被视为指向该字符串位置的指针
```c
printf("%s, %p, %c\n", "hello", "world", *"ok"); // hello,0X000000999,o
```
- 字符串数组:和字符数组区别,两种初始化方式
```c
char a[40] = "sadasfsdfgsdgfdgfdhfdh"; //简易初始化
char a[40] = {'a','b','c'...'g', '\n'} //标准初始化
char a[] = "dsfsdfsdfdsfsdfsdf"; //编译器自动计算长度
const char * a = "sdsafsdfsdfsdfsfdf"; //同上
//定长初始化中未被初始化的部分填充'\0'
```
- 数组形式与指针形式区别
- - 数组形式的a == &a[0] 只能作为常量,不能进行a++等操作,指针形式a 是可以进行a ++的
- - 指针对数据类型匹配很高,指向常量的指针需要被声明为常量const char * p = "abc";
- - 意味着不能用p改变数据的值,但可以改变p的位置
- - 初始化数组把静态存储区的字符串拷贝给数组,初始化指针只是把字符串的地址给指针
- 字符串与数组
```c
//相当于字符的二维数组
char f[3][4] = {{"ab"},{"cd"},{"e"}}; // ab\0, cd\0, e\0\0
//相当于3个字符串指针
const char * p[3] = {{"ab"},{"cd"},{"e"}}; // ab\0, cd\0, e\0 自动获取大小
```
- 字符串与指针:指针拷贝也只拷贝地址,没有拷贝整个字符串
### 字符串输入
- 分配空间:用显示声明来输入,否则会丢失数据
```c
char *name; scanf("%s", name); //不好
char name[SIZE]; scanf("%s", name); //可以的
```
- gets()函数:已废弃,并不知道字符串有多长,输入字符过长导致缓冲区溢出,可能导致其他数据被擦除
```c
#include <stdio.h>
int main(void){
char name[10];
gets(name);
puts(name);
return 0;
}
//gcc 编译没报任何消息
//fgdfgdfgdfgfdgfdg
//fgdfgdfgdfgfdgfdg
```
> 实际情况:大多数编译器仍支持
- fgets()函数:可以替代gets(),可扩展,可以从文件输入,保留换行符,需要手动设置为空字符
- - 读一行:读到换行或者读到n个字符,最终打印的n-1个字符
```c
#include <stdio.h>
int main(void){
char a[10];
fgets(a, 7, stdin); //读了dsfdsf个字符+'\0'
fputs(a, stdout); //输出dsfdsf\0 没有+'\n'
return 0;
}
//dsfdsfsdgfdgdffdg
//dsfdsf
```
- - 连续读取,fgets可以存储换行符,读完一段,继续读剩下的,可以直接读到文件尾部
```c
#include <stdio.h>
#define N 10
int main(void){
char word[N];
while( fgets(word, N, stdin) != NULL && word[0] != '\n' ){
fputs(word, stdout);
}
return 0;
}
```
- - 每行只读一定数量的字符,并丢弃了换行符
```c
#include <stdio.h>
#define N 10
int main(){
char word[N];
int i;
while( fgets(word, N, stdin) != NULL && word[0] != '\n'){
i = 0;
while(word[i] != '\n' && word[i] != '\0')
i++; //不是换行符或者空字符跳过
if(word[i] == '\n')
word[i] = '\0'; //遇到换行符,转空字符
else
while(getchar() != '\n') //读到空字符,丢弃剩余
continue;
fputs(word, stdout);
}
return 0;
}
```
> 空字符于空指针:空字符('\0')与空指针(NULL)都可以用0表示,但空字符是字符型(1字节),空指针是指针型(4字节)
- gets_s()函数:c11新增,可扩展,只从标准输入中输入,丢弃换行符,输入太长时更安全
- s_gets()函数:fgets()变体,遇到换行符设为空,遇到空丢弃其余字符
- scanf()函数:可指定宽度,但遇空格即终止,只能用于输入单词
### 字符串输出
- puts()函数:使用字符串地址作参数,自动添加换行符
- fputs()函数:用于文件输出,不添加换行符,遇fgets()配对使用
- printf()函数:不自动加换行符,打印多个字符更简单
### 自定义输入输出
### 字符串函数
(类型)函数名 | 参数 | 作用
---|---|---
int strlen | char * | 统计字符串长度
char * strcat | char *, char * | 把第二个字符串拼接在第一个上
char * strncat | char *, char *, int | 把第二个字符串指定长度添加到第一个字符串上
int strcmp | char *, char * | 比较两个字符串,相同返回0,二大于1返回正,否则返回负
int strncmp | char *, char *, int | 限定比较的字符串长度
char * strcpy | char *, char * | 把第二个拷贝到第一个
char * strcpy | char *, char * int | 限制拷贝的字符串长度
void sprintf | char *, 格式化, name | 将printf的内容存储在一个字符串中
### 字符串排序
- 示例
```c
#include <stdio.h>
#include <string.h>
#define SIZE 81 //字符串长度
#define LIM 20 //最大行数
#define HALT "" //读到空字符结束
void strSort(char * str [], int num); //排序函数
char * strGets(char * , int ); //输入字符串函数
int main(void){
char in[LIM][SIZE];
char * pstr[LIM];
int ct = 0, k = 0; //输入输出计数
while(ct < LIM && strGets(in[ct], SIZE) != NULL && in[ct][0] != '\0'){
pstr[ct] = in[ct];
ct++; //输入字符串
}
strSort(pstr, ct); //排序字符串
for(k = 0; k < ct; k++)
puts(pstr[k]); //输出字符串
return 0;
}
//选择排序
void strSort(char * str [], int num){
char *temp;
int top, seek;
for (top = 0; top < num-1; ++top)
{
for (seek = top + 1; seek < num; ++seek)
{
if( strcmp(str[top], str[seek]) > 0 )
temp = str[top];
str[top] = str[seek];
str[seek] = temp;
}
}
}
//自定义输入函数
char * strGets(char * str, int n){
char * ret_val;
int i = 0;
ret_val = fgets(str, n, stdin);
if(ret_val){
while(str[i] != '\n' && str[i] != '\0')
i++;
if(str[i] == '\n')
str[i] = '\0';
else
while(getchar() != '\n')
continue;
}
return ret_val;
}
```
- 排序单位是指针:排序的是指针而不是字符串本身
- 选择排序算法
```c
//伪代码
for n = 首元素 to n=倒数第2个元素
找出剩余元素中的最大元素,并将其放在第n个元素
//C代码
for(top = 0; top < n - 1; top++)
for(seek = top + 1; seek < n; seek++)
if(a[top] > a[seek])
swap(&a[top], &a[seek]);
```
### 命令行参数:int argc, char *argv[]
```c
int main(int argc, char *argv[])
{
argc // 命令行字符串数量
argv // 字符串数组指针 argv[n] 表示第n个字符串的地址
}
```
```c
#include <stdio.h>
int main(int argc, char * argv[]){
int i = argc;
printf("%d\n", argc);
while( i-- > 1 )
puts(argv[i]);
}
// --i情况 (没想到argc = 4) (- -)
// test86 see you later 0 1 2 3
// 1) (i = 4- 1 = 3, i > 0) -> a[3]
// 2) (i = 3- 1 = 2, i > 0) -> a[2]
// i--情况
// 1) (i = 4 > 0, i = 3 - 1 = 2) -> a[3]
// 2) (i = 3 > 0, i = 2 - 1 = 2) -> a[2]
// 3) (i = 2 > 0, i = 1 - 1 = 1) -> a[1]
```
### 字符串转数字
- 小训练:逆转字符串
```c
void reStr(char * a, int n){
int i = 0;
char b[n];
while(i++ < n)
b[i] = a[i-1];
i = 0;
while(n-- >= 0){
a[i] = b[n];
i++;
}
}
```
- 小训练:命令行输出
```c
#include <stdio.h>
#include <ctype.h>
#define N 10
void pf(char * , int);
void toUpper(char * , int);
void toLower(char * , int);
int main(int argc, char * argv[]){
char a[N];
switch (argv[1][1]){
case 'p': pf(a, N); break;
case 'u': toUpper(a, N); break;
case 'l': toLower(a, N); break;
default : puts("enter error!"); break;
}
return 0;
}
//原样输出
void pf(char * a, int n){
while( fgets(a, n, stdin) != NULL && a[0] != '\n'){
fputs(a, stdout);
}
}
//输出大写
void toLower(char * a, int n){
int i;
while( fgets(a, n, stdin) != NULL && a[0] != '\n'){
i = 0;
while(i++ < n-1){ // i=0<9 i=1 a[0], i=1<9 i=2 a[1] ---> i=8<9 i=9 a[8]
if(isupper(a[i-1]))
a[i-1] = tolower(a[i-1]);
}
fputs(a, stdout);
}
}
//输出小写
void toUpper(char * a, int n){
int i;
while( fgets(a, n, stdin) != NULL && a[0] != '\n'){
i = 0;
while(i++ < n-1){
if(islower(a[i-1]))
a[i-1] = toupper(a[i-1]);
}
fputs(a, stdout);
}
}
```
================================================
FILE: articals/c++/class.md
================================================
# 类(7.14)
> 基本思想:数据抽象,封装。数据抽象是一种依赖于接口于实现分离式编程技术
### 抽象数据类型
- 设计类
- 改进类
- 定义成员函数
- 引入this
- 引入const成员函数
- 类作用域和成员函数
- 外部定义成员函数
- 定义返回this对象的函数
- 定义非成员函数
- 构造函数:特殊的成员函数控制对象的初始化,只要对象被构建就会执行构造函数
```
1)没有返回类型,含有一个参数列表和函数体
2)可以包含多个构造函数,但构造函数之间必须是重载的
3)构造函数不能声明成const,创建const对象时,直到构造函数完成才能获得常量属性
4)没有构造函数会执行默认初始化,通过一个特殊的构造函数来初始化对象,无须任何实参
5)执行顺序,存在类内初始值,用其初始化,否则默认构造函数初始化
6)只有当不存在任何构造函数的情况下,编译器才会帮我们创建默认构造函数,否则不会
7)包含内置类型或复合类型的成员可能产生未定义的值
8)类中包含其他类型成员且这个成员的类型没有默认构造函数,也不会生成默认构造函数
```
- 拷贝赋值析构
### 访问控制、封装
- 公有与私有
- 友元:允许一个非成员函数访问类的私有成员,关键词friend,声明可以出现在类内部的任何地方
- - 1)将非成员函数reset(),声明为example类的友元,可以访问私有成员
```
//
class example; // 这里必须对类 example 做前向声明,否则下面的函数声明将报错
void reset(example &e);
class example
{
public:
friend void reset(class example &e);
private:
int n;
};
// 该函数定义必须放在类 example 的后面,否则无法解析变量n
void reset(example &e)
{
e.n = 0;
}
```
- - 2)将man设为woman的友元类,这样man对象的任何成员函数都可以访问woman的私有成员
```
class woman; // 前向声明
class man
{
public:
void disp(woman &w);
void reset(woman &w);
};
class woman
{
public:
friend class man; //
private:
string name;
};
void man::disp(woman &w)
{
cout << w.name << endl;
}
void man::reset(woman &w)
{
w.name.clear();
}
```
- - 3)将一个类的成员函数声明为一个另一个类的友元函数,从而来访问私有函数
```
[cpp] view plain copy print?
class woman; // 前向声明
class man
{
public:
void disp(woman &w);
void reset(woman &w);
};
class woman
{
public:
friend void man::disp(woman &w);
private:
string name;
};
void man::disp(woman &w)
{
cout << w.name << endl;
}
// man的reset()成员函数不是woman类的友元函数,因此不能访问其私有成员
/*
void man::reset(woman &w)
{
w.name.clear();
}
*/
```
- - **友元定义与声明存在依赖关系,一定要弄清楚顺序**
> 原则:对象的声明里的其他对象必须放在该对象之前声明,对象的定义里的对象必须放在该对象之前定义
- - 重载函数:多个重载函数的版本,那么可以将其中的一个或者几个设为某个类的友元。其他的函数不受此设置的影响
- - 友元必须具备public权限,否则不能调用
### 类的特性
- 类成员
- 返回*this函数
- 类类型
- 友元2
### 类作用域
- 名字查找
- 构造函数2
- 委托构造函数
- 默认构造函数
- 隐式类转换
- 聚合类
### 静态成员
- 声明静态成员
- 使用静态成员
- 定义静态函数
- 内类初始化
- 特殊作用
================================================
FILE: articals/c++/function.md
================================================
# 函数
### 函数基础:兼容C
- 典型的函数:返回类型,函数名字,0个或多个形参组成的列表,函数体
- 函数调用:实参初始化形参,控制权转移给被调函数
- 实参与形参:实参是形参的初始值,实参类型必须与形参类型匹配,至少可以隐式的转换成形参
- 形参列表:可以为空,但不能省略,为了与c兼容加上void,任何形参都不能同名,而且外层作用域的局部变量不能与形参同名
- 返回类型:大多数类型都能作为函数返回类型,void是特殊的返回类型,表示不返回任何值,不能是数组或者函数类型,但可以是它们的指针
- 局部对象:名字有作用域,对象有生命周期,形参和函数体内部都变量都是局部变量,仅在函数作用域可见
- 自动对象:只存在于块执行期间的对象称自动对象
- 局部静态对象:将局部变量定义成static类型,在执行路径第一次经过对象定义语句初始化,程序结束后被销毁
- 函数声明:函数只能定义一次,但可以声明多次,用分号代替函数体,也称函数原型,记得在头文件中声明
- 分离式编译:编译和链接多个文件
### 参数传递:传值和引用
- 传值参数:初始值拷贝给对象,对变量改变不会影响初始值,指针形参可以间接访问他所指向的对象,可以修改对象的值
- 传引用参数:通过引用形参,允许函数改变一个或者多个实参的值
```
#include <iostream>
void swap(int &a, int &b){
int tem = a;
a = b;
b = tem;
} //传引用
int main(void){
int c = 1, d = 2;
swap(c, d);
std:: cout << c << d << std:: endl;
} // 结果:21
```
- - 使用引用可以避免拷贝,拷贝大的类型或者容器对象比较低效
- - 使用引用参数返回额外的信息,一个函数只能返回一个值,引用给我提供了解决方法
```
//返回指定字符串中指定字符的位置和出现的次数
string::size_type find_char(const string &s, char c, string::size_type &occurs){
auto ret = s.size();
occurs = 0;
for(decltype(re))
}
```
- - const形参和实参:同样的规则应用到形参上
```
int b;
void reset(int &a); reset(b);//参数为引用,只能用int对象,不能用字面量,需要转换的对象,const int
void reset(int *a); reset(&b);//参数为指针,只能用int *对象
//允许字面量初始常量引用
```
- - 尽量用常量引用:把函数不会改变的形参定义称引用是一种比较常见的错误,给调用者误导这是可以修改的,同时限制了实参的类型
- - 数组形参:不允许拷贝数组,只能通过指针形式来传值
```
//比c语言多一样
void print(const int *);
void print(const int []);
void print(const int [10]); //期望的长度,不一定
//通过显示传递参数来表示数组的大小
void print(const int [], size_t );
//数组引用形参
void print(int (&arr)[10]);
//多维数组
void print(int (*mat)[10], int row);
void print(int mat[][10], int row);
```
### 返回类型
### 函数重载
### 特殊用途
- 默认实参:有一种形参很多次调用都赋予相同的值,这样的值称为默认实参
```
//默认实参的形式,直接在函数中给形参赋值,一旦某一形参被赋予了值,后面所有形参都必须赋默认值
string screen(sz ht = 24, sz wid = 80, char background = '');
//使用默认实参,默认实参按位置解析,负责填写缺少的尾部实参,只能是尾部的
//调用必须赋值赋满所有的形参
window = screen(); ==> 24, 80, ''
window = screen(66); ==> 66, 80, ''
window = screen(66, 256); ==> 66, 256, ''
window = screen( , ,'a'); ==> 错误,只能省略尾部的,从第一位开始填写的
//通常声明放头文件中,函数只声明一次,可以声明多次但形参不能重复赋值
//默认实参是可以初始化的,必须在函数之外进行
sz sw = 80;
string screen(sz ht = 24, sz wid = sw, char background = '');
```
- 内联函数:避免调用函数开销,在每个调用点内联的展开,优化规模较小,流程直接,频繁调用的函数
```
inline const string & shorterString(const string &s1, const string &s2){
return s1.size() <= s2.size() ? s1 : s2;
}
cout << shortrtString(a,b) << endl;
==> cout << s1.size() <= s2.size() ? s1 : s2 << endl; //内联的展开
```
- - 用函数的内联取代宏原因
```
1)宏代码最大的缺点容易出错
2)宏无法进行调试
3)宏无法操作类的私有成员
```
- - 函数内联的工作原理:将内联函数的返回值,形参,函数放入符号表,没有错误则将代码放入符号表,发现正确调用后直接替换调用语句
- - 优点:==具备宏的效率,增加了安全型,又可以自由的操作类的成员==,编译器可以根据上下文对代码进行深优化
- - 注意:
```
1)inline必须与函数定义放一起才算真正的内联(声明时没多大必要加inline)
2)定义在类内部的函数会自动变成内联函数
3)定义有必要放头文件,这样每个文件都可以访问到,否则每个源文件都有从新定义它
4)慎用内联,函数只有10行甚至更小时才用内联,内联会增加代码的长度,复杂的代码增加更多的执行开销和内存消耗
5)内联的声明只是请求,是否使用取决于编译器,太长的函数编译器可能拒绝使用内联
```
- constexpr:能用于常量表达式的函数,函数返回类型和形参必须都是字面量类型,函数有且只有一个return语句
```
constexpr int new_st(){ return 42; } //常量函数
constexpr int foo = new_st(); //常量表达式
//被隐式的指定为内联函数
//允许函数返回值并非常量
```
### 函数匹配
### 函数指针
================================================
FILE: articals/c++/oop.md
================================================
# 面向对象程序设计(7.16)
### oop
- 概述
- 动态绑定
### 基类派生类
- 定义基类
```
class A{};
```
- 定义派生类
```
class B : public A{};
```
- 类型转换与继承
### 虚函数
- 虚函数:实现多态,实现运行期绑定
```
#include <iostream>
using namespace std;
class A
{
public:
virtual void foo()
{
cout<<"A::foo() is called"<<endl;
}
};
class B:public A
{
public:
void foo()
{
cout<<"B::foo() is called"<<endl;
}
};
class C:public A{
void foo(){
cout << "C::foo() is calles" << endl;
}
};
int main(void)
{
A *a = new B();
a->foo(); // 在这里,a虽然是指向A的指针,但是被调用的函数(foo)却是B的!
a = new C();
a->foo();
return 0;
}
```
- 纯虚函数:方便实现多态性,具有存虚函数不能生成对象,必须由不同的派生类来实现它
```
virtual void foo() = 0;
```
### 抽象基类
### 继承与访问控制
- 三种权限:对于类中成员对外开放的属性
访问权限 | public | protect | private
---|---|---|---
对本类 | 可见 | 可见 | 可见
对子类 | 可见 | 可见 | 不可见
外部调用 | 可见 | 不可见 | 不可见
- 继承方式:子类对父类的访问权限控制
- 1)公有继承:直接继承不改变父类中的权限
- 2)保护继承:把父类中公有成员变换成保护成员
- 3)私有继承:把父类的公有成员和保护成员变为私有成员
```
#include <iostream>
using namespace std;
class A{
private:
void show(){ cout << "private:A" << endl; }
protected:
void show2(){ cout << "protected:A" << endl; }
public:
void show3(){ cout << "public:A" << endl; }
};
class B : public A{
};
class C : protected A{
};
class D : private A{
};
int main(void){
A a;
a.show(); //fail
a.show2(); //fail
a.show3(); //ok 只有公有成员外部才可以直接调用
// //公有继承:权限属性不变
B b;
b.show(); //fail
b.show2(); //fail
b.show3(); //ok
//保护继承:公有属性转保护属性
C c;
c.show(); //fail
c.show2(); //fail
c.show3(); //fail 保护属性
//私有继承:公有属性,保护继承转私有继承
D d;
d.show(); //fail
d.show2(); //fail 私有属性
d.show3(); //fail 私有属性
return 0;
}
```
### 继承类作用域
### 构造函数域拷贝控制
### 容器域继承
### 文本查询
================================================
FILE: articals/c++/reload.md
================================================
# 重载运算符
### 理论
- 来源:对于自定义的数据类型,需要和自带的运算符的相同功能的运算,实质是函数重载
- 语法:operator关键词
```
Complex operator+(Complex c2){
Complex c;
c.real = real + c2.real;
c.imag = imag + c2.imag;
return c;
}
```
- 参数数量:
- - 非成员函数:一元有一个运算符,二元有两个运算符,对于二元左侧传递给第一个参数,右侧传递给第二个参数
- - 成员函数:左侧运算对象绑定到this指针上,运算参数对象比运算符运算对象少一个
- 注意:
```
1)只能重载已有的运算符,不能发明新的运算符
2)部分运算符既是一元又是二元,只能从参数上来判断到底重载的那个运算符
3)优先级和结合率与内置运算符保持一致
4)不能被重载的运算符:作用域运算符::,成员运算符., 点乘运算符.*,条件运算符 :?
5)不应被重载的运算符:逻辑与或运算符和逗号运算符
6)需要有与内置运算符一一样的含义有重载==就应当有!=
7)应当与内置运算符的放回类型兼容
```
- 作为成员与非成员函数
```
准则:
1)赋值,下标,调用,成员访问运算符必须作为成员
2)复合赋值一般作为成员
3)改变对象状态的,或与类型密切相关的,递增,递减,解引用之类的一般作为成员
4)具有对称型的运算符可能转换任意一端的运算对象,算术,相等,关系和位运算等作为非成员
```
### 输入输出:必须是非成员函数
```
ostream &operator<<(ostream &os, const Sale_data &item){
os << item.isbn() << " " << item.units_sold << endl;
return os;
}
```
### 赋值
### 下标
### 递增递减
### 成员访问
### 函数调用
================================================
FILE: articals/c++/str_map_arr.md
================================================
# 字符串、向量、数组
### 名字空间
- 作用域操作符
```
std:: cout << i; //左侧的作用域中找出右侧的名字,头文件不应包含
```
- 使用using声明:最安全的方法
```
using namespace::name;
using std::cin; //使用cin时从std中获取
using namespace std; //对文件使用名字空间
```
### string库:可变长字符序列
- 头文件:#include <string>
- 定义初始化:直接初始化,拷贝初始化
```
string s1; //默认初始化
string s1(s2); //直接初始化
string s1 = s2; //拷贝初始化
string s1(n, 'c'); // 初始化成连续字符串
```
- 操作:
表示 | 作用
---|---
<< s | 输出
>> s | 输入
getline(is, s)| 读取一行给s
s.empty() | 判空
s.size() | 返回字符个数
s[n] | 返回第n个字符的引用
s1+s2 | 返回连接的结果
s1 = s2 | 用s2的副本代替s1
s1 == s2 | 字符完全一样相等,大小写敏感
- 读取string
```
string s;
cin >> s; //跳过空格,从第一个字符开始读取,读到下一个空格为止
cout << s << endl;
string s1;
while( cin >> s1 ){
cout << s1 << endl; //读到文件末尾
}
string s2;
while ( getline(cin, line) ){
cout << line << endl; // 读一整行
}
```
- empty和size
```
while( getline(cin , line) ){
if( !line.empty() )
if(line.size() > 80 )
cout << line << endl;
} //跳过空行,输出字符超过80的行
```
- 处理单个字符:使用继承c的库 ctpye.h ---> cctype
```
#incldue <cctype>
for (auto c : str) //使用基于范围的for语句
```
### vector库:对象的集合,所有对象都相同,类模板,每一个对象有一个与之对应的索引,被称为容器
> vector是模板.并非类型
- 头文件:#include <vector>
### 迭代器(7.19)
### 数组
# 表达式
### 成员访问运算符
### sizeof运算符
### 类型转换
### 优先级
# 语句
### 语句作用域
### 范围for语句:遍历容器和其他序列的所有元素
```
vector<int> v = {0,1,2,3,4,5,6,7,8,9};
//范围变量必须是引用型才能进行写操作
for (auto &r : v)
r *= 2; //v中每个元素的值翻倍
//等价于
for(auto beg = v.begin(), end = v.end(); beg != end; ++ beg)
auto &r = *beg;
r *= 2;
```
### 异常处理语句
- throw 表达式:主动抛出异常
```
if(a != b)
throw runtime_error("data ...");
```
- try……catch表达式:捕获处理异常
```
try {
……
}catch (runtime_error err) {
cout << err.what() << endl;
}
```
- 标准异常
header 1 | header 2
---|---
row 1 col 1 | row 1 col 2
row 2 col 1 | row 2 col 2
================================================
FILE: articals/c++/var.md
================================================
# 变量和基本类型
### 变量
### 复合类型:基于其他类型定义的类型
- 引用:为对象起的别名,已经存在的对象的另一个名字
```
int ival = 1024;
int &refVal = ival; //引用定义时必须被初始化
//引用定义时必须和初始值绑定在一起,无法再绑定其他值
//引用并非对象无法定义引用的引用
//引用只能绑定在对象上,不能绑定常量
//绑定时类型必须严格的匹配
```
- 指针:本身就是一个对象,允许赋值和拷贝
```
int ival = 42;
int *p = &ival; // 类型严格匹配
```
- - 指针的值:4种情况
```
//1)指向一个对象
//2)指向紧邻对象的下一个位置
//3)空指针,不指向任何对象
//4)无效指针其他值
```
- - 指针访问对象:使用解引用符,间接访问符
```
cout << *p << endl; //p为指向a的指针
```
- - 空指针:不指向任何对象
```
int *p = nullptr; //生成空指针
int *p = 0;
int *p = NULL; //预处理变量 include cstdlib
```
- - void*:特殊的指针,存任意对象的地址
```
double obj = 3.14, *pd = &obj;
void *p = &obj; //不能直接操作对象
p = pd; //指向同一个对象
```
- - 定义多个变量
```
int* p, q; //一个指针一个变量
int *p, *q; //两个指针
```
- - 指向指针的指针
```
int ival = 1024;
int *p = &ival;
int **pi = &p;
```
```
graph LR
pi[p的地址]-->p[ival的地]
p[ival的地址]-->ival[1024]
```
### const:限定对象不被改变
- 初始化和const:const的对象一旦创建就不能被改变,所以必须初始化
```
const int buff = 512; //编译时初始化
const int i = getSize(); //运行时初始化
//默认情况仅在文件内有效
//想要文件共享const,定义和声明都必须加extern
//如果其中一个没加会报错undefined reference to `a'
collect2.exe: error: ld returned 1 exit status
```
- const的引用:**对常量的引用,不能用作修改他所绑定的对象**
```
const int ci = 1024; //常量对象
const int &r1 = ci; //必须加const
r1 = 42; //错误,不允许改变值
int i = 1024; //非常量对象
const int &r1 = i; //允许
const int &r2 = 42; //允许
const int &r3 = r1 * 42; //允许
```
> 对常量的引用可能引用一个并非常量的对象,但不允许它修改对象的值
- const的指针:**常量指针必须初始化,不能修改指针的指向**
```
int a = 0;
int * const p = &a;
const b = 1024;
const int * const q = &b;
```
### 类型处理
### 结构
- 内存字节对齐原则:
- 1)第一个成员的地址为0,以后的每一个成员的地址,都要以该成员大小为整数倍地址来开始存储
- 2)结构体作为成员要从最大的元素地址的整数倍开始存储
- 3)结构体的总大小要是最大元素的整数倍,不然就要补齐
```
typedef struct bb
{
int id; //[0]....[3]
double weight; //[8].....[15] 原则1
float height; //[16]..[19],总长要为8的整数倍,补齐[20]...[23] 原则3
}BB;
//24
typedef struct aa
{
char name[2]; //[0],[1]
int id; //[4]...[7] 原则1
double score; //[8]....[15]
short grade; //[16],[17]
BB b; //[24]......[47] 原则2
}AA;
//48
struct stu
{
union{
char bj[5];
int bh[2];
} Class; //[0]....[5]
char xm[8]; //[8]....[16]
float cj; //[16]...[19]
}xc;
//20
```
================================================
FILE: articals/h5/0001.md
================================================
# 前言
最近在写移动端 H5 应用,遇到一个值得记录下来的点。现在从它的由来到实现,我们来聊一下移动端 1px,说 1px 不够准确,应该说成 1 **物理像素**。
通过阅读下面文章,你将会理解以下问题:
## 问题
- **为什么有 1px 这个问题?**
- **实现 1px 有哪些方法?这些方法分别有哪些优缺点?**
- **开源项目中使用的哪些解决方案?**
- **如何在项目中处理 1px 的相关问题?**
# 由来
## 基本概念
首先,我们要了解两个概念,一个是**像素(pixel)**可以简写为**px**,另外一个是**设备像素比(DPR)**
像素 :指在由一个数字序列表示的图像中的一个最小单元,单位是 px,不可再次分割了。
设备像素比(DPR): 设备像素比 = 设备像素 / 设备独立像素。
下面我来简单解释下几个概念
- CSS 像素 (虚拟像素):指的是 CSS 样式代码中使用的逻辑像素,在 CSS 规范中,长度单位可以分为两类,绝对单位以及相对单位。px 是一个相对单位,相对的是设备像素。
- 设备像素 (物理像素):指设备能控制显示的最小物理单位,意指显示器上一个个的点。从屏幕在工厂生产出的那天起,它上面设备像素点就固定不变了,和屏幕尺寸大小有关。
- 设备独立像素 (逻辑像素):可以认为是计算机坐标系统中得一个点,这个点代表一个可以由程序使用的虚拟像素(比如: CSS 像素),这个点是没有固定大小的,越小越清晰,然后由相关系统转换为物理像素。
**也就是说,当逻辑像素是 1pt 时,在 DPR 为 2 的 设备上显示为 2px 的物理像素**
## 参考数据
**各种类型的 iphone 手机屏幕设备的参数**

注:这里的缩放因子呢,就是 DRP 的值
**设计稿对比数据**

会有人好奇,为什么设计稿上显示是 750x1334 呢,这是因为设计稿是显示的**物理像素**
而我们 css 中的像素是**逻辑像素**应该为 375x 667,在编写代码时要将自定义宽度设置成 375px

那么此时设计稿上的 1px 宽度实际代表的 css 参数应该是 0.5px 对应物理像素 1px,那么怎么实现这个物理像素为 1px 呢
# 实践
**归根结底有两种方案,一种是利用 css 中的`transfrom:scaleY(0.5)`,另一种是设置 媒体查询根据不同 DPR 缩放**
## 解决方案一
### 原理
**利用 css 的 伪元素`::after` + `transfrom` 进行缩放**
**为什么用伪元素?**
因为伪元素`::after`或`::before`是独立于当前元素,可以单独对其缩放而不影响元素本身的缩放
> 伪元素大多数浏览器默认单引号也可以使用,和伪类一样形式,而且单引号兼容性(ie)更好些
### 实现
```html
<div class="cell border-1px"> cell <div>
<style>
.cell {
width: 100px;
height: 100px;
}
<!--全部边框-->
.border-1px:after {
content: '';
position: absolute;
box-sizing: border-box;
top: 0;
left: 0;
width: 200%;
height: 200%;
border: 1px solid #000;
border-radius: 4px;
-webkit-transform: scale(0.5);
transform: scale(0.5);
-webkit-transform-origin: top left;
}
<!--单边框,以上边框为例-->
.border-1px-top:before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
border-top: 1px solid red;
transform: scaleY(.5);
transform-origin: left top;
}
</style>
```
## 解决方案二(升级方案一)
### 原理
使用 less 对公共代码(方案一)封装,同时增加媒体查询分别对不同 DPR 的设备,进行不同的缩放
```less
.border(
@borderWidth: 1px;
@borderStyle: solid;
@borderColor: @lignt-gray-color;
@borderRadius: 0) {
position: relative;
&:before {
content: '';
position: absolute;
width: 98%;
height: 98%;
top: 0;
left: 0;
transform-origin: left top;
-webkit-transform-origin: left top;
box-sizing: border-box;
pointer-events: none;
}
@media (-webkit-min-device-pixel-ratio: 2) {
&:before {
width: 200%;
height: 200%;
-webkit-transform: scale(.5);
}
}
@media (-webkit-min-device-pixel-ratio: 2.5) {
&:before {
width: 250%;
height: 250%;
-webkit-transform: scale(.4);
}
}
@media (-webkit-min-device-pixel-ratio: 2.75) {
&:before {
width: 275%;
height: 275%;
-webkit-transform: scale(1 / 2.75);
}
}
@media (-webkit-min-device-pixel-ratio: 3) {
&:before {
width: 300%;
height: 300%;
transform: scale(1 / 3);
-webkit-transform: scale(1 / 3);
}
}
.border-radius(@borderRadius);
&:before {
border-width: @borderWidth;
border-style: @borderStyle;
border-color: @borderColor;
}
}
.border-all(
@borderWidth: 1px;
@borderStyle: solid;
@borderColor: @lignt-gray-color;
@borderRadius: 0) {
.border(@borderWidth; @borderStyle; @borderColor; @borderRadius);
}
```
## 其他方案:
- 使用图片:兼容性最好,灵活行最差,不能改变颜色、长度
- 使用 `viewport` 和 `rem`,`js` 动态改变 `viewport` 中 `scale` 缩放,缺点在于不适用于已有的项目,例如:使用 `vh` 和 `vw` 布局的
```html
<meta name="viewport" id="WebViewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
```
- 使用 css 渐变`linear-gradient`或者`box-shadow`
**上述 3 种方案均有致命缺陷暂不推荐使用**
## 兼容性
最后看一下兼容性如何,主要是伪元素、`transform:scale` 和`min-device-pixel-ratio` 这几个关键词的兼容性



## 开源库的解决方案
### vant 组件库
[跳去 github 查看相关代码](https://github.com/youzan/vant/blob/dev/src/style/mixins/hairline.less)
使用`less`写的
```less
.hairline-common() {
position: absolute;
box-sizing: border-box;
content: ' ';
pointer-events: none;
}
.hairline(@color: @border-color) {
.hairline-common();
top: -50%;
right: -50%;
bottom: -50%;
left: -50%;
border: 0 solid @color;
transform: scale(0.5);
}
```
也是采用第一种解决方案
### ant-design-mobile 组件库
[跳去 github 查看相关代码](https://github.com/ant-design/ant-design-mobile/blob/master/components/style/mixins/hairline.less)
```less
.scale-hairline-common(@color, @top, @right, @bottom, @left) {
content: '';
position: absolute;
background-color: @color;
display: block;
z-index: 1;
top: @top;
right: @right;
bottom: @bottom;
left: @left;
}
.hairline(@direction, @color: @border-color-base) when (@direction = 'top') {
border-top: 1PX solid @color;
html:not([data-scale]) & {
@media (min-resolution: 2dppx) {
border-top: none;
&::before {
.scale-hairline-common(@color, 0, auto, auto, 0);
width: 100%;
height: 1PX;
transform-origin: 50% 50%;
transform: scaleY(0.5);
@media (min-resolution: 3dppx) {
transform: scaleY(0.33);
}
}
}
}
}
.hairline(@direction, @color: @border-color-base) when (@direction = 'right') {
border-right: 1PX solid @color;
html:not([data-scale]) & {
@media (min-resolution: 2dppx) {
border-right: none;
&::after {
.scale-hairline-common(@color, 0, 0, auto, auto);
width: 1PX;
height: 100%;
background: @color;
transform-origin: 100% 50%;
transform: scaleX(0.5);
@media (min-resolution: 3dppx) {
transform: scaleX(0.33);
}
}
}
}
}
.hairline(@direction, @color: @border-color-base) when (@direction = 'bottom') {
border-bottom: 1PX solid @color;
html:not([data-scale]) & {
@media (min-resolution: 2dppx) {
border-bottom: none;
&::after {
.scale-hairline-common(@color, auto, auto, 0, 0);
width: 100%;
height: 1PX;
transform-origin: 50% 100%;
transform: scaleY(0.5);
@media (min-resolution: 3dppx) {
transform: scaleY(0.33);
}
}
}
}
}
.hairline(@direction, @color: @border-color-base) when (@direction = 'left') {
border-left: 1PX solid @color;
html:not([data-scale]) & {
@media (min-resolution: 2dppx) {
border-left: none;
&::before {
.scale-hairline-common(@color, 0, auto, auto, 0);
width: 1PX;
height: 100%;
transform-origin: 100% 50%;
transform: scaleX(0.5);
@media (min-resolution: 3dppx) {
transform: scaleX(0.33);
}
}
}
}
}
.hairline(@direction, @color: @border-color-base, @radius: 0) when (@direction = 'all') {
border: 1PX solid @color;
border-radius: @radius;
html:not([data-scale]) & {
@media (min-resolution: 2dppx) {
position: relative;
border: none;
&::before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 200%;
height: 200%;
border: 1PX solid @color;
border-radius: @radius * 2;
transform-origin: 0 0;
transform: scale(0.5);
box-sizing: border-box;
pointer-events: none;
// @media (min-resolution: 3dppx) {
// width: 300%;
// height: 300%;
// border-radius: @radius * 3;
// transform: scale(0.33);
// }
}
}
}
}
```
这个值得研究下,比 vant 和 第一种解决方案有点不同,主要在于处理了 DPR 为 2 和为 3 的两种情况,相比来说更加完善。
> 这里 PX 大写,为了防止插件将 px 转成 rem 等单位
# 总结
通过该文,你大概了解 1px 问题的来龙去脉了吧,也明白了如何解决相关问题,如果这票文章能解决你的疑问或者工作中问题,不妨点个赞收藏下。
由于技术水平有限,文章中如有错误地方,请在评论区指出,感谢!
接下我应该会关于**移动端 H5 布局问题和一些踩坑**进行一段学习工作总结,不妨点个关注。
[issue评论区](https://github.com/suoyuesmile/suo-blog/issues/40)
================================================
FILE: articals/h5/0002.md
================================================
# 前言
最近写第三个移动端 H5 的项目了,准备记录下自己在 H5 项目中的一些实践探索。移动端 H5 与 PC 端开发最大的区别之一,大概就是**响应式布局**问题。
那么下面我们来聊聊移动端响应式布局,了解他的来龙去脉,对现有的最佳解决方案探索。
## 问题
全文将围绕下面几个问题进行论述和展开:
- **写移动端 H5 相关页面,相比 PC 端有哪些值得注意的点?**
- **关于H5 响应式布局有哪些解决方案?**
- **什么是 rem?如何在项目中完美使用它?**
- **vh/vw 是最佳解决方案吗?它有什么优势和缺陷**
- **大型开源库里面常用解决方案是什么?**
- **怎样快速搭建一套移动端布局解决方案?**
# 由来
## 概念
#### 什么是 H5 技术?
H5 这个命名本身是一个很不讨巧的命名,咋一眼看上去认为 HTML5,或者第 5 级标题的标签,对一些造成一些不小的误解。
> 比如:我的一个某后端同事,谈论到 H5 很简单,HTML 之前我也学过一些,以后要是你请假,我来帮你写。
> 我是一脸蒙蔽,H5 === HTML?
再看看,搜索引擎中H5是什么?(引用来自谷歌词条第一页)

如此看来,将 H5 视作 HTML 的大有人在,而 H5 这个概念只在中国特有,所以对外国人来说他们也认为是 HTML, 所以,对于外国人和非这个领域的人来说,他们存在一样的误解。
目前的 H5 算是一个比较大的概念了,我认为的 H5 技术是**一系列移动端 web 前端技术的集合** 大致用一个韦恩图表示如下

我们这里只谈 web 前端中 H5 技术,H5 技术本身是用于**移动端的 web 网页**。由于App本身有个 “ webview ” 的容器,在容器里可以运行 web 前端相关代码,由此 H5 和原生 App 结合又衍生出来了 **Hybrid App 技术**。
#### Hybrid App 技术大致原理

这是我给公司同事普及 H5 知识绘制的图像。
# 实践
## 解决方案一:rem + pxToRem
### 概念
css 中用于计量的单位有两种,一种是**绝对单位**,另一种是**相对单位**
#### 绝对单位

对于绝对单位,一般来说常用的也就 `px`, 其他的可能打印需要用到
#### 相对单位

对于相对单位来说,`em` 和 `rem` 属于一对,`vw` 和 `vh` 属于一对。
前一对相对于**字体大小**,区别在于 `rem` 相对于**根字体**,对于我们控制整体的大小相对容易些,所以我们可以使用它来控制整个页面的缩放。
后一对,相对于视窗的大小,这个将在下一个节中发挥主要作用。
### 原理
1. 监听屏幕视窗的宽度,通过一定比例换算赋值给`html`的`font-size`。此时,根字体大小就会随屏幕宽度而变化。
2. 将 `px` 转换成 `rem`, 常规方案有两种,一种是利用`sass`/`less`中的自定义函数 `pxToRem`,写`px`时,利用`pxToRem`函数转换成 `rem`。另外一种是直接写`px`,编译过程利用插件全部转成`rem`。这样 dom 中元素的大小,就会随屏幕宽度变化而变化了。
### 实现
1. 动态更新根字体大小
```js
const MAX_FONT_SIZE = 420
// 定义最大的屏幕宽度
document.addEventListener('DOMContentLoaded', () => {
const html = document.querySelector('html')
let fontSize = window.innerWidth / 10
fontSize = fontSize > MAX_FONT_SIZE ? MAX_FONT_SIZE : fontSize
html.style.fontSize = fontSize + 'px'
})
```
2. `px` 转 `rem`
#### `pxToRem` 方案一
```scss
$rootFontSize: 375 / 10;
// 定义 px 转化为 rem 的函数
@function px2rem ($px) {
@return $px / $rootFontSize + rem;
}
.demo {
width: px2rem(100);
height: px2rem(100);
}
```
#### `pxToRem`方案二
`vue-cli3` 中配置 装 `postcss-pxtorem` 插件就可以了,其他平台大致差不多
```js
const autoprefixer = require('autoprefixer')
const pxtorem = require('postcss-pxtorem')
module.exports = {
// ...
css: {
sourceMap: true,
loaderOptions: {
postcss: {
plugins: [
autoprefixer(),
pxtorem({
rootValue: 37.5,
propList: ['*']
})
]
}
}
}
}
```
[点击快速配置 H5 项目工程](https://github.com/suoyuesmile/vue-h5-awsome)
继续探索[postcss-pxtorem](https://github.com/cuth/postcss-pxtorem/blob/master/index.js)插件源码,查看它实现的原理
```js
function createPxReplace (rootValue, unitPrecision, minPixelValue) {
return function (m, $1) {
if (!$1) return m;
var pixels = parseFloat($1);
if (pixels < minPixelValue) return m;
var fixedVal = toFixed((pixels / rootValue), unitPrecision);
return (fixedVal === 0) ? '0' : fixedVal + 'rem';
};
}
```
`px`变换成 `rem` 主要是这个函数,当然里面有很多可配置的参数, 核心原理和我们方案一差不多,方便在于,不需要每次写`px`都要加上一个函数,代码也清晰很多
> 是不是所有元素 `px` 都要转换成 `rem`呢?,那可不一定哦,border 中的 `px` 不应该转 rem,涉及到另外一个 1px 的问题,上一篇文章详细论述过,避免 px 转 rem,将 border 中的 px 大写成 PX/Px/pX
1px 适配问题请移至 [吃透移动端 1px](https://juejin.im/post/5df3053ce51d45583d425ada)
## 解决方案二:vh + vw
### 原理
**`vw` 相对于视窗宽度的单位,随宽度变化而变化。由此看来,方案一其实是方案二的一种 Hack, 通过使用监听实现了方案二的效果**
### 实现
与 rem 类似做法,直接使用 [postcss-px-to-viewport](https://github.com/evrone/postcss-px-to-viewport/blob/master/index.js) 插件进行配置, 配置方式也是和 [postcss-pxtorem](https://github.com/cuth/postcss-pxtorem/blob/master/index.js) 大同小异
我们看看插件的原理是不是也是一样的
```js
function createPxReplace(opts, viewportUnit, viewportSize) {
return function (m, $1) {
if (!$1) return m;
var pixels = parseFloat($1);
if (pixels <= opts.minPixelValue) return m;
var parsedVal = toFixed((pixels / viewportSize * 100), opts.unitPrecision);
return parsedVal === 0 ? '0' : parsedVal + viewportUnit;
};
}
```
**果然呢,连方法名、变量名、代码逻辑,都一摸一样哈哈哈,谁抄谁,我就不指出来啦 - -**
## 其他解决方案
| | 方案 | 缺陷
| ---------- | ------------ | ------------|
|1|百分比|高度无法百分比|
|2|媒体查询 + meta 中 viewport |不同设备宽度不同,缩放比无法完全确定|
|3|flex |还是无法解决宽度超出问题|
上面方案均存在致命缺陷,不推荐使用它完成移动端布局计算。
> flex 与 rem 结合使用更佳
## 兼容性
上述两种方案,**兼容性主要在于 rem,vh,vw 关键词上**

`rem`在移动端表现高达 100%,令人惊叹!


`vh vw` 表现惨不忍睹
**不得不说 `rem` 仍然是移动端 h5 布局的最佳方案**
## 开源库解决方案
### vant 组件库

vant 组件库中,默认采用 px 做计量单位,如果需要使用 rem,直接使用插件完美适配。
对于 vw 方案,vant 也是可以通过插件将 px 转成 vw,对于 vw 可能会存在一些坑点。
### ant-design-mobile 组件库
ant-design-mobile 组件库仍然使用 `px` 单位
```less
@hd: 1px; // 基本单位
// 字体尺寸
// ---
@font-size-icontext: 10 * @hd;
@font-size-caption-sm: 12 * @hd;
@font-size-base: 14 * @hd;
@font-size-subhead: 15 * @hd;
@font-size-caption: 16 * @hd;
@font-size-heading: 17 * @hd;
// 圆角
// ---
@radius-xs: 2 * @hd;
@radius-sm: 3 * @hd;
@radius-md: 5 * @hd;
@radius-lg: 7 * @hd;
@radius-circle: 50%;
// 边框尺寸
// ---
@border-width-sm: 1PX;
@border-width-md: 1PX;
@border-width-lg: 2 * @hd;
```
与 `vant` 组件一样,还是由开发者来决定到底用哪一种方案
这种把选择权交给开发者,算是一种开源库的最灵活的做法了。
# 总结
通过该文,你大概了解 H5 问题的来龙去脉了吧,也明白了如何解决移动端响应式布局问题,如果这票文章能解决你的疑问或者工作中问题,不妨点个赞收藏下。
由于技术水平有限,文章中如有错误地方,请在评论区指出,感谢!
上一篇文章 解决了 1px 问题,这篇文章解决了响应式布局问题,
接下我应该会继续研究下关于 H5 一些踩坑总结,之后应该回去研究下 vue 最新的源码再进行分享,想持续了解更多,不妨点个关注。
================================================
FILE: articals/h5/0003.md
================================================
# 前言
作为一个开发了多个 H5 项目的前端工程师,在开发过程中难免会遇到一些兼容性等**爬过坑**的问题。现在我将这些问题一一汇总一下,并在后面给出**坑产生的原理**,和**现阶段常规的填坑方案**。由此来做一个阶段性的总结。
> 常规操作哈,**点赞**后再观看呗!你的**点赞**就是我创作的动力之一!
# 问题
下面列举了我遇到的一些常规问题,如有遇到其他问题请在评论区补充,之后我也会实践后加以补充,感谢!(经常更新该文)
## 移动端 H5 相关问题汇总:
- **1px 问题**
- **响应式布局**
- **iOS 滑动不流畅**
- **iOS 上拉边界下拉出现白色空白**
- **页面件放大或缩小不确定性行为**
- **click 点击穿透与延迟**
- **软键盘弹出将页面顶起来、收起未回落问题**
- **iPhone X 底部栏适配问题**
- **保存页面为图片和二维码问题和解决方案**
- **微信公众号 H5 分享问题**
- **H5 调用 SDK 相关问题及解决方案**
- **H5 调试相关方案与策略**
## 移动端 H5 相关基础技术概览

# 原理与实践
之前两篇文章已经详细的论述了**1px** 问题与 **响应式布局**问题,并给出了原理和解决方案。
> 防止丢失,**点赞收藏**后跳转至快捷通道:[**1px**](https://juejin.im/entry/5df32ffd6fb9a016194afb5e)通道与[响应式布局](https://juejin.im/entry/5df613c3f265da33ca400e72)通道
接下来呢,我们看看其他问题的原理和解决方案吧。
> 以下解决方案,均经过我测试成功,健康安全,请放下食用。由于篇幅原因,某些非核心解决方案的实现细节暂未谈论,需要自行研究。
## iOS 滑动不流畅
### 表现
上下滑动页面会产生卡顿,手指离开页面,页面立即停止运动。整体表现就是滑动不流畅,没有滑动惯性。
### 产生原因
**为什么 iOS 的 webview 中 滑动不流畅,它是如何定义的?**
最终我在 `safari` 文档里面寻找到了答案(文档链接在参考资料项)。

原来在 iOS 5.0 以及之后的版本,滑动有定义有两个值 `auto` 和 `touch`,默认值为 `auto`。
```css
-webkit-overflow-scrolling: touch; /* 当手指从触摸屏上移开,会保持一段时间的滚动 */
-webkit-overflow-scrolling: auto; /* 当手指从触摸屏上移开,滚动会立即停止 */
```
### 解决方案
#### 1.在滚动容器上增加滚动 touch 方法
将`-webkit-overflow-scrolling` 值设置为 `touch`
```css
.wrapper {
-webkit-overflow-scrolling: touch;
}
```
> 设置滚动条隐藏: `.container ::-webkit-scrollbar {display: none;}`
可能会导致使用`position:fixed;` 固定定位的元素,随着页面一起滚动
#### 2.设置 overflow
设置外部 `overflow` 为 `hidden`,设置内容元素 `overflow` 为 `auto`。内部元素超出 body 即产生滚动,超出的部分 body 隐藏。
```css
body {
overflow-y: hidden;
}
.wrapper {
overflow-y: auto;
}
```
> 两者结合使用更佳!
## iOS 上拉边界下拉出现白色空白
### 表现
手指按住屏幕下拉,屏幕顶部会多出一块白色区域。手指按住屏幕上拉,底部多出一块白色区域。
### 产生原因
在 iOS 中,手指按住屏幕上下拖动,会触发 `touchmove` 事件。这个事件触发的对象是整个 `webview` 容器,容器自然会被拖动,剩下的部分会成空白。
### 解决方案
#### 1. 监听事件禁止滑动
移动端触摸事件有三个,分别定义为
```
1. touchstart :手指放在一个DOM元素上。
2. touchmove :手指拖曳一个DOM元素。
3. touchend :手指从一个DOM元素上移开。
```
显然我们需要控制的是 `touchmove` 事件,由此我在 W3C 文档中找到了这样一段话
> Note that the rate at which the user agent sends touchmove events is implementation-defined, and may depend on hardware capabilities and other implementation details.
> If the preventDefault method is called on the first touchmove event of an active touch point, it should prevent any default action caused by any touchmove event associated with the same active touch point, such as scrolling.
**`touchmove` 事件的速度是可以实现定义的,取决于硬件性能和其他实现细节**
**`preventDefault` 方法,阻止同一触点上所有默认行为,比如滚动。**
由此我们找到解决方案,通过监听 `touchmove`,让需要滑动的地方滑动,不需要滑动的地方禁止滑动。
> 值得注意的是我们要过滤掉具有滚动容器的元素。
实现如下:
```js
document.body.addEventListener('touchmove', function(e) {
if(e._isScroller) return;
// 阻止默认事件
e.preventDefault();
}, {
passive: false
});
```
#### 2. 滚动妥协填充空白,装饰成其他功能
在很多时候,我们可以不去解决这个问题,换一直思路。根据场景,**我们可以将下拉作为一个功能性的操作**。
**比如: 下拉后刷新页面**

## 页面放大或缩小不确定性行为
### 表现
双击或者双指张开手指页面元素,页面会放大或缩小。
### 产生原因
HTML 本身会产生放大或缩小的行为,比如在 PC 浏览器上,可以自由控制页面的放大缩小。但是在移动端,我们是不需要这个行为的。所以,我们需要禁止该不确定性行为,来提升用户体验。
### 原理与解决方案
HTML `meta` 元标签标准中有个 中 `viewport` 属性,用来控制页面的缩放,一般用于移动端。如下图 MDN 中介绍

移动端常规写法
```html
<meta name="viewport" content="width=device-width, initial-scale=1.0">
```
因此我们可以设置 `maximum-scale`、`minimum-scale` 与 `user-scalable=no` 用来避免这个问题
```html
<meta name=viewport
content="width=device-width, initial-scale=1.0, minimum-scale=1.0 maximum-scale=1.0, user-scalable=no">
```
## click 点击事件延时与穿透
### 表现
监听元素 `click` 事件,点击元素触发时间延迟约 `300ms`。
点击蒙层,蒙层消失后,下层元素点击触发。
### 产生原因
#### 为什么会产生 click 延时?
iOS 中的 safari,为了实现双击缩放操作,在单击 300ms 之后,如果未进行第二次点击,则执行 `click` 单击操作。也就是说来判断用户行为是否为双击产生的。但是,在 App 中,无论是否需要双击缩放这种行为,`click` 单击都会产生 300ms 延迟。
>
#### 为什么会产生 click 点击穿透?
双层元素叠加时,在上层元素上绑定 `touch` 事件,下层元素绑定 `click` 事件。由于 `click` 发生在 `touch` 之后,点击上层元素,元素消失,下层元素会触发 `click` 事件,由此产生了点击穿透的效果。
### 原理与解决方案
#### 解决方案一:使用 touchstart 替换 click
前面已经介绍了,移动设备不仅支持点击,还支持几个触摸事件。
那么我们现在基本思路就是用 `touch` 事件代替`click` 事件。
将 `click` 替换成 `touchstart` 不仅解决了 `click` 事件都延时问题,还解决了穿透问题。因为穿透问题是在 `touch` 和 `click` 混用时产生。
在原生中使用
```js
el.addEventListener("touchstart", () => { console.log("ok"); }, false);
```
在 vue 中使用
```html
<button @touchstart="handleTouchstart()">点击</button>
```
开源解决方案中,也是既提供了 `click` 事件,又提供了`touchstart` 事件。如 vant 中的 `button` 组件

**那么,是否可以将 `click` 事件全部替换成 `touchstart` 呢?为什么开源框架还会给出 `click` 事件呢?**
我们想象一种情景,同时需要点击和滑动的场景下。如果将 `click` 替换成 `touchstart` 会怎样?
> 事件触发顺序: `touchstart`, `touchmove`, `touchend`, `click`。
很容易想象,在我需要`touchmove`滑动时候,优先触发了`touchstart`的点击事件,是不是已经产生了冲突呢?
所以呢,在具有滚动的情况下,还是建议使用 `click` 处理。
在接下来的`fastclick`开源库中也做了如下处理。
针对 `touchstart` 和 `touchend`,截取了部分源码。
```js
// If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and:
// 1) the user does a fling scroll on the scrollable layer
// 2) the user stops the fling scroll with another tap
// then the event.target of the last 'touchend' event will be the element that was under the user's finger
// when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check
// is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42).
this.updateScrollParent(targetElement);
```
```js
// Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled
// and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42).
scrollParent = targetElement.fastClickScrollParent;
if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
return true;
}
```
主要目的就是,在使用 `touchstart` 合成 `click` 事件时,保证其不在滚动的父元素之下。
#### 解决方案二: 使用 fastclick 库
使用 `npm/yarn` 安装后使用
```js
import FastClick from 'fastclick';
FastClick.attach(document.body, options);
```
同样,使用`fastclick`库后,`click` 延时和穿透问题都没了
按照我的惯例,只要涉及开源库,那么我们一定要去了解它实现的原理。主要是将现有的原生事件集合封装合成一个兼容性较强的事件集合。
[fastclick源码](https://github.com/ftlabs/fastclick/blob/master/lib/fastclick.js) 核心代码不长, 1000 行不到。有兴趣可以了解一下!
## 软键盘将页面顶起来、收起未回落问题
### 表现
Android 手机中,点击 `input` 框时,键盘弹出,将页面顶起来,导致页面样式错乱。
移开焦点时,键盘收起,键盘区域空白,未回落。
### 产生原因
我们在app 布局中会有个固定的底部。安卓一些版本中,输入弹窗出来,会将解压 `absolute` 和 `fixed` 定位的元素。导致可视区域变小,布局错乱。
### 原理与解决方案
软键盘将页面顶起来的解决方案,主要是通过监听页面高度变化,强制恢复成弹出前的高度。
```js
// 记录原有的视口高度
const originalHeight = document.body.clientHeight || document.documentElement.clientHeight;
window.onresize = function(){
var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
if(resizeHeight < originalHeight ){
// 恢复内容区域高度
// const container = document.getElementById("container")
// 例如 container.style.height = originalHeight;
}
}
```
键盘不能回落问题出现在 iOS 12+ 和 wechat 6.7.4+ 中,而在微信 H5 开发中是比较常见的 Bug。
兼容原理,1.判断版本类型 2.更改滚动的可视区域
```js
const isWechat = window.navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i);
if (!isWechat) return;
const wechatVersion = wechatInfo[1];
const version = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
// 如果设备类型为iOS 12+ 和wechat 6.7.4+,恢复成原来的视口
if (+wechatVersion.replace(/\./g, '') >= 674 && +version[1] >= 12) {
window.scrollTo(0, Math.max(document.body.clientHeight, document.documentElement.clientHeight));
}
```
> `window.scrollTo(x-coord, y-coord)`,其中`window.scrollTo(0, clientHeight)`恢复成原来的视口
## iPhone X系列安全区域适配问题
### 表现
头部刘海两侧区域或者底部区域,出现刘海遮挡文字,或者呈现黑底或白底空白区域。
### 产生原因
iPhone X 以及它以上的系列,都采用**刘海屏设计**和**全面屏手势**。头部、底部、侧边都需要做特殊处理。才能适配 iPhone X 的特殊情况。
### 解决方案
**设置安全区域,填充危险区域,危险区域不做操作和内容展示。**
> 危险区域指头部不规则区域,底部横条区域,左右触发区域。

具体操作为:`viewport-fit` `meta` 标签设置为 `cover`,获取所有区域填充。
判断设备是否属于 iPhone X,给头部底部增加**适配层**
> `viewport-fit` 有 3 个值分别为:
> - `auto`:此值不影响初始布局视图端口,并且整个web页面都是可查看的。
> - `contain`:
视图端口按比例缩放,以适合显示内嵌的最大矩形。
> - `cover`:视图端口被缩放以填充设备显示。强烈建议使用 `safe area inset` 变量,以确保重要内容不会出现在显示之外。
#### 设置 viewport-fit 为 `cover`
```html
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes, viewport-fit=cover">
```
#### 增加适配层
使用 `safe area inset` 变量
```css
/* 适配 iPhone X 顶部填充*/
@supports (top: env(safe-area-inset-top)){
body,
.header{
padding-top: constant(safe-area-inset-top, 40px);
padding-top: env(safe-area-inset-top, 40px);
padding-top: var(safe-area-inset-top, 40px);
}
}
/* 判断iPhoneX 将 footer 的 padding-bottom 填充到最底部 */
@supports (bottom: env(safe-area-inset-bottom)){
body,
.footer{
padding-bottom: constant(safe-area-inset-bottom, 20px);
padding-bottom: env(safe-area-inset-bottom, 20px);
padding-top: var(safe-area-inset-bottom, 20px);
}
}
```
> `safe-area-inset-top`, `safe-area-inset-right`, `safe-area-inset-bottom`, `safe-area-inset-left`
`safe-area-inset-*`由四个定义了视口边缘内矩形的 `top`, `right`, `bottom` 和 `left` 的环境变量组成,这样可以安全地放入内容,而不会有被非矩形的显示切断的风险。对于矩形视口,例如普通的笔记本电脑显示器,其值等于零。 对于非矩形显示器(如圆形表盘,`iPhoneX` 屏幕),在用户代理设置的四个值形成的矩形内,所有内容均可见。
其中 `env()` 用法为 `env( <custom-ident> , <declaration-value>? )`,第一个参数为自定义的区域,第二个为备用值。
其中 `var()` 用法为 `var( <custom-property-name> , <declaration-value>? )`,作用是在 `env()` 不生效的情况下,给出一个备用值。
`constant()` 被 `css` 2017-2018 年为草稿阶段,是否已被标准化未知。而其他iOS 浏览器版本中是否有此函数未知,作为兼容处理而添加进去。
详情请查看文章末尾的参考资料。
#### 兼容性

## 页面生成为图片和二维码问题
### 表现
在工作中有需要将页面生成图片或者二维码的需求。可能我们第一想到的,交给后端来生成更简单。但是这样我们需要把页面代码全部传给后端,网络性能消耗太大。
### 解决方案
#### 生成二维码
使用 QRCode 生成二维码
```js
import QRCode from 'qrcode';
// 使用 async 生成图片
const options = {};
const url = window.location.href;
async url => {
try {
console.log(await QRCode.toDataURL(url, options))
} catch (err) {
console.error(err);
}
}
```
将 `await QRCode.toDataURL(url, options)` 赋值给 图片 `url` 即可
#### 生成图片
主要是使用 `htmlToCanvas` 生成 `canvas` 画布
```js
import html2canvas from 'html2canvas';
html2canvas(document.body).then(function(canvas) {
document.body.appendChild(canvas);
});
```
但是不单单在此处就完了,由于是 `canvas` 的原因。移动端生成出来的图片比较模糊。
我们使用一个新的 `canvas` 方法多倍生成,放入一倍容器里面,达到更加清晰的效果,通过超链接下载图片
**下载文件简单实现,更完整的实现方式之后更新**
```js
const scaleSize = 2;
const newCanvas = document.createElement("canvas");
const target = document.querySelector('div');
const width = parseInt(window.getComputedStyle(target).width);
const height = parseInt(window.getComputedStyle(target).height);
newCanvas.width = width * scaleSize;
newCanvas.height = widthh * scaleSize;
newCanvas.style.width = width + "px";
newCanvas.style.height =width + "px";
const context = newCanvas.getContext("2d");
context.scale(scaleSize, scaleSize);
html2canvas(document.querySelector('.demo'), { canvas: newCanvas }).then(function(canvas) {
// 简单的通过超链接设置下载功能
document.querySelector(".btn").setAttribute('href', canvas.toDataURL());
}
```
> 根据需要设置 `scaleSize` 大小
## 微信公众号分享问题
### 表现
在微信公众号 H5 开发中,页面内部点击分享按钮调用 SDK,方法不生效。
### 解决方案
#### 解决方法:添加一层蒙层,做分享引导。
因为页面内部点击分享按钮无法直接调用,而分享功能需要点击右上角更多来操作。
然后用户可能不知道通过右上角小标里面的功能分享。又想引导用户分享,这时应该怎么做呢?
技术无法实现的,从产品出发。

**如果技术上实现复杂,或者直接不能实现。不要强行钻牛角尖哦,学会怼产品,也是程序员必备的能力之一。**
## H5 调用 SDK 相关解决方案
### 产生原因
在 Hybrid App 中使用 H5 是最常见的不过了,刚接触的,肯定会很生疏模糊。不知道 H5 和 Hybrid 是怎么交互的。怎样同时支持 iOS 和 Android 呢?现在来谈谈 Hybrid 技术要点,**原生与 H5 的通信**。
### 解决方案

使用 `DSBridge` 同时支持 iOS 与 Android
> 文档见参考资料
#### SDK小组 提供方法
1. 注册方法 `bridge.register`
```js
bridge.register('enterApp', function() {
broadcast.emit('ENTER_APP')
})
```
2. 回调方法 `bridge.call`
```js
export const getSDKVersion = () => bridge.call('BLT.getSDKVersion')
```
#### 事件监听与触发法
```js
const broadcast = {
on: function(name, fn, pluralable) {
this._on(name, fn, pluralable, false)
},
once: function(name, fn, pluralable) {
this._on(name, fn, pluralable, true)
},
_on: function(name, fn, pluralable, once) {
let eventData = broadcast.data
let fnObj = { fn: fn, once: once }
if (pluralable && Object.prototype.hasOwnProperty.call(eventData, 'name')) {
eventData[name].push(fnObj)
} else {
eventData[name] = [fnObj]
}
return this
},
emit: function(name, data, thisArg) {
let fn, fnList, i, len
thisArg = thisArg || null
fnList = broadcast.data[name] || []
for (i = 0, len = fnList.length; i < len; i++) {
fn = fnList[i].fn
fn.apply(thisArg, [data, name])
if (fnList[i].once) {
fnList.splice(i, 1)
i--
len--
}
}
return this
},
data: {}
}
export default broadcast
```
#### 踩坑注意
方法调用前,一定要判断 SDK 是否提供该方法
如果 Android 提供该方法,iOS 上调用就会出现一个方法**调用失败等弹窗**。
怎么解决呢?
提供一个判断是否 Android、iOS。根据设备进行判断
```
export const hasNativeMethod = (name) =>
return bridge.hasNativeMethod('BYJ.' + name)
}
export const getSDKVersion = function() {
if (hasNativeMethod('getSDKVersion')) {
bridge.call('BYJ.getSDKVersion')
}
}
```
> 同一功能需要iOS,Android方法名相同,这样更好处理哦
## H5 调试相关方案策略
### 表现
调试代码一般就是为了**查看数据**和**定位 bug**。分为两种场景,一种是开发和测试时调试,一种是生产环境上调试。
> 为什么有生产环境上调试呢?有些时候测试环境上没法复现这个 bug,测试环境和生产环境不一致,此时就需要紧急生产调试。
在 PC 端开发时,我们可以直接掉出控制台,使用浏览器提供的工具操作devtools或者查看日志。但是在 App 内部我们怎么做呢?
### 原理与解决方案
#### 1. `vconsole` 控制台插件
使用方法也很简单
```js
import Vconsole from 'vconsole'
new Vconsole()
```

有兴趣看看它实现的基本原理,我们关注的点应该在 **vsconsole 如何打印出我们所有 log 的** [腾讯开源vconsole](https://github.com/Tencent/vConsole/blob/dev/src/core/core.js)
上述方法仅用于开发和测试。**生产环境中不允许出现,所以,使用时需要对环境进行判断。**
```js
import Vconsole from 'vconsole'
if (process.env.NODE_ENV !== 'production') {
new Vconsole()
}
```
#### 2. 代理 + spy-debugger
操作稍微有点麻烦,不过我会详细写出,大致分为 4 个步骤
1. 安装插件(全局安装)
```sh
sudo npm install spy-debugger -g
```
2. 手机与电脑置于同一 wifi 下,手机设置代理
设置手机的 HTTP 代理,代理 IP 地址设置为 PC 的 IP 地址,端口为`spy-debugger`的启动端口
> spy-debugger 默认端口:9888
> Android :设置 - WLAN - 长按选中网络 - 修改网络 - 高级 - 代理设置 - 手动
> IOS :设置 - Wi-Fi - 选中网络, 点击感叹号, HTTP 代理手动
3. 手机打开浏览器或者 app 中 H5 页面
4. 打开桌面日志网站进行调试,点击 npm 控制台监听地址。查看抓包和 H5 页面结构
**这种方式可以调试生成环境的页面,不需要修改代码,可以应付大多数调试需求**
# 总结
本篇文章耗费作者一个多星期的业余时间,存手工敲打 4500 +字,同时收集,整理之前很多坑点和边写作边**思考**和**总结**。如果能对你有帮助,便是它最大的价值。都看到这里还不**点赞**,太过不去啦!😄
由于技术水平有限,文章中如有错误地方,请在评论区指出,感谢!
关于移动端 H5 的文章告一段落了,之后实践中遇到的问题都将在此文中更新。另外准备做一个移动端 H5 开源项目。多关注下 [我的github](https://github.com/suoyuesmile/suo-blog)动态哦!
之后,应该回去研究下**开源和面试题相关内容**分享,想持续了解更多,不妨**点赞**和**关注**呗。
# 参考资料
- [Safari CSS Reference](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/css/property/-webkit-overflow-scrolling)
- [MDN touch 事件]()
- [MDN css var()](https://developer.mozilla.org/zh-CN/docs/Web/CSS/var)
- [MDN css env()](https://developer.mozilla.org/zh-CN/docs/Web/CSS/env)
- [csswg env() drafts](https://drafts.csswg.org/css-env-1/)
- [fastclick 源码](https://github.com/ftlabs/fastclick/blob/master/lib/fastclick.js)
- [DSBridge-Android](https://github.com/wendux/DSBridge-Android) & [DSBridge-iOS](https://github.com/wendux/DSBridge-IOS)
- [qrcodejs 源码](https://github.com/davidshimjs/qrcodejs)
- [html2canvas 源码](https://github.com/niklasvh/html2canvas)
- [关于H5页面在iPhoneX适配](https://www.cnblogs.com/lolDragon/p/7795174.html)
- [vant 相关文档](https://youzan.github.io/vant/#/zh-CN/button)
================================================
FILE: articals/interview/0001.md
================================================
首先呢,统计一下情况:
本人校招进入新三板上市企业工作一年,并有半年多一线互联网实习经验
来到杭州投出简历 24 封,收到面试邀约 10 次
`result = 正式offer * 2 + 口头offer * 1`
令人头疼的是并没拿到自己想要的 offer,理想的公司大多连面试机会都不给...
伤脑筋...明天还有两家电话面试,过了大半个月,还是打算继续面下去...
### 理想公司:
- ***服:简历都没过(惨)还被一个蚂***外包招聘diss我这样的一年工作经验都外包都够呛(晕)
- *赞:投了很多遍,简历全部卡在`HR`上了(惨)
- *猫:没敢投(吓)
- **车:一下午全部面完,环境一般,每轮面试都等了很长时间,两轮技术面后又和HR聊了一个多小时技术问题,表示很无奈,从此对大搜车印象大大折扣。回去等通知,一周之后说经验不符。敢情经验不符,你让我去面试个球(气)
- *吧:HR主动找,问
```js
你会 React ?我答会
你会移动端吗?我答会
你有过 H5 经验吗?我答有
对不起,面试官说经验不符
???(懵)
```
- **顺:只招应届生了
### 考题汇总:
- `this` 指向 * 10 (必考有没有,这都不知道还学啥JavaScript--笑)
- 同步异步或者事件机制 * 8
- `Vue` 双向绑定实现原理 * 8
- 箭头函数 * 6(考察 ES6 使用情况)
- `call` `apply` `bind` 的使用和区别 * 6 (问到`this`很可能问到这些)
- 常用 `Array` 函数 * 6
- `Vuex` 应用及其原理 * 6
- `Vue` 父子兄弟通信 * 5
- `Redux` 原理 * 5
- `dom` 事件 * 5
- `Vdom` 原理及`diff`算法 * 5
- `Promise`机制 * 5
- 原型链及面向对象相关知识 * 4
- `HTTPS` 安全性 * 3
- 闭包 * 3
- 变量提升 * 3
- `HTTP` 状态码 * 2
- `Proxy` 和 其他一些 `ES6` 新特性
- 防抖与节流 * 1
- 深浅拷贝原理和实现 * 1
- `getComputedStyle` * 1
- `rem` * 1 (考察关于移动端布局到问题)
- 其他忘记了...
### 聊聊面试题
#### `this` 指向什么? 一起源于 `this`
《You dou't kown JavaScript》 这本书讲等最清楚了
首先是两个误解:
1. `this` 指向自身,根据英语翻译来说,这是一种自然的想法,其实不然,这是一个误解。
2. `this` 指向函数作用域,这个在某种情况下是正确的
其次是四种情况
1. 默认绑定
```js
var name = 'lufei'
function show() {
var name = 'namei'
console.log(this.name)
}
show()
// lufei
```
可以看出最后 `this` 绑定在全局对象上,所以结果是 `lufei`
2. 隐式绑定
```js
function show() {
var member = 'namei'
console.log(this.member)
}
var member = 'zoro'
var caomao = {
member: 'lufei',
showMember: show
}
caomao.showMember()
// lufei
```
这里最后通过 `caomao` 来调用这个函数,函数中的 `this` 则被绑定到 `caomao` 这个对象上
3. 显式绑定
```js
var caomao = {
member: 'lufei'
}
var member = 'zoro'
function show() {
var member = 'namei'
console.log(this.member)
}
show.call(caomao)
// lufei
```
通过 `call`,`apply`,`bind` 我们可以显示的改变 `this` 的绑定
4. `new` 绑定
最后一种是使用 `new` 调用函数,或者说是构造函数调用时
```
function SeaPoacherBoat(member) {
this.member = member
}
var caomao = new SeaPoacherBoat('lufei')
console.log(caomao.member) // lufei
```
这段代码会执行以下操作:
1. 创建一个全新的对象
2. 进行原型(`prototype`)链接
3. 将 新对象 绑定到函数调用的 `this`
4. 如果没有返回其他对象,则自动返回一个新对象
它们绑定的优先级是 `new` > 显示绑定 > 隐式绑定 > 默认,这也是很容易理解的,`new` 是生成了一个全新的对象优先级是最高的,显示绑定函数要起作用优先级一定要高于隐式绑定,默认绑定是最低的这个也无可厚非
最后一句话总结 **`this` 是运行期间绑定,和它声明的环境无关,只与调用它的对象有关**
#### 我们知道了它的指向,要想改变它怎么办呢?
改变 `this` 指向最直接的方法是 `call`, `apply`, `bind`,来看一下下面这段代码
```js
var name = '草帽海贼团'
var caomao = {
name: '路飞'
}
function printMember(arg1, arg2) {
var name = '娜美'
console.log(this.name)
console.log(arg1, arg2)
}
printMember('山治', '索隆') // 草帽海贼团 山治 索隆
printMember.call(caimao, '山治', '索隆') // 路飞 山治 索隆
printMember.apply(caimao, ['山治', '索隆']) // 路飞 山治 索隆
printMember.bind(caimao, '山治', '索隆')() // 路飞 山治 索隆
```
根据上面代码,`this` 现在指向的 `window` 对象,所以打印的是草帽海贼团而不是娜美
下面我们通过三种方式将 `this` 指针绑定到 `caomao` 这个对象,所以最后打印的都是路飞
很明显它们的区别无非就在于形式的不同,以`call`为基础来说,`apply` 是将后面的参数合成一个数组一起传人函数,`bind`最后返回的是一个函数,只有调用这个函数后才算执行。
有一种特殊情况就是把 `null` 和 `undefined` 作为`this`的绑定对象传人进去,这样的实际情况是采用的默认绑定原则
那么这有什么用途呢?常见用于**展开数组**来,看一段代码
```js
function print(a, b) {
console.log(a, b)
}
print.apply(null, [1, 2])
```
还有呢, 使用`bind`用于**柯里化**
```js
var foo = print.bind(null, 1)
foo(2)
```
也就是延迟执行最终的结果
**是不是所有函数都可以绑定`this` 呢?**
没错你可能很快想到就是箭头函数,普通函数来说,`this`是运行期绑定,而 `ES6`新规则里箭头函数并没有绑定 `this`,它是不存在 `this`的绑定的。那在箭头函数中存在`this` 会怎么样呢
```js
// 情景一,全局范围内调用箭头函数
var foo = () => { console.log(this) }
foo() // window
// 情景二,对象中调用
function monkey() {
var bar = () => console.log(this)
bar()
}
var obj = {
monkey: monkey
}
var other = {
obj: obj
}
other.obj.monkey() // { monkey }
```
之前很多人对箭头函数中的 `this` 都有一些误解,认为箭头函数中的 `this` 自身绑定或者是任何绑定在最终调用方式上。其实不然,从上面代码中我们可以看出箭头中的 `this` 绑定在离最近外层的对象 obj 上, 而不是最终调用对象 other 上。
#### 我们知道了 `this` 的指向的对象调用它的函数,那么调用它的时候到底发生了什么?我们需要知道JS执行机制到底是怎么样的
```js
console.log(run)
var run
function run(run) {
var run = 2
this.run = run
console.log(this, arguments)
console.log(run)
}
run('1')
console.log(run)
run = 3
console.log(run)
```

我们来分析一下它的运行方式
首先开始预解析,它有个规则是**变量声明提升**,我们可以知道函数声明会被提升到最上面,其次是变量。**声明后的变量不会重复声明**,所以第二次声明的变量不生效,我们手动来做一次转换
```
// 提升函数声明
function run(run) {
console.log(this, arguments)
var run = 2
this.run = run
console.log(run)
}
// 提升变量声明
var run
console.log(run)
run('1')
console.log(run)
run = 3
console.log(run)
```
所以第一个 log 会打印出函数而不是变量
开始按顺序执行下面的语句,此时遇到一个`run()`的调用
将`run`推入到执行栈中,进行以下几个步骤:
1. 绑定 `this` 和 初始化参数, 根据之前谈到的规则,`this` 绑定到调用它的全局对象 `window`,所以第二个 log 打印出 `window`对象和传递过来的参数
2. 同样在函数作用域中开始执行预解析,执行语句,函数中又定义了一个`run`。我们知道作用域原理是就近查找,存在一个屏蔽作用,`run` 函数作用域中的 `run` 此刻就是 `2`,所以第三个 log 会打印出 `2`, `this.run = run` 将全局中的 `run` 赋值为 `2`
3. 执行完成后,`run` 函数出栈,继续执行全局语句,`run` 的值已经被改变成 `2`,所以此刻第四个 log 也打印出了 `2`,最终又被改变成 `3`,所以最后一个 log ,打印出了 `3`
### 聊聊框架
Vue 和 React 你学哪一个?
哎呀!头疼, 能不能不要选啊,选 `React` 都说 `React`待遇好,大厂都爱`React`。
HR问,你`Vue` 多少经验?没有,bye~,不符合项目经验。那就学 Vue 呗,好上手,越来越流行。
HR问,你`React` 多少经验?没有,bye~,不符合项目经验。- -
大家仰望天空叹息到,学不动了...不怕学不动了,就怕学到的东西马上就过时了。
所以只有学到**真正底层基础思想**的东西才是真正重要的。
就算哪天没有这些框架了也能马上撸一个出来。
### 分享想法
最近找工作萌生了一个 开源 idea
- 痛点一:每次制作需要去找模版,去制作模版,而对于我们前端而言,更加擅长制作个性在线简历,可不可以考虑使用前端技术制作一个在线简历模版,开源免费供大家使用,大家开发自己的主题,大家不需要花钱去模版网站找那些并不适合自己的简历模版。
- 痛点二:对于前端来说,知识点太杂,面试考点太多。简历不单单是一个介绍,也是我们技术的一个总结。通过开发一个工具自动识别我们简历里面的技术点,模拟面试官给出一些面试考察的题目,让我们知道自己的不足,持续的学习和进步。
- 痛点三:对于简历,我们不应该一份简历进行海投,应该针对不同的岗位职责进行修改。所以我们可以开发一个输入职位地址,自动匹配简历与岗位中的差异并标记。这样我们就知道自身与岗位职责之间又多大差距,然后努力去接近它。同时我们需要对不同简历进行管理。
以上都是目前各大招聘网站和简历制作网站所没有的需求,这是我们技术人员和求职者自身的诉求。
而目前各大招聘网站更加注重招聘者的需求,往往不会管应聘者的需求,甚至要求各种付费的一些功能。
这个开源项目不是为了取代招聘网站,而是做一个从学习->工作->求职环节的一个补充。
需求
- v1.0.0 在线简历编辑功能,自己制作主题功能...
- v2.0.0 技术匹配识别功能,模拟面试功能,面试评分功能...
- v3.0.0 简历管理功能,职位匹配功能...
- v4.0.0 内推,代码练习,文章订阅...
技术实现
待定...
### 开源计划
https://github.com/suoyuesmile/resume-promotion

### 感谢阅读
第二次发文章,技术不到位多多海涵,里面技术点一部分来自 `You don't kown JavaScript`,另一部分来自平时看过的文章和平时的总结。以后会持续更新,也算是对自己技术相关原理的总结。推荐大家去认真看看这本书,相信你会有更大的收获。
高清电子书资源(请私聊,我单独发给你)

### 下期预告(待定)
#### 函数又来自哪?同时数组又来自哪?原型链又是什么东西?
#### 我们已经有了函数,为什么还要箭头函数?箭头函数仅仅是替代函数写法吗?
#### 我们知道 Vue 通过 `Object.defineProperty()` 劫持对象,那么它数组又是怎么劫持的呢?
#### 函数有个执行栈,我们知道同步函数是在执行栈里执行,那异步函数呢?
#### 说到异步,怎么实现异步的?异步与同步最大的区别在于什么?
#### 回调函数可以实现异步,为什么还要用 `Promise`?
#### `Promise` 异步就很好用了,为啥又有 `async` 和 `await`
------------------------------更新-------------------------------------
2019.7.3 更新 工作已确定,帮忙内推的朋友多谢了...去了一家小型待遇还不错的小公司
2019.12.6 更新 前一天还在谈论技术方案,今天公司倒闭缱散了,又成自由人了... 希望下家稳定些...
[掘金地址](https://juejin.im/post/5d14bb9a5188255d3f6ca8f6)
[issue评论区](https://github.com/suoyuesmile/suo-blog/issues/37)
================================================
FILE: articals/js/0001.md
================================================
对写文章这件事已经阁了3个月了,工作太忙很难抽出大块时间来总结写作。现在稍微闲赋些,准备好好对以前的技术做一下总结。为什么要写关于 `Promise` 呢?有以下 3 点
1. 之前面试时候,面试官问 `Promise` 问的比较多,实在要对它进行一个好好总结了,也是 JavaScript 比较难懂的一个技术点,平时我面试别人时候,也喜欢问 `Promise` 相关的,保证他在工作中能够熟练运用,自己能封装`axios`,能控制比较复杂的同步异步流程等...
2. 这三个月的工作中,自己也总是遇到关于 `Promise` 的一些运用场景,有时候又比较疑惑一些地方,也是为自己总结一下 `Promise`,以后在工作中更加运用自如。
接下来我从最基础的同步异步谈起,再通过图示谈他的语法,如何自己写一个`Promise`,再谈一下我在工作中遇到的 `Promise`,最后谈一下 新的语法 `async` 和 `await `与 `Promise` 的结合和比较
3. 网上关于`Promise`的介绍大多数是一些语法的介绍,大多没有结合场景和同步异步相关理解来谈。对于理解`Promise`的前世今生还是不够深入,不够具体。
### 理解同步异步
#### 理解JS执行原理
```js
console.log(1)
setTimeout(() => {
console.log(2)
}, 1000)
console.log(3)
```

如果延迟时间为`0`呢
```js
console.log(1)
setTimeout(() => {
console.log(2)
}, 0)
console.log(3)
```

```js
console.log(1)
setTimeout(() => {
console.log(2)
}, 2000)
console.log(3)
setTimeout(() => {
console.log(4)
}, 1000)
console.log(5)
setTimeout(() => {
console.log(6)
}, 0)
console.log(7)
setTimeout(() => {
console.log(8)
}, 1000)
console.log(9)
```

这里可以发现几点
- 1,3,5,7,9 是同步代码,6,4,8,2是异步代码,同步先于异步执行
- 单看同步代码,按位置顺序依次执行
- 单看异步代码,不同执行时间,越长越靠后执行。相同执行时间,按位置顺序依次执行
这里我们总结下同步与异步的规律
- **代码中存在异步函数,不管需要时间多久,都要在同步完成后执行**
- **同步按位置顺序执行;异步按时间长短执行,同样时间长短时,按位置顺序执行**
这是一个怎样的机制,JS引擎又是如何处理的呢?
我找到了一张这样的图

首先来解释一下这个图:这是JS的事件循环,分为3个步骤
1. 引擎将同步、异步函数按次序载入到执行栈里面
2. 执行栈的将异步函数放入异步线程里面
3. 线程根据任务完成时间依次推入任务队列中执行
如何处理异步呢, 最初的方法是使用回调
#### 理解回调
引入一下知乎上的高赞回答

现在我们把它用代码写出来看看
```js
function fetchSomething() {
console.log('去取货!')
}
function buySomething(callback) {
console.log('没货了!')
setTimeout(() => {
console.log('有货了!')
callback()
}, 1000)
}
buySomething(fetchSomething)
```

用简单的语言描述就是:**将一个函数作为参数传给另一个函数调用**
要搞清楚的一点是,回调和异步没有直接的关系,也可以同步回调,也可以异步回调。我们是通过回调这个机制来实现异步的操作,例如
```js
// 这个一个请求的异步函数,来实现异步操作
function getSomePeopleName(params, callback) {
setTimeout(() => {
let data
if (params === 'suo') {
data = 'yue'
}
console.log(callback(data))
}, 1000)
}
console.log(getSomePeopleName('suo', (data) => '我是回调函数:' + data))
```

回调函数的结果一定是在回调函数里面,如果我是这样一个流程呢?
A -> B -> C -> D
```js
function A(callback) {
console.log('开始执行A')
setTimeout(() => {
callback('A')
}, 500)
}
function B(callback) {
console.log('开始执行B')
setTimeout(() => {
callback('B')
}, 400)
}
function C(callback) {
console.log('开始执行C')
callback('C')
}
function D(callback) {
console.log('开始执行D')
setTimeout(() => {
callback('D')
}, 200)
}
A((a) => {
B((b) => {
C((c) => {
D((d) => {
console.log(a, b, c, d)
})
})
})
})
```

由上可知,回调函数有几个特定
- 使用回调函数嵌套,回调函数一定在上一个回调之后执行,用于可以控制流程,不会出现异步函数在执行顺序的混乱,即使同步异步函数混合
- 回调函数解构嵌套,代码不够清晰,俗称回调地狱
那么有没有更好的异步操作机制呢?这里我们就要谈到 `Promise` 了
### 深入 Promise
#### 为什么要有Promise?
#### ES6 标准中 Promise 语法
- `Promise`是一个构造函数
我们写一个简单的 `Promise` 看看
```js
new Promise(() => {})
```

```js
// 有一个参数executor的构造函数
// executor 也是一个函数,具有两个参数 resolve, reject 是两个回调函数,当执行到回调函数时,会执行
const isResolve = true
new Promise((resolve, reject) => {
if (isResolve) {
resolve()
} else {
reject()
}
})
```

可以看到 `Promise` 的状态从`pending`变成`resolved`
如果将 `isResolve` 置为 `false` 呢?

`Promise` 状态从 `pending` 变成 `rejected` 同时抛出一个异常,并且异常未被捕获,所以我们写Promise时候一定要加上catch 来捕获异常
```js
const isResolve = false
new Promise((resolve, reject) => {
if (isResolve) {
resolve()
} else {
reject('我拒绝你')
}
}).catch((err) => {
console.log('捕获异常', err)
})
```

现在我们把异常捕获到了,但是神奇的事情发生了,异常状态应该是`rejected`,怎么变成 `resolved`了呢?
我们或许很纳闷,这个放在后面讨论,我们先看看 `then` 怎么处理的
```js
const isResolve = true
new Promise((resolve, reject) => {
if (isResolve) {
resolve('通过')
} else {
reject('我拒绝你')
}
}).then((res) => {
console.log('resolve', res)
}, (res) => {
console.log('reject', res)
})
```

当`isResolve = false` 时

我们可以看到 `then` 是怎么处理的
1. 如果 前面`resolve()`调用,Promise状态为 `resolved`,`then`则执行第一个回调函数参数
2. 如果 前面`reject()`调用,Promise状态为 `rejected`,`then`则执行第二个回调函数参数
3. **then 执行回调函数之后Promise 的 状态都为 resolved**
下面进一步验证下
```js
const isResolve = false
new Promise((resolve, reject) => {
if (isResolve) {
resolve('通过')
} else {
reject('我拒绝你')
}
}).catch(err => {
console.log('我捕获到了', err)
}).then((res) => {
console.log('resolve', res)
}, (res) => {
console.log('reject', res)
})
```

果然呢,`catch`之后,`then`还会去执行,并且`resolve` 的参数为 `undefined`
问题是现在我们如何控制一个流程呢?`Promise`并不能直接给我们进行长流程的分支选择
下面有一个简单流程

尝试使用`Promise`去控制流程
```js
const process = [102, 204]
new Promise((resolve, reject) => {
if (process[0] === 101) {
setTimeout(() => {
console.log(101)
resolve(101)
}, 1000)
} else {
setTimeout(() => {
console.log(102)
reject(102)
}, 1000)
}
}).then(() => {
if (process[1] === 201) {
setTimeout(() => {
console.log(201)
}, 500)
} else {
setTimeout(() => {
console.log(202)
}, 500)
}
}, () => {
if (process[1] === 203) {
setTimeout(() => {
console.log(203)
}, 500)
} else {
setTimeout(() => {
console.log(204)
}, 500)
}
}).catch((err) => {
console.log(err)
})
```

下面我们试试更加复杂的流程
#### Promise 调用链:then 的作用
单个`Promise`没办法控制长流程,我们怎么将`Promise`形成一个控制链呢,需要理解`then`的返回在其中起到的作用
```js
promise.then(onFulfilled, onRejected)
```
- 接收两个参数,`onFulfilled` 在`promise`的 `resolved` 状态被调用
- 接收两个参数,`onRejected` 在`promise`的 `rejected` 状态被调用
- 返回值比较复杂,下面用表格列出来
| 序号 | 场景 | 返回的Promise状态改变为 | 回调函数参数值 |
| ---- | ----------------- | ----------------------- | ------------------------- |
| 1 | 返回1 个值 | resolved | 返回值 |
| 2 | 没有返回 | resolved | undefined |
| 3 | 抛出错误 | rejected | 错误 |
| 4 | resolved的Promise | resolved | 返回的Promise回调的参数值 |
| 5 | rejected的Promise | rejected | 返回的Promise回调的参数值 |
| 6 | pending的Promise | pending | 返回的Promise回调的参数值 |
我们可以看出想要控制`then` 的后续流程,必须通过这 6 种情况来控制
下面来测试一下 这 6 种情况是否符合我们的预期
1. 返回一个值
```js
new Promise((resolve, reject) => {
resolve('通过')
}).then((res) => {
console.log('1', res)
return res // then的返回值
}).then((res) => {
console.log('2', res)
})
```

2. 不返回

3. 抛出错误

4. resolved的Promise

5. rejected的Promise

6. pending的Promise

#### 看图写代码

分析特点:
这样就比较复杂了,还要考虑暂停的问题,但是根据我们上面测试到的,通过`then`的返回值控制流程也没有想象那么难
```js
task([101, 201])
function task(testPath) {
console.log('开始测试', testPath)
new Promise((resolve, reject) => {
console.log('000')
if (101 === testPath[0]) {
resolve('101')
} else {
reject('102')
}
}).then((res) => {
console.log('201', '上一个返回:' + res)
return new Promise(() => {})
}, (res) => {
if (202 === testPath[1]) {
console.log('202', '上一个返回:' + res)
return '202'
} else {
console.log('203', '上一个返回:' + res)
throw '203'
}
}).then((res) => {
console.log('301', '上一个返回:' + res)
return Promise.resolve('301')
}, (res) => {
console.log('302', '上一个返回:' + res)
return Promise.resolve('302')
}).then((res) => {
console.log('401', '上一个返回:' + res)
return Promise.reject('401')
}).catch((err) => {
console.log(err)
})
}
```



- `Promise.resolve()` 等同用 `new Promise((resolve, reject) => resolve())`
- `Promise.reject()` 等同用 `new Promise((resolve, reject) => reject())`
- `Promise.all()`
```js
// 作为参数promise 数组中,所有promise状态都是resolved才回调then第一个,只要有一个reject就reject
Promise.all([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)]).then((res) => {
console.log('通过', res)
}, (res) => {
console.log('拒绝', res)
})
```

返回值为全部值的一个数组
```js
Promise.all([Promise.resolve(1), Promise.resolve(2), Promise.reject(3)]).then((res) => {
console.log('通过', res)
}, (res) => {
console.log('拒绝', res)
})
```

返回值仅返回拒绝的那个
- `Promise.race()`
```js
Promise.race([new Promise((resolve, reject) => {
setTimeout(() => {
reject(1)
}, 1001)
}), new Promise((resolve, reject) => {
setTimeout(() => {
resolve(2)
}, 1002)
})]).then((res) => {
console.log('通过', res)
}).catch((res) => {
console.log('拒绝', res)
})
```

race 相当于竞赛,多个`Promise`竞赛,谁先状态变成`resolved`和`rejected`,谁就执行下面的回调(根据时间来抉择)
## 下节预告
### Promise 到 generator 再到 async & await
### Promise 实际应用
#### 对异步请求封装
#### 流程控制
### 手写一个Promise
## 后记
总结一下,从同步异步到回调,在到`Promise`的语法和应用全部都可以在谷歌浏览器的控制台中输出测试。通过一点点代码的编写和输出,才会让我们思维更清晰,对`Promise`的理解更深刻。之后再总结工作中用到的`Promise`,以后也会慢慢将`async`、`await`结合P`romise`来谈关于 es6 以后异步相关的新特性。
================================================
FILE: articals/js/0002.md
================================================
Promise 处理异步代码相对于纯回调函数比较有序明了,但是对于同步函数写法还是挺繁琐的,下面有两种语法糖让异步更加清晰简洁
### 生成器
#### generator 函数
像指针一样下移,有点像在debug代码
```js
function* gen() {
yield 1
yield 2
yield 3
}
let g = gen()
console.log(g.next())
console.log(g.next())
console.log(g.next())
console.log(g.next())
```

- 中断并完成下移`return()`
```js
function* gen() {
yield 1
yield 2
yield 3
}
let g = gen()
console.log(g.next())
console.log(g.next())
console.log(g.return('完成'))
console.log(g.next())
```

- 中断并抛出异常 `throw()`
```js
function* gen() {
try {
yield 1
yield 2
yield 3
} catch(e) {
console.log(e)
}
}
let g = gen()
console.log(g.next())
console.log(g.next())
console.log(g.throw('异常'))
console.log(g.next())
```

如果在异步函数里面使用 `generator` 函数怎样?
```js
function promise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('resolved')
}, 1000)
})
}
function* generate() {
promise().then((res) => {
console.log(res)
})
}
function fn() {
const res = generate().next()
console.log(res)
}
fn()
```

现在发现,异步代码不需要`then`回调了,看起来和同步函数写法一样
不过现在我们有了`async`、`await`函数,将生成器进一步封装,也可以说出语法糖
### async、await函数
使用Promise 写法写一个简单的例子
```js
function promise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('resolved')
}, 1000)
})
}
function fn() {
promise().then((res) => {
console.log(res)
})
}
fn()
```

改写成 `async` 函数
```js
async function asyncFn() {
console.log(await promise())
}
asyncFn()
```

**async 和 then 一样 可以达到同一个的效果,而且代码中没有回调函数的影子了**
多条异步链的情况
```js
function promise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1)
}, 1000)
})
}
function fn() {
const p = promise().then((res) => {
console.log('第一个then', res)
return res === 2 ? new Promise((resolve, reject) => {
setTimeout(() => {
resolve(2)
}, 500)
}) : new Promise((resolve, reject) => {
setTimeout(() => {
reject(3)
}, 500)
})
}).then((res) => {
console.log('第二个then', res)
}).catch((err) => {
console.log('异常', err)
})
}
fn()
```

使用 async 改写
```js
function promise() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1)
}, 1000)
})
}
function promise2() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(2)
}, 500)
})
}
function promise3() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(3)
}, 500)
})
}
async function asyncFn() {
const step1_res = await promise()
console.log('第一步的结果:', step1_res)
try {
if (step1_res === 2) {
console.log('第二步的结果:', await promise2())
} else {
console.log('第二步的拒绝的结果:', await promise3())
}
}
catch(err) {
console.log('异常:', err)
}
}
asyncFn()
```

**用同步的代码写出了异步的效果**
================================================
FILE: articals/react/0001.md
================================================
2019年7月3日 天气小晴
现在早上9点,准时开始学习 React
### 半个小时过一遍 React 官方文档和教程 (9:00 - 9:30)

#### 扫视一遍它的基本介绍(5分钟)
我们看到下面介绍了三个 React 最重要的特性:
- **声明式**:它是说:React 创建用户界面很简单,当数据改变就会高效的更新和立即渲染组件。同时声明式可以让你的代码更加**可预测和易调试**。
怎么就是可预测的和易调试呢,暂时不是很理解
- **组件化**:可以创建一个管理自身状态的组件,通过组合这些组件来创造复杂的UI。因为组件逻辑是用 JavaScript 写的而不是模版,所以你可以传更丰富的数据到你的APP,同时还可以与 DOM 解藕。
- **一学多用**:不需要新的技术栈,重新写新的代码就可以开发一些新的功能。比如用作服务器渲染,`React Native` 编写移动端代码。

再往下扫,给出了 React 的 4 个简单的小例子
- **Helloworld(认识 组件 和 props)**
```jsx
class HelloMessage extends React.Component {
render() {
return (
<div>
Hello {this.props.name}
</div>
);
}
}
ReactDOM.render(
<HelloMessage name="Taylor" />,
document.getElementById('hello-example')
);
```
看到它使用 ES6 的继承,继承了一个组件的基类,此刻充满好奇心的你,肯定会想我继承的这个 `React.Component` 到底是啥?(先留着之后去看 React 的源码)
没有写构造函数,说明它直接继承了基类的构造函数
里面有一个 `render` 函数 `return` 一个貌似模版的东西,这个就是最简单的组件
紧接着下面一个 `ReactDOM.render`函数接受两个参数一个是组件标签,一个`id`查找,现在大概的意思就是`render`函数就是要把组件渲染到找到`id`的这个地方。
组件标签里面的属性就给组件中作为`this.props`的属性。而且我们知道**父组件通过 `props` 可以将数据传递给子组件**。
- **定时器(认识 状态state)**
```jsx
class Timer extends React.Component {
constructor(props) {
super(props);
this.state = { seconds: 0 };
}
tick() {
this.setState(state => ({
seconds: state.seconds + 1
}));
}
componentDidMount() {
this.interval = setInterval(() => this.tick(), 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>
Seconds: {this.state.seconds}
</div>
);
}
}
ReactDOM.render(
<Timer />,
document.getElementById('timer-example')
);
```
我们看到第二个例子会发现里面多了很多其他的东西:
- 构造函数
- state
- 声明周期函数
发现我们可以在组件里面定义组件的构造函数,而且可以在构造函数里面初始化一个名为 状态(state)的东东。
**怎样去理解状态(state)这个词?**
我们假设组件是有生命的,它必然有个生命周期。大致分给三个阶段:
出生----> 变化----> 死亡 (对应) 创建----> 更新----> 销毁
伴随着生命周期的变化,它身上的属性也在发生变化,比如体温、寿命、心情、皮肤好坏、细胞生命力,甚至思维模式。我们可以把**这些变化的属性成为状态(state)**
但是作为它的创建者,我们即为它的上帝,所以需要控制管理它的状态的变化。所以我们在每一个阶段的变化中加了一个钩子,在相应的阶段去定义一些程序。
gitextract_o3sr3lo_/ ├── .gitattributes ├── .gitignore ├── .vscode/ │ └── launch.json ├── README.md ├── articals/ │ ├── c/ │ │ ├── Demo/ │ │ │ ├── argv[2] │ │ │ ├── bug1.c │ │ │ ├── mywords │ │ │ ├── test.c │ │ │ ├── test10.c │ │ │ ├── test11.c │ │ │ ├── test12.c │ │ │ ├── test13.c │ │ │ ├── test14.c │ │ │ ├── test15.c │ │ │ ├── test16.c │ │ │ ├── test17.c │ │ │ ├── test18.c │ │ │ ├── test19.c │ │ │ ├── test2.c │ │ │ ├── test20.c │ │ │ ├── test21.c │ │ │ ├── test22.c │ │ │ ├── test23.c │ │ │ ├── test24.c │ │ │ ├── test25.c │ │ │ ├── test26.c │ │ │ ├── test27.c │ │ │ ├── test28.c │ │ │ ├── test29.c │ │ │ ├── test3.c │ │ │ ├── test30.c │ │ │ ├── test31.c │ │ │ ├── test32.c │ │ │ ├── test33.c │ │ │ ├── test34.c │ │ │ ├── test35.c │ │ │ ├── test36.c │ │ │ ├── test37.c │ │ │ ├── test38.c │ │ │ ├── test39.c │ │ │ ├── test4.c │ │ │ ├── test40.c │ │ │ ├── test41.c │ │ │ ├── test42.c │ │ │ ├── test43.c │ │ │ ├── test44.c │ │ │ ├── test45.c │ │ │ ├── test46.c │ │ │ ├── test47.c │ │ │ ├── test48.c │ │ │ ├── test49.c │ │ │ ├── test5.c │ │ │ ├── test50.c │ │ │ ├── test51.c │ │ │ ├── test52.c │ │ │ ├── test53.c │ │ │ ├── test54.c │ │ │ ├── test55.c │ │ │ ├── test56.c │ │ │ ├── test57.c │ │ │ ├── test58.c │ │ │ ├── test59.c │ │ │ ├── test6.c │ │ │ ├── test60.c │ │ │ ├── test61.c │ │ │ ├── test62.c │ │ │ ├── test63.c │ │ │ ├── test64.c │ │ │ ├── test65.c │ │ │ ├── test66.c │ │ │ ├── test67.c │ │ │ ├── test68.c │ │ │ ├── test69.c │ │ │ ├── test7.c │ │ │ ├── test70.c │ │ │ ├── test71.c │ │ │ ├── test72.c │ │ │ ├── test73.c │ │ │ ├── test74.c │ │ │ ├── test75.c │ │ │ ├── test76.c │ │ │ ├── test77.c │ │ │ ├── test78.c │ │ │ ├── test79.c │ │ │ ├── test8.c │ │ │ ├── test80.c │ │ │ ├── test81.c │ │ │ ├── test82.c │ │ │ ├── test83.c │ │ │ ├── test84.c │ │ │ ├── test85.c │ │ │ ├── test86.c │ │ │ ├── test87.c │ │ │ ├── test88.c │ │ │ ├── test89.c │ │ │ ├── test9.c │ │ │ ├── test90.c │ │ │ ├── test91.c │ │ │ ├── test91.h │ │ │ ├── test92.c │ │ │ ├── test93.c │ │ │ ├── test94.c │ │ │ ├── test95.c │ │ │ ├── test96.c │ │ │ ├── test97.c │ │ │ ├── test98.c │ │ │ ├── test99.c │ │ │ ├── testDice_d.c │ │ │ ├── testFgets.c │ │ │ ├── testFgets2.c │ │ │ ├── testFgets3.c │ │ │ ├── testFileIO.c │ │ │ ├── testGets.c │ │ │ ├── testIO.c │ │ │ ├── testP02.c │ │ │ ├── testPntAdd.c │ │ │ ├── testPo.c │ │ │ ├── testPoint.c │ │ │ ├── testPrintfScanf.c │ │ │ ├── testR_d.c │ │ │ ├── testRand.c │ │ │ ├── testRandom.c │ │ │ ├── testRecursion.c │ │ │ ├── testReducto.c │ │ │ ├── testScope.c │ │ │ ├── testStrSort.c │ │ │ ├── testSwap.c │ │ │ ├── testToBinary.c │ │ │ ├── words │ │ │ ├── words.red │ │ │ └── wordscp │ │ ├── array.md │ │ ├── data.md │ │ ├── fileIO.md │ │ ├── function.md │ │ ├── memory.md │ │ └── string.md │ ├── c++/ │ │ ├── class.md │ │ ├── function.md │ │ ├── oop.md │ │ ├── reload.md │ │ ├── str_map_arr.md │ │ └── var.md │ ├── h5/ │ │ ├── 0001.md │ │ ├── 0002.md │ │ └── 0003.md │ ├── interview/ │ │ └── 0001.md │ ├── js/ │ │ ├── 0001.md │ │ └── 0002.md │ ├── react/ │ │ └── 0001.md │ └── vue/ │ ├── 0001.md │ └── 0002.md ├── booknotes/ │ ├── bst.md │ ├── compute.md │ ├── demo/ │ │ ├── AVL.class.cpp │ │ ├── BST.class.cpp │ │ ├── BTNode.h │ │ ├── BTree.class.cpp │ │ ├── BinNode.h │ │ ├── BinTree.class.cpp │ │ ├── Edge.h │ │ ├── Graph.class.cpp │ │ ├── GraphMatrix.class.cpp │ │ ├── Lcs.cpp │ │ ├── List.class.cpp │ │ ├── ListNode.h │ │ ├── Node.h │ │ ├── PQ.class.cpp │ │ ├── PQ_ComplHeap.class.cpp │ │ ├── Queue.class.cpp │ │ ├── RedBlack.class.cpp │ │ ├── SList.class.cpp │ │ ├── Splay.class.cpp │ │ ├── Stack.class.cpp │ │ ├── Vector.class.cpp │ │ ├── VectorTest.cpp │ │ ├── Vertex.h │ │ ├── a_bubbleSort.cpp │ │ ├── a_convert.cpp │ │ ├── a_evaluate.cpp │ │ ├── a_fib.cpp │ │ ├── a_hailstone.cpp │ │ ├── a_paren.cpp │ │ ├── a_sum.cpp │ │ ├── a_vector.cpp │ │ └── sort.cpp │ ├── graph.md │ ├── hash.md │ ├── list.md │ ├── proqueue.md │ ├── sort.md │ ├── string.md │ ├── sum.md │ ├── superBST.md │ ├── tree.md │ └── vector.md ├── package.json ├── public/ │ └── html/ │ ├── demo-box-model.html │ ├── demo-display.html │ ├── demo-float.html │ ├── demo-position.html │ └── layout.css ├── src/ │ ├── README.md │ ├── algorithm/ │ │ ├── array/ │ │ │ ├── insert.js │ │ │ └── searchInsert.js │ │ ├── search/ │ │ │ └── binsearch.js │ │ ├── sort/ │ │ │ ├── bubblesort.js │ │ │ └── quicksort.js │ │ └── string/ │ │ └── repeat.js │ ├── babel/ │ │ └── tiny-compiler/ │ │ └── index.js │ ├── cryto/ │ │ └── sha256.js │ ├── css/ │ │ ├── box-model.html │ │ ├── center.html │ │ ├── flex.html │ │ ├── float.html │ │ ├── hairline.html │ │ ├── layout.html │ │ ├── three-layout.html │ │ ├── two-layout.html │ │ └── var.html │ ├── data-structure/ │ │ ├── linklist-circle.js │ │ ├── linklist-curd.js │ │ ├── linklist.js │ │ └── list.js │ ├── javascript/ │ │ ├── array.js │ │ ├── async_sync.js │ │ ├── block-scope.js │ │ ├── call.js │ │ ├── callback.js │ │ ├── class/ │ │ │ └── construct.js │ │ ├── class.js │ │ ├── closure/ │ │ │ ├── closure-circle.js │ │ │ └── proxy.js │ │ ├── code/ │ │ │ ├── huiwen-longest-str.js │ │ │ ├── is-huiwen-num.js │ │ │ ├── is-huiwen-string.js │ │ │ ├── longest-asc-str.js │ │ │ ├── longest-norepeat-str.js │ │ │ ├── merge-two-array.js │ │ │ ├── merge-two-lists.js │ │ │ ├── two-nums-2.js │ │ │ ├── two-nums-add.js │ │ │ ├── two-nums.js │ │ │ └── valid-parent.js │ │ ├── curry.js │ │ ├── debounce.js │ │ ├── dom.js │ │ ├── event-loop.js │ │ ├── event.js │ │ ├── flat.js │ │ ├── function-scope.js │ │ ├── function-this.js │ │ ├── hoisting.js │ │ ├── implement/ │ │ │ ├── apply.js │ │ │ ├── async.js │ │ │ ├── bind.js │ │ │ ├── class.js │ │ │ ├── compose.js │ │ │ ├── copy.js │ │ │ ├── inherit.js │ │ │ ├── new.js │ │ │ ├── pipe.js │ │ │ ├── promise.js │ │ │ ├── reduce.js │ │ │ └── sleep.js │ │ ├── inherit.js │ │ ├── map.js │ │ ├── new.js │ │ ├── object/ │ │ │ ├── copy.js │ │ │ ├── enum.js │ │ │ ├── exist.js │ │ │ ├── get-set.js │ │ │ ├── iterator.js │ │ │ ├── property-desciptor.js │ │ │ └── traverse.js │ │ ├── promise.js │ │ ├── proto.js │ │ ├── proxy/ │ │ │ └── base.js │ │ ├── recursion/ │ │ │ └── base.js │ │ ├── regExp.js │ │ ├── scope.js │ │ ├── set/ │ │ │ └── set.js │ │ ├── set.js │ │ ├── sleep.js │ │ ├── string.js │ │ ├── this.js │ │ ├── throttle.js │ │ ├── type.js │ │ └── uniqu.js │ ├── json/ │ │ ├── data.json │ │ ├── distinct_data.json │ │ ├── manage__origin_data.json │ │ ├── manage_cata_data.js │ │ └── manage_cata_data.json │ ├── koa/ │ │ ├── db/ │ │ │ └── index.js │ │ └── index.js │ ├── leetcode/ │ │ ├── 1.两数之和.js │ │ ├── 13.罗马数字转整数.js │ │ ├── 14.最长公共前缀.js │ │ ├── 165.比较版本号.js │ │ ├── 2.两数相加.js │ │ ├── 20.有效的括号.js │ │ ├── 21.合并两个有序链表.js │ │ ├── 26.删除排序数组中的重复项.js │ │ ├── 27.移除元素.js │ │ ├── 28.实现-str-str.js │ │ ├── 3.无重复字符的最长子串.js │ │ ├── 341.扁平化嵌套列表迭代器.js │ │ ├── 35.搜索插入位置.js │ │ ├── 38.外观数列.js │ │ ├── 53.最大子序和.js │ │ ├── 58.最后一个单词的长度.js │ │ ├── 66.加一.js │ │ ├── 67.二进制求和.js │ │ ├── 69.x-的平方根.js │ │ ├── 7.整数反转.js │ │ └── 9.回文数.js │ ├── linux/ │ │ └── process_manage.sh │ ├── node/ │ │ ├── api-test/ │ │ │ └── image.js │ │ ├── app/ │ │ │ ├── index.js │ │ │ ├── requestHandles.js │ │ │ ├── router.js │ │ │ └── server.js │ │ ├── file/ │ │ │ ├── file-download.js │ │ │ └── file-read.js │ │ └── node-fetch/ │ │ └── index.js │ ├── question/ │ │ └── interserction.js │ ├── react/ │ │ ├── app/ │ │ │ ├── .gitignore │ │ │ ├── README.md │ │ │ ├── package.json │ │ │ ├── public/ │ │ │ │ ├── index.html │ │ │ │ ├── manifest.json │ │ │ │ └── robots.txt │ │ │ └── src/ │ │ │ ├── antd/ │ │ │ │ ├── searchDemo.js │ │ │ │ └── upload.js │ │ │ ├── antd-mobile/ │ │ │ │ ├── input.js │ │ │ │ ├── picker-demo.js │ │ │ │ ├── steps-demo.js │ │ │ │ └── steps-demo.scss │ │ │ ├── assets/ │ │ │ │ ├── font/ │ │ │ │ │ └── PingFangSC-Regular.fft │ │ │ │ └── scss/ │ │ │ │ └── font.scss │ │ │ ├── components/ │ │ │ │ ├── count-down.js │ │ │ │ ├── steps-hooks.js │ │ │ │ ├── steps.js │ │ │ │ └── steps.scss │ │ │ ├── examples/ │ │ │ │ └── steps-demo.js │ │ │ ├── font/ │ │ │ │ └── pingfangsc-demo.js │ │ │ ├── index.js │ │ │ ├── paratice/ │ │ │ │ ├── hook.js │ │ │ │ ├── index.css │ │ │ │ ├── index.js │ │ │ │ └── lasy-compontent.js │ │ │ ├── redux.js │ │ │ ├── router/ │ │ │ │ ├── index.js │ │ │ │ └── index.scss │ │ │ ├── serviceWorker.js │ │ │ └── setupTests.js │ │ ├── demo.html │ │ └── demo.jsx │ ├── shell/ │ │ └── image_filter.sh │ ├── typescript/ │ │ ├── js/ │ │ │ ├── class-demo.js │ │ │ ├── decorators-demo.js │ │ │ ├── demo.js │ │ │ ├── fn-demo.js │ │ │ ├── function-demo.js │ │ │ ├── generics-demo.js │ │ │ ├── interface-demo.js │ │ │ ├── overload-demo.js │ │ │ ├── type-advanced-demo.js │ │ │ ├── type-demo.js │ │ │ └── type-inference-demo.js │ │ └── ts/ │ │ ├── class-demo.ts │ │ ├── decorators-demo.ts │ │ ├── demo.ts │ │ ├── function-demo.ts │ │ ├── generics-demo.ts │ │ ├── interface-demo.ts │ │ ├── overload-demo.ts │ │ ├── tsconfig.json │ │ ├── type-advanced-demo.ts │ │ ├── type-demo.ts │ │ └── type-inference-demo.ts │ ├── web-api/ │ │ ├── localstorage.js │ │ └── sessionstorage.js │ └── webpack/ │ └── simple-webpack/ │ ├── buddle.js │ └── example/ │ ├── entry.js │ ├── message.js │ └── name.js └── yarn-error.log
SYMBOL INDEX (513 symbols across 223 files)
FILE: articals/c/Demo/bug1.c
function main (line 3) | int main(){
function alpha (line 13) | int alpha(char ch){
FILE: articals/c/Demo/test.c
function main (line 7) | int main(){
FILE: articals/c/Demo/test10.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test11.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test12.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test13.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test14.c
function main (line 4) | int main(){
FILE: articals/c/Demo/test15.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test16.c
function main (line 7) | int main(){
FILE: articals/c/Demo/test17.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test18.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test19.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test2.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test20.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test21.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test22.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test23.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test24.c
function main (line 4) | int main(){
FILE: articals/c/Demo/test25.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test26.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test27.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test28.c
function main (line 4) | int main(){
FILE: articals/c/Demo/test29.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test3.c
function main (line 6) | int main(){
function jolly (line 14) | void jolly(){
function deny (line 17) | void deny(){
FILE: articals/c/Demo/test30.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test31.c
function main (line 3) | int main(){
function thr (line 10) | void thr(int n){
FILE: articals/c/Demo/test32.c
function main (line 3) | int main(){
function resmode (line 13) | void resmode(int first, int second){
FILE: articals/c/Demo/test33.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test34.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test35.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test36.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test37.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test38.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test39.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test4.c
function main (line 6) | int main(){
function br (line 16) | void br(){
function ic (line 19) | void ic(){
FILE: articals/c/Demo/test40.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test41.c
function main (line 3) | int main(){
function addff (line 11) | float addff(float f1, float f2){
FILE: articals/c/Demo/test42.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test43.c
function main (line 4) | int main()
function swap (line 26) | void swap(int *a, int *b)
FILE: articals/c/Demo/test44.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test45.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test46.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test47.c
function main (line 4) | int main(){
FILE: articals/c/Demo/test48.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test49.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test5.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test50.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test51.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test52.c
function main (line 7) | int main(){
FILE: articals/c/Demo/test53.c
function main (line 6) | int main(){
FILE: articals/c/Demo/test54.c
function main (line 5) | int main(){
function _Bool (line 17) | _Bool isPrime(int n){
FILE: articals/c/Demo/test55.c
function main (line 5) | int main(){
function menu (line 25) | void menu(){
FILE: articals/c/Demo/test56.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test57.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test58.c
function main (line 3) | int main(){
function dealSpecial (line 15) | void dealSpecial(char sp){
FILE: articals/c/Demo/test59.c
function main (line 3) | int main(){
FILE: articals/c/Demo/test6.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test60.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test61.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test62.c
function main (line 6) | int main(){
function count (line 28) | void count(){
function get_int (line 40) | int get_int(){
function get_first (line 51) | char get_first(){
function get_choice (line 59) | char get_choice(){
FILE: articals/c/Demo/test63.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test64.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test65.c
function main (line 3) | int main(void){
function show (line 10) | void show(char a, int b, int c) {
FILE: articals/c/Demo/test66.c
function main (line 3) | int main(){
function avg (line 9) | double avg(double a, double b){
FILE: articals/c/Demo/test67.c
function main (line 3) | int main(void){
function large_of (line 10) | void large_of(double *a, double *b){
FILE: articals/c/Demo/test68.c
function main (line 4) | int main(void){
function order (line 11) | void order(double *a, double *b, double *c){
function swap (line 17) | void swap(double *m, double *n){
FILE: articals/c/Demo/test69.c
function main (line 3) | int main(){
function power (line 10) | double power(double n, int c){
FILE: articals/c/Demo/test7.c
function main (line 3) | int main(){
function smile (line 13) | void smile(){
FILE: articals/c/Demo/test70.c
function main (line 3) | int main(){
function power (line 10) | double power(double n, int c){
FILE: articals/c/Demo/test71.c
function main (line 3) | int main(void){
function to_base_n (line 9) | void to_base_n(int x, int n){
FILE: articals/c/Demo/test72.c
function main (line 4) | int main(void){
function fibonacciRec (line 11) | int fibonacciRec(int n){
function fibonacci (line 17) | int fibonacci(int n){
FILE: articals/c/Demo/test73.c
function main (line 7) | int main(void){
function cp_arr (line 21) | void cp_arr(double target[], const double source[], int n){
function cp_ptr (line 28) | void cp_ptr(double target[], const double *source, int n){
function cp_ptrs (line 35) | void cp_ptrs(double target[], const double *source_start, const double *...
function show_arr (line 41) | void show_arr(double a[], int n){
FILE: articals/c/Demo/test74.c
function main (line 6) | int main(void){
function sort (line 12) | void sort(double a[], int n){
function swap (line 19) | void swap(double *p, double *q){
function show_arr (line 24) | void show_arr(const double a[], int n){
FILE: articals/c/Demo/test75.c
function main (line 8) | int main(void){
function cp_arr (line 15) | void cp_arr(double target[], const double source[], int n){
function cp2_arr2 (line 22) | void cp2_arr2(double tgt[][COLS], const double src[][COLS], int rows){
function show_arr2 (line 27) | void show_arr2(const double a[][COLS], int rows){
FILE: articals/c/Demo/test76.c
function main (line 8) | int main(void){
function cp_arr (line 22) | void cp_arr(double target[], const double source[], int m){
function cp_ptr (line 29) | void cp_ptr(double target[], const double *source, int m){
function cp_ptrs (line 36) | void cp_ptrs(double target[], const double *source_start, const double *...
function show_arr (line 42) | void show_arr(double a[], int n){
FILE: articals/c/Demo/test77.c
function main (line 3) | int main(void){
function show_vla (line 15) | void show_vla(int rows, int cols, double arr[rows][cols]){
FILE: articals/c/Demo/test78.c
function main (line 7) | int main(void){
function perYearFall (line 19) | void perYearFall(const double a[][MONTH], int year){
function perMonthFall (line 33) | void perMonthFall(const double a[][MONTH], int year){
FILE: articals/c/Demo/test79.c
function main (line 11) | int main(void){
function getArr (line 24) | void getArr(double a[][COLS], int rows){
function averageGroup (line 31) | void averageGroup(double b[], const double a[][COLS], int rows){
function average (line 41) | double average(const double a[][COLS], int rows){
function max (line 50) | double max(double a[][COLS], int rows){
function show (line 64) | void show(double a[], int size, double av, double m){
function swap (line 73) | void swap(double *p, double *q){
FILE: articals/c/Demo/test8.c
function main (line 4) | int main(){
function one_three (line 10) | void one_three(){
function two (line 15) | void two(){
FILE: articals/c/Demo/test80.c
function main (line 2) | int main(void){
FILE: articals/c/Demo/test81.c
function main (line 4) | int main(void){
function getStr (line 10) | void getStr(char * a, int n){
FILE: articals/c/Demo/test82.c
function main (line 4) | int main(void){
function getStr (line 10) | void getStr(char * a, int n) {
FILE: articals/c/Demo/test83.c
function main (line 4) | int main(void){
function reStr (line 12) | void reStr(char * a, int n){
FILE: articals/c/Demo/test84.c
function main (line 2) | int main(void){
FILE: articals/c/Demo/test85.c
function main (line 4) | int main(void){
FILE: articals/c/Demo/test86.c
function main (line 2) | int main(int argc, char * argv[]){
FILE: articals/c/Demo/test88.c
function main (line 7) | int main(int argc, char * argv[]){
function pf (line 18) | void pf(char * a, int n){
function toLower (line 25) | void toLower(char * a, int n){
function toUpper (line 37) | void toUpper(char * a, int n){
FILE: articals/c/Demo/test89.c
function main (line 4) | int main(){
function critic (line 11) | void critic(int u){
FILE: articals/c/Demo/test9.c
function main (line 2) | int main(){
FILE: articals/c/Demo/test90.c
function main (line 2) | int main(void){
FILE: articals/c/Demo/test91.c
function set_mode (line 2) | void set_mode(int mode){
function get_info (line 8) | void get_info(void){
function show_info (line 12) | void show_info(void){
FILE: articals/c/Demo/test92.c
function main (line 4) | int main(){
function a (line 9) | int a(void){
FILE: articals/c/Demo/test94.c
function main (line 7) | int main(){
function rand1 (line 17) | int rand1(int n){
function count (line 21) | void count( const int *a, int n){
FILE: articals/c/Demo/test95.c
function main (line 8) | int main(){
function rand1 (line 21) | int rand1(int n){
function sort (line 25) | void sort(int *a, int n){
function show (line 35) | void show( const int *a, int n){
FILE: articals/c/Demo/test96.c
function get_n (line 4) | int get_n(){
function show (line 11) | void show(char * a[], int n){
function main (line 17) | int main(void){
FILE: articals/c/Demo/test97.c
function main (line 4) | int main(int argc, char * argv[]){
FILE: articals/c/Demo/test98.c
function main (line 5) | int main(){
FILE: articals/c/Demo/testDice_d.c
function main (line 5) | int main(void){
FILE: articals/c/Demo/testFgets.c
function main (line 2) | int main(void){
FILE: articals/c/Demo/testFgets2.c
function main (line 3) | int main(void){
FILE: articals/c/Demo/testFgets3.c
function main (line 3) | int main(){
FILE: articals/c/Demo/testFileIO.c
function main (line 2) | int main(){
FILE: articals/c/Demo/testGets.c
function main (line 2) | int main(void){
FILE: articals/c/Demo/testIO.c
function main (line 3) | int main(int argc, char * argv[]){
FILE: articals/c/Demo/testP02.c
function main (line 3) | int main(){
FILE: articals/c/Demo/testPntAdd.c
function main (line 3) | int main(){
FILE: articals/c/Demo/testPo.c
function sum (line 3) | int sum(int * start, int * end){
function main (line 13) | int main(void){
FILE: articals/c/Demo/testPoint.c
function main (line 3) | int main(void){
function arr (line 9) | int arr(int n){
FILE: articals/c/Demo/testPrintfScanf.c
function main (line 2) | int main(){
FILE: articals/c/Demo/testR_d.c
function main (line 4) | int main(void){
FILE: articals/c/Demo/testRand.c
function rand0 (line 3) | unsigned int rand0(void){
function changeNext (line 7) | void changeNext(unsigned int seed){
FILE: articals/c/Demo/testRandom.c
function rollem (line 14) | int rollem(int sides){
function roll_n_dice (line 20) | int roll_n_dice(int dice, int sides){
FILE: articals/c/Demo/testRecursion.c
function main (line 3) | int main(void){
function up_and_down (line 7) | int up_and_down(int n){
FILE: articals/c/Demo/testReducto.c
function main (line 5) | int main(int argc, char * argv[]){
FILE: articals/c/Demo/testScope.c
function main (line 2) | int main(void){
FILE: articals/c/Demo/testStrSort.c
function main (line 9) | int main(void){
function strSort (line 23) | void strSort(char * str [], int num){
FILE: articals/c/Demo/testSwap.c
function main (line 3) | int main(void){
function swap (line 9) | void swap(int *p, int * q){
FILE: articals/c/Demo/testToBinary.c
function main (line 3) | int main(void){
function to_binary (line 10) | void to_binary(int n){
FILE: booknotes/demo/AVL.class.cpp
class AVL (line 4) | class AVL: public BST<T> {
FILE: booknotes/demo/BST.class.cpp
class BST (line 1) | class BST: public public BinTree<T> {
function searchIn (line 19) | static BinNodePosi(T) & searchIn(BinNodePosi(T) & v, const T & e, BinN...
function BinNodePosi (line 27) | BinNodePosi(T) BST<T>:: insert(const T & e) {
FILE: booknotes/demo/BinTree.class.cpp
class BinTree (line 2) | class BinTree {
method size (line 9) | int size() const { return _size; }
method empty (line 10) | bool empty() const { return _root; }
method BinNodePosi (line 11) | BinNodePosi(T) root() const { return _root; }
function BinNodePosi (line 28) | BinNodePosi(T) BinTree<T>::insertAsRC( BinNodePosi(T) x, T const &e){
function traverse (line 35) | void traverse( BinNodePosi(T) x, VST & visit) {
function travPre_I1 (line 43) | void travPre_I1( BinNodePosi(T) x, VST & visit) {
function travPre_I2 (line 57) | void travPre_I2( BinNodePosi(T) x, VST & visit ) {
function visitAlongLeftBranch (line 67) | static void visitAlongLeftBranch( BinNodePosi(T) x, VST & visit, Stack<B...
function traverse (line 75) | void traverse( BinNodePosi(T) x, VST & visit) {
function travPre_I2 (line 83) | void travPre_I2( BinNodePosi(T) x, VST & visit ) {
function goAlongLeftBranch (line 95) | static void goAlongLeftBranch( BinNodePosi(T) x, VST & visit, Stack<BinN...
function traverse (line 102) | void traverse( VST & visit) {
FILE: booknotes/demo/Edge.h
type EStatus (line 1) | typedef enum { UNDETERMINED, TREE, CROSS, FORWORD, BACKWAED } EStatus;
FILE: booknotes/demo/Graph.class.cpp
class Graph (line 1) | class Graph {
method reset (line 3) | void reset() {
FILE: booknotes/demo/GraphMatrix.class.cpp
class GraphMatrix (line 1) | class GraphMatrix : public Graph<Tv, Te> {
method GraphMatrix (line 7) | GraphMatrix() { n = e = 0;}
method Tv (line 14) | Tv & Vertex(int i) { return V[i].data }
method NextNbr (line 17) | int NextNbr(int i, int j) {
method firstNbr (line 22) | int firstNbr(int i) {
method insert (line 26) | int insert(Tv const & vertex) {
method Tv (line 34) | Tv remove(int i) {
method exists (line 52) | bool exists(int i, int j) {
method Te (line 55) | Te & edge(int i, int j) {
method insert (line 60) | void insert( Te const& edge, int w, int i, int j) {
method Te (line 69) | Te remove(int i, int j) {
FILE: booknotes/demo/Lcs.cpp
function main (line 18) | int main(void){
function LCS (line 26) | int LCS(string a, int m, string b, int n){
function LCS2 (line 37) | int LCS2(string a, int m, string b, int n){
FILE: booknotes/demo/List.class.cpp
class List (line 2) | class List {
function T (line 27) | T List<T>::operator[](Rank r) const {
function Posi (line 35) | Posi(T) List<T>::find(T const &e, int n, Posi(n) p) const {
function Posi (line 42) | Posi(T) List<T>::insertBefore(Posi(T) p, T const & e) { //O(1)
function Posi (line 46) | Posi(T) ListNode<T>::insertAsPred(T const & e) {
function T (line 61) | T List<T>::remove(Posi(T) p) { //O(1)
function Posi (line 109) | Posi(T) List<T>::search(T const &e, int n, Posi(T) p) const {
function Posi (line 128) | Posi(T) List<T>::selectMax(Posi(T) p, int n) {
FILE: booknotes/demo/PQ.class.cpp
type PQ (line 1) | struct PQ{
FILE: booknotes/demo/PQ_ComplHeap.class.cpp
class PQ_ComplHeap (line 1) | class PQ_ComplHeap : public PQ<T> , public Vector<T> {
method PQ_ComplHead (line 7) | PQ_ComplHead( T* A, Rank n) { copyFrom(A, 0, n); heapify(n); }
method T (line 10) | T getMax() { return _elem[0]; }
FILE: booknotes/demo/Queue.class.cpp
class Queue (line 1) | class Queue : public List<T>{
method enqueue (line 3) | void enqueue(T const &e) { insertAsLast(e); }
method T (line 4) | T dequeue() { return remove( first() ); }
method T (line 5) | T & front() { return first()->data; }
FILE: booknotes/demo/RedBlack.class.cpp
class RedBlack (line 1) | class RedBlack: public BST<T> {
FILE: booknotes/demo/SList.class.cpp
class SList (line 2) | class SList {
FILE: booknotes/demo/Splay.class.cpp
class Splay (line 1) | class Splay : public BST<T> {
FILE: booknotes/demo/Stack.class.cpp
class Stack (line 1) | class Stack :public Vector<T> {
method push (line 3) | void push(T const & e) { insert(size(), e); }
method T (line 4) | T pop() { return remove( size() -1 ); }
method T (line 5) | T & top() { return (*this)[ size() - 1]; }
FILE: booknotes/demo/Vector.class.cpp
class Vector (line 3) | class Vector{
method Vector (line 12) | Vector(int c = DEFAULT_CAPACITY){ _elem = new T[_capacity = c]; _size ...
method Vector (line 13) | Vector(T const *A, Rank lo, Rank hi) { copyFrom(A, lo, hi); }
method Vector (line 14) | Vector(Vector<T> const& V, Rank lo, Rank hi) { copyFrom(V._elem, lo, h...
method Vector (line 15) | Vector(Vector<T> const& V) { copyFrom(V._elem, 0, V._size); }
function Rank (line 45) | Rank Vector<T>::insert(Rank r, T const & e) {
function T (line 64) | T Vector<T>::remove(Rank r) {
function Rank (line 70) | Rank Vector<T>::find(T const & e, Rank lo, Rank hi) const {
function Rank (line 118) | static Rank binSearch(T * A, T const &e, Rank lo, Rank hi) {
function Rank (line 128) | static Rank binSearch(T * A, T const &e, Rank lo, Rank hi) {
function Rank (line 136) | static Rank binSearch(T * A, T const &e, Rank lo, Rank hi) {
function Rank (line 144) | static Rank fibSearch(T * A, T const &e, Rank lo, Rank hi) {
function Rank (line 186) | Rank Vector<T>::bubble(Rank lo, Rank hi) {
FILE: booknotes/demo/VectorTest.cpp
function main (line 7) | int main() {
FILE: booknotes/demo/Vertex.h
type VStatus (line 1) | typedef enum { UNDISCOVERED, DISCOVERED, VISITED} VStatus;
FILE: booknotes/demo/a_bubbleSort.cpp
function bubblesort (line 4) | void bubblesort(int A[], int n){
function main (line 12) | int main(){
FILE: booknotes/demo/a_convert.cpp
function convert (line 6) | void convert( Stack<char> & S, __int64 n, int base) {
function main (line 13) | int main() {
FILE: booknotes/demo/a_evaluate.cpp
function evaluate (line 8) | float evaluate(char * s, char * & RPN) {
FILE: booknotes/demo/a_fib.cpp
function fib (line 3) | int fib(int n){
function fib2 (line 7) | int fib2(int n){
function main (line 15) | int main(void){
FILE: booknotes/demo/a_hailstone.cpp
function hailstone (line 6) | int hailstone(int n) {
function main (line 14) | int main(){
FILE: booknotes/demo/a_paren.cpp
function paren (line 4) | bool paren(const char exp[], int lo, int hi) {
function main (line 15) | int main(void) {
FILE: booknotes/demo/a_sum.cpp
function SumI (line 3) | int SumI(int A[], int n){
function SumJ (line 11) | int SumJ(int A[], int n){
function sum (line 14) | int sum(int A[], int lo, int hi){
function main (line 19) | int main(){
FILE: booknotes/demo/a_vector.cpp
function main (line 5) | int main(void){
FILE: booknotes/demo/sort.cpp
function Rank (line 7) | Rank Vector<T>::partition( Rank lo, Rank hi) {
FILE: src/algorithm/array/insert.js
function insert (line 8) | function insert(arr, targetIndex, target) {
FILE: src/algorithm/search/binsearch.js
function binSearch (line 5) | function binSearch(target, arr) {
FILE: src/algorithm/sort/bubblesort.js
function bubble (line 8) | function bubble(arr) {
FILE: src/algorithm/string/repeat.js
function repeat (line 1) | function repeat(o, n) {
FILE: src/babel/tiny-compiler/index.js
function tokenizer (line 6) | function tokenizer(input) {
function parsing (line 105) | function parsing(tokens) {
function traverse (line 169) | function traverse(ast, visitor) {
function transformer (line 209) | function transformer(ast) {
function codeGenerator (line 265) | function codeGenerator(node) {
function compiler (line 288) | function compiler(input) {
FILE: src/data-structure/linklist.js
function ListNode (line 2) | function ListNode(val) {
function create (line 13) | function create(arr) {
function get (line 27) | function get(list, index) {
function insertAt (line 43) | function insertAt(list, index, el) {
function deleteAt (line 56) | function deleteAt(list, index) {
FILE: src/data-structure/list.js
function ListNode (line 2) | function ListNode(val) {
FILE: src/javascript/array.js
function flat (line 8) | function flat(array) {
FILE: src/javascript/call.js
method a (line 3) | a() {
function d (line 10) | function d(a, b) {
FILE: src/javascript/callback.js
function A (line 2) | function A() {
function B (line 6) | function B(callback) {
function C (line 13) | function C(callback) {
FILE: src/javascript/class/construct.js
function FakeClass (line 1) | function FakeClass(val) {
FILE: src/javascript/closure/proxy.js
function dos (line 1) | function dos() {
FILE: src/javascript/code/huiwen-longest-str.js
function solve (line 7) | function solve(s) {
FILE: src/javascript/code/is-huiwen-num.js
function solve (line 12) | function solve(x) {
FILE: src/javascript/code/is-huiwen-string.js
function solve (line 7) | function solve(s) {
FILE: src/javascript/code/longest-asc-str.js
function longestAseStr (line 1) | function longestAseStr() {}
FILE: src/javascript/code/longest-norepeat-str.js
function solve (line 16) | function solve(s) {
FILE: src/javascript/code/merge-two-array.js
function mergeTwoArray (line 1) | function mergeTwoArray(l1, l2) {
FILE: src/javascript/code/merge-two-lists.js
function mergeTwoLists (line 12) | function mergeTwoLists(l1, l2) {
FILE: src/javascript/code/two-nums-2.js
function twoNums (line 1) | function twoNums(nums, target) {
FILE: src/javascript/code/two-nums-add.js
function twoNumsAdd (line 3) | function twoNumsAdd(l1, l2) {
FILE: src/javascript/code/two-nums.js
function twoNums (line 1) | function twoNums(nums, target) {
FILE: src/javascript/code/valid-parent.js
function validParent (line 5) | function validParent(s) {
FILE: src/javascript/curry.js
function curry (line 2) | function curry(fn, len = fn.length) {
function _curry (line 6) | function _curry(fn, len, ...args) {
FILE: src/javascript/debounce.js
function debounce (line 4) | function debounce(fn, intervalTime) {
function task (line 16) | function task() {
FILE: src/javascript/flat.js
function flat (line 6) | function flat(origin) {
function reduce_flat (line 18) | function reduce_flat(origin) {
FILE: src/javascript/function-scope.js
function foo (line 11) | function foo() {
FILE: src/javascript/function-this.js
function b (line 1) | function b() {
FILE: src/javascript/hoisting.js
function a (line 8) | function a() {
function a (line 13) | function a() {}
FILE: src/javascript/implement/bind.js
function test (line 22) | function test(b) {
FILE: src/javascript/implement/sleep.js
function sleep (line 1) | function sleep(ms) {
function test (line 6) | async function test() {
FILE: src/javascript/inherit.js
function Base (line 10) | function Base() {
function PrototypeListInherit (line 22) | function PrototypeListInherit() {
function ConstructInherit (line 34) | function ConstructInherit() {
function ComposeInherit (line 48) | function ComposeInherit() {
function PrototypeInherit (line 61) | function PrototypeInherit() {}
FILE: src/javascript/new.js
function A (line 1) | function A() {
FILE: src/javascript/object/copy.js
function shadowCopy (line 25) | function shadowCopy(origin) {
function isObject (line 33) | function isObject(origin) {
function deepCopy (line 37) | function deepCopy(origin, map = new Map()) {
FILE: src/javascript/object/get-set.js
method b (line 7) | get b() {
method c (line 11) | get c() {
method c (line 15) | set c(val) {
FILE: src/javascript/promise.js
constant PENDING (line 1) | const PENDING = 'pending'
constant FULFILLED (line 2) | const FULFILLED = 'fulfilled'
constant REJECTED (line 3) | const REJECTED = 'rejected'
function Promise (line 4) | function Promise() {
function resolvePromise (line 39) | function resolvePromise() {}
FILE: src/javascript/proto.js
function B (line 5) | function B() {}
FILE: src/javascript/recursion/base.js
function speed (line 2) | function speed(n, callback) {
function recursion (line 10) | function recursion(n) {
function feibulaqi (line 24) | function feibulaqi(n) {
function jumpStep (line 39) | function jumpStep(n) {
function Node (line 54) | function Node() {
function recursionReduce (line 64) | function recursionReduce(n) {
function febulaqi2 (line 77) | function febulaqi2(n) {
FILE: src/javascript/scope.js
function a (line 1) | function a() {
FILE: src/javascript/set.js
function intersection (line 10) | function intersection(s1, s2) {
FILE: src/javascript/set/set.js
function intersection (line 10) | function intersection(s1, s2) {
FILE: src/javascript/sleep.js
function sleep (line 1) | function sleep(milliseconds) {
FILE: src/javascript/throttle.js
function throttle (line 4) | function throttle(fn, wait) {
function throttle (line 16) | function throttle(fn, wait) {
FILE: src/javascript/uniqu.js
function set_uniqu (line 2) | function set_uniqu(array) {
function filter_uniqu (line 6) | function filter_uniqu(array) {
function filter_map_uniqu (line 10) | function filter_map_uniqu(array) {}
function reduce_uniqu (line 11) | function reduce_uniqu(array) {
FILE: src/node/app/requestHandles.js
function start (line 6) | function start(response, request) {
function upload (line 26) | function upload(response, request) {
function show (line 44) | function show(response, request) {
FILE: src/node/app/router.js
function route (line 1) | function route(pathname, handles, response, request) {
FILE: src/node/app/server.js
function createServer (line 4) | function createServer(route, handles) {
FILE: src/question/interserction.js
function set_intersection (line 1) | function set_intersection(set1, set2) {
function intersection (line 15) | function intersection(nums1, nums2) {
FILE: src/react/app/src/antd-mobile/picker-demo.js
class AMPicker (line 57) | class AMPicker extends React.Component {
method render (line 59) | render() {
FILE: src/react/app/src/antd-mobile/steps-demo.js
class StepsDemo (line 6) | class StepsDemo extends React.Component {
method render (line 7) | render() {
FILE: src/react/app/src/antd/searchDemo.js
function ImagePickerDemo (line 4) | function ImagePickerDemo() {
FILE: src/react/app/src/antd/upload.js
class UploadDemo (line 6) | class UploadDemo extends React.Component {
method onImageClick (line 7) | async onImageClick(files) {
method render (line 34) | render() {
FILE: src/react/app/src/components/count-down.js
function CountDown (line 4) | function CountDown(props) {
FILE: src/react/app/src/components/steps.js
class Steps (line 46) | class Steps extends React.Component {
method constructor (line 47) | constructor(props) {
method componentDidMount (line 54) | componentDidMount() {
method render (line 76) | render() {
FILE: src/react/app/src/examples/steps-demo.js
function stepsDemo (line 46) | function stepsDemo() {
FILE: src/react/app/src/font/pingfangsc-demo.js
function PingFangScDemo (line 3) | function PingFangScDemo() {
FILE: src/react/app/src/paratice/hook.js
class Hook (line 3) | class Hook extends React.Component {
method render (line 4) | render() {
function HookExample (line 13) | function HookExample() {
FILE: src/react/app/src/paratice/index.js
function filterShao (line 8) | function filterShao(str) {
function CreatEl (line 14) | function CreatEl(props) {
class Clock (line 30) | class Clock extends React.Component {
method constructor (line 31) | constructor(props) {
method componentDidMount (line 35) | componentDidMount() {
method componentWillUnmount (line 38) | componentWillUnmount() {
method tick (line 41) | tick() {
method render (line 46) | render() {
class FormDemo (line 52) | class FormDemo extends React.Component {
method constructor (line 53) | constructor(props) {
method render (line 79) | render() {
class EventHandles (line 103) | class EventHandles extends React.Component {
method constructor (line 104) | constructor() {
method render (line 116) | render() {
function BoilingVerdict (line 125) | function BoilingVerdict(props) {
class TemperatureInput (line 136) | class TemperatureInput extends React.Component {
method constructor (line 137) | constructor(props) {
method render (line 147) | render() {
class Calculator (line 160) | class Calculator extends React.Component {
method constructor (line 161) | constructor(props) {
method render (line 180) | render() {
function toFahrenheit (line 200) | function toFahrenheit(fahrenheit) {
function toCelsius (line 204) | function toCelsius(celsius) {
function tryConvert (line 208) | function tryConvert(temperature, convert) {
function Child (line 219) | function Child() {
function ComposeCompontent (line 223) | function ComposeCompontent() {
function PropsComponent (line 227) | function PropsComponent(props) {
class Toolbar (line 243) | class Toolbar extends React.Component {
method render (line 247) | render() {
class ThemeButton (line 252) | class ThemeButton extends React.Component {
method render (line 253) | render() {
class Button (line 257) | class Button extends React.Component {
method render (line 262) | render() {
class ErrorBoundary (line 289) | class ErrorBoundary extends React.Component {
method componentDidCatch (line 294) | componentDidCatch(error, errorInfo) {
method render (line 298) | render() {
function App (line 306) | function App() {
FILE: src/react/app/src/paratice/lasy-compontent.js
function LasyCompontent (line 3) | function LasyCompontent() {
FILE: src/react/app/src/router/index.js
function RouterDOM (line 15) | function RouterDOM() {
FILE: src/react/app/src/serviceWorker.js
function register (line 23) | function register(config) {
function registerValidSW (line 57) | function registerValidSW(swUrl, config) {
function checkValidServiceWorker (line 101) | function checkValidServiceWorker(swUrl, config) {
function unregister (line 131) | function unregister() {
FILE: src/typescript/js/class-demo.js
function __ (line 11) | function __() { this.constructor = d; }
function Person (line 23) | function Person(name) {
function Child (line 36) | function Child(name) {
function Person2 (line 49) | function Person2(name) {
function Animal (line 68) | function Animal() {
function Cat (line 77) | function Cat() {
FILE: src/typescript/js/decorators-demo.js
function __ (line 11) | function __() { this.constructor = d; }
function Age (line 22) | function Age(v) {
function CatCat (line 37) | function CatCat() {
FILE: src/typescript/js/fn-demo.js
function add (line 2) | function add(num1, num2) {
FILE: src/typescript/js/function-demo.js
function add (line 2) | function add(num1, num2) {
FILE: src/typescript/js/generics-demo.js
function getData1 (line 9) | function getData1(val) {
function getData2 (line 12) | function getData2(val) {
function getData (line 15) | function getData(val) {
function PersonAny (line 21) | function PersonAny(name, age) {
function PersonClassAny (line 34) | function PersonClassAny(name) {
FILE: src/typescript/js/interface-demo.js
function ajax (line 7) | function ajax(config) {
function PersonClass (line 16) | function PersonClass() {
function ChildClass (line 25) | function ChildClass(name) {
FILE: src/typescript/js/overload-demo.js
function overload (line 2) | function overload(a) {
FILE: src/typescript/js/type-advanced-demo.js
function extend (line 9) | function extend(first, second) {
function PersonIntersect (line 22) | function PersonIntersect(name) {
function ConsoleLoggable (line 29) | function ConsoleLoggable() {
FILE: src/typescript/ts/class-demo.ts
class Person (line 2) | class Person {
method constructor (line 4) | constructor(name: string) {
method run (line 7) | run(): string {
class Child (line 16) | class Child extends Person {
method constructor (line 17) | constructor(name: string) {
method study (line 20) | study(): string {
class Person2 (line 31) | class Person2 {
method constructor (line 33) | constructor(name: string) {
method active (line 37) | static active() {
method run (line 41) | run(): string {
method run (line 53) | run(): string {
class Cat (line 59) | class Cat extends Animal {
method eat (line 60) | eat(): string {
FILE: src/typescript/ts/decorators-demo.ts
function Age (line 2) | function Age(v: number) {
class CatCat (line 11) | @Age(1)
FILE: src/typescript/ts/function-demo.ts
function add (line 1) | function add(num1: number, num2: number): number {
FILE: src/typescript/ts/generics-demo.ts
function getData1 (line 2) | function getData1(val: string): string {
function getData2 (line 6) | function getData2(val: number): number {
function getData (line 10) | function getData<T>(val: T): T {
class PersonAny (line 16) | class PersonAny<T> {
method constructor (line 17) | constructor(name: T, age: T) {
method run (line 23) | run(val: T): T {
type PersonInfoAny (line 32) | interface PersonInfoAny {
type PersonInfoAny2 (line 37) | interface PersonInfoAny2<T> {
type PersonInterfaceAny (line 43) | interface PersonInterfaceAny<T> {
class PersonClassAny (line 48) | class PersonClassAny implements PersonInterfaceAny<string> {
method constructor (line 50) | constructor(name: string) {
method run (line 53) | run(val: string) {
FILE: src/typescript/ts/interface-demo.ts
type PersonInfo (line 2) | interface PersonInfo {
type Config (line 16) | interface Config {
function ajax (line 22) | function ajax(config: Config) {
type kv (line 30) | interface kv {
type UserArr (line 37) | interface UserArr {
type UserObj (line 40) | interface UserObj {
type PersonInterface (line 47) | interface PersonInterface {
class PersonClass (line 52) | class PersonClass implements PersonInterface {
method constructor (line 54) | constructor() {
method run (line 57) | run() {
type ChildInterface (line 63) | interface ChildInterface extends PersonInterface {
class ChildClass (line 67) | class ChildClass implements ChildInterface {
method constructor (line 69) | constructor(name: string) {
method run (line 72) | run() {
method cry (line 75) | cry() {
FILE: src/typescript/ts/overload-demo.ts
function overload (line 4) | function overload(a: any): string {
FILE: src/typescript/ts/type-advanced-demo.ts
function extend (line 2) | function extend<T, U>(first: T, second: U): T & U {
class PersonIntersect (line 15) | class PersonIntersect {
method constructor (line 16) | constructor(public name: string) {}
type Loggable (line 18) | interface Loggable {
class ConsoleLoggable (line 21) | class ConsoleLoggable implements Loggable {
method log (line 22) | log() {
FILE: src/typescript/ts/type-demo.ts
type Flag (line 14) | enum Flag {
FILE: src/webpack/simple-webpack/buddle.js
function createAssets (line 9) | function createAssets(filename) {
function createGraph (line 39) | function createGraph(entry) {
function buddle (line 61) | function buddle(graph) {
Condensed preview — 389 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,182K chars).
[
{
"path": ".gitattributes",
"chars": 282,
"preview": "*.js linguist-language=JavaScript\n*.css linguist-language=JavaScript\n*.html linguist-language=JavaScript\n*.c linguist-la"
},
{
"path": ".gitignore",
"chars": 29,
"preview": "/node_modules\n/json\nprivate-*"
},
{
"path": ".vscode/launch.json",
"chars": 171,
"preview": "{\n \"version\": \"0.2.0\",\n \"configurations\": [\n {\n \"type\": \"node\",\n \"request\": \"launch\",\n \"name\": \"Laun"
},
{
"path": "README.md",
"chars": 34236,
"preview": " :rocket: _It's my records of the journey from phper to fronter, now sharing to you and hoping that these make sence for"
},
{
"path": "articals/c/Demo/bug1.c",
"chars": 448,
"preview": "#include <stdio.h>\nint alpha(char);\nint main(){\n\tchar ch;\n\twhile( (ch = getchar()) != EOF ) {\n\t\tprintf(\"location: %d\\n\","
},
{
"path": "articals/c/Demo/mywords",
"chars": 64,
"preview": "5.3 6.2 3.6 5.6 7.9\n5.6 3.9 1.5 6.9 4.8\n4.1 56.6 23.7 56.1 18.6 "
},
{
"path": "articals/c/Demo/test.c",
"chars": 212,
"preview": "#include <stdio.h>\n/**\n * @return\n * @Author Suoyue\n * @DateTime 2017-08-21\n */\nint main(){\n\tprintf(\"shao suo\\n\");\n\tpr"
},
{
"path": "articals/c/Demo/test10.c",
"chars": 85,
"preview": "#include <stdio.h>\n\nint main(){\n\tint a = 66;\n\tprintf(\"ASCII = %c\\n\", a);\n\treturn 0;\n}"
},
{
"path": "articals/c/Demo/test11.c",
"chars": 146,
"preview": "#include <stdio.h>\nint main(){\n\tprintf(\"\\aStartled by the sudden sound, Sally shouted,\\n\\\"By the Great Pumpkin, what was"
},
{
"path": "articals/c/Demo/test12.c",
"chars": 228,
"preview": "#include <stdio.h>\nint main(){\n\tfloat f;\n\tprintf(\"Enter a floating-point value:\");\n\tscanf(\"%f\", &f);\n\tprintf(\"fixed-poin"
},
{
"path": "articals/c/Demo/test13.c",
"chars": 189,
"preview": "#include <stdio.h>\n#define YEAR_S 3.156e+7\nint main(){\n\tfloat age;\n\tprintf(\"please input your age:\");\n\tscanf(\"%f\", &age)"
},
{
"path": "articals/c/Demo/test14.c",
"chars": 200,
"preview": "#include <stdio.h>\n#define WATER_W 3.0e-23\n#define KATUO_W 950\nint main(){\n\tfloat n;\n\tprintf(\"please input kuatu num:\");"
},
{
"path": "articals/c/Demo/test15.c",
"chars": 158,
"preview": "#include <stdio.h>\n#define YIN_CM 2.54\nint main(){\n\tfloat h;\n\tprintf(\"please input your height:\");\n\tscanf(\"%f\", &h);\n\tpr"
},
{
"path": "articals/c/Demo/test16.c",
"chars": 296,
"preview": "#include <stdio.h>\n#define PIN_CUP 2\n#define CUP_YAS 8\n#define YAS_SOU 2\n#define SOU_CHA 3\n\nint main(){\n\tfloat cup;\n\tpri"
},
{
"path": "articals/c/Demo/test17.c",
"chars": 259,
"preview": "#include <stdio.h>\n#include <string.h>\nint main(){\n\tchar fname[30];\n\tchar sname[30];\n\tprintf(\"please input your first na"
},
{
"path": "articals/c/Demo/test18.c",
"chars": 351,
"preview": "#include <stdio.h>\nint main(){\n\tchar fname[30], sname[30], tip[10] = \"name:\";\n\tprintf(\"please input your first name:\");\n"
},
{
"path": "articals/c/Demo/test19.c",
"chars": 115,
"preview": "#include <stdio.h>\nint main(){\n\tfloat f;\n\tscanf(\"%f\", &f);\n\tprintf(\"%.1f\\n\", f);\n\tprintf(\"%.1e\\n\", f);\n\treturn 0;\n}"
},
{
"path": "articals/c/Demo/test2.c",
"chars": 147,
"preview": "#include <stdio.h>\nint main(){\n\tchar* name = \"shaosuo\";\n\tchar* address = \"wuhan\";\n\tprintf(\"name = %s, address = %s\\n\", n"
},
{
"path": "articals/c/Demo/test20.c",
"chars": 161,
"preview": "#include <stdio.h>\nint main(){\n\tfloat h;\n\tprintf(\"please input your height(cm):\");\n\tscanf(\"%f\", &h);\n\tprintf(\"Dabbey, yo"
},
{
"path": "articals/c/Demo/test21.c",
"chars": 269,
"preview": "#include <stdio.h>\nint main(){\n\tfloat speed, fsize;\n\tprintf(\"please input download speed, file size:\");\n\tscanf(\"%f%f\", &"
},
{
"path": "articals/c/Demo/test22.c",
"chars": 433,
"preview": "#include <stdio.h>\n#include <string.h>\n int main(){\n \tchar fname[30], sname[30];\n \tint flen, slen;\t\n\tprintf(\"please inpu"
},
{
"path": "articals/c/Demo/test23.c",
"chars": 249,
"preview": "#include <stdio.h>\n#include <float.h>\nint main(){\n\tdouble d = 1.0/3.0;\n\tfloat f = 1.0/3.0;\n\tprintf(\"%.6Lf, %.12Lf, %.18L"
},
{
"path": "articals/c/Demo/test24.c",
"chars": 236,
"preview": "#include <stdio.h>\n#define JIA_S 3.785\n#define YIN_KM 1.609\nint main(){\n\tfloat s, fule;\n\tprintf(\"please input s(yinli), "
},
{
"path": "articals/c/Demo/test25.c",
"chars": 201,
"preview": "#include <stdio.h>\n#define ROUND 60\nint main(){\n\tint min = 1;\n\twhile(min > 0){\n\t\tprintf(\"please input a min:\");\n\t\tscanf("
},
{
"path": "articals/c/Demo/test26.c",
"chars": 168,
"preview": "#include <stdio.h>\nint main(){\n\tint n, max;\n\tprintf(\"please input a intege:\");\n\tscanf(\"%d\", &n);\n\tmax = n + 10;\n\twhile( "
},
{
"path": "articals/c/Demo/test27.c",
"chars": 196,
"preview": "#include <stdio.h>\nint main(){\n\tint days = 1;\n\twhile(days){\n\t\tprintf(\"please input days:\");\n\t\tscanf(\"%d\", &days);\n\t\tprin"
},
{
"path": "articals/c/Demo/test28.c",
"chars": 293,
"preview": "#include <stdio.h>\n#define CM_INCHES 0.393701\n#define CM_FEET 0.032808\nint main(){\n\tfloat height = 1.0;\n\twhile(height){\n"
},
{
"path": "articals/c/Demo/test29.c",
"chars": 186,
"preview": "#include <stdio.h>\nint main(){\n\tint n, count = 0, sum = 0;\n\tprintf(\"please input n:\");\n\tscanf(\"%d\" ,&n);\n\twhile( count++"
},
{
"path": "articals/c/Demo/test3.c",
"chars": 225,
"preview": "#include <stdio.h>\n\nvoid jolly();\nvoid deny();\n\nint main(){\n\tjolly();\n\tjolly();\n\tjolly();\n\tdeny();\n\treturn 0;\n}\n\nvoid jo"
},
{
"path": "articals/c/Demo/test30.c",
"chars": 194,
"preview": "#include <stdio.h>\nint main(){\n\tint n, count = 0, sum = 0;\n\tprintf(\"please input n:\");\n\tscanf(\"%d\" ,&n);\n\twhile( count++"
},
{
"path": "articals/c/Demo/test31.c",
"chars": 139,
"preview": "#include <stdio.h>\nvoid thr(int n);\nint main(){\n\tint n;\n\tscanf(\"%d\", &n);\n\tthr(n);\n\treturn 0;\n}\n\nvoid thr(int n){\n\tprint"
},
{
"path": "articals/c/Demo/test32.c",
"chars": 347,
"preview": "#include <stdio.h>\nvoid resmode();\nint main(){\n\tint first, second;\n\tprintf(\"start!\\n\");\n\tprintf(\"input second operand\\n\""
},
{
"path": "articals/c/Demo/test33.c",
"chars": 164,
"preview": "#include <stdio.h>\nint main(){\n\tchar a[27] = \"abcdefghijklmnopqrstuvwxyz\";\n\tint i = 0;\n\twhile( i++ < 26){\n\t\tprintf(\"%c\\n"
},
{
"path": "articals/c/Demo/test34.c",
"chars": 170,
"preview": "#include <stdio.h>\nint main(){\n\tint i, j;\n\tchar ch = '$';\n\tfor(i = 0; i < 5; ++i){\n\t\tfor (j = 0; j <= i; ++j)\n\t\t{\n\t\t\tpri"
},
{
"path": "articals/c/Demo/test35.c",
"chars": 211,
"preview": "#include <stdio.h>\nint main(){\n\tchar lets[27] = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\tint i, j;\n\tfor (i = 0; i < 6; ++i)\n\t{\n\t\tf"
},
{
"path": "articals/c/Demo/test36.c",
"chars": 219,
"preview": "#include <stdio.h>\nint main(){\n\tchar lets[27] = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\tint i, j;\n\tfor (i = 0; i < 6; i++)\n\t{\n\t\tf"
},
{
"path": "articals/c/Demo/test37.c",
"chars": 383,
"preview": "#include <stdio.h>\n#define START 64\nint main(){\n\tchar ch;\n\tint i, j;\n\tscanf(\"%c\", &ch);\n\tfor (j = 0; j < ch - START; ++j"
},
{
"path": "articals/c/Demo/test38.c",
"chars": 293,
"preview": "#include <stdio.h>\nint main(){\n\tint i, start, end;\n\tprintf(\"start,end\\n\");\n\tscanf(\"%d,%d\",&start, &end);\n\tfor (i = start"
},
{
"path": "articals/c/Demo/test39.c",
"chars": 162,
"preview": "#include <stdio.h>\n#include <string.h>\nint main(){\n\tchar w[50];\n\tscanf(\"%s\", w);\n\tint len = strlen(w);\n\twhile(len-- >= 0"
},
{
"path": "articals/c/Demo/test4.c",
"chars": 220,
"preview": "#include <stdio.h>\n\nvoid br();\nvoid ic();\n\nint main(){\n\tbr();\n\tprintf(\", \");\n\tic();\n\tprintf(\"\\n\");\n\tic();\n\tprintf(\",\\n\")"
},
{
"path": "articals/c/Demo/test40.c",
"chars": 230,
"preview": "#include <stdio.h>\nint main(){\n\tfloat num1, num2;\n\twhile (scanf(\"%f%f\", &num1, &num2) != 2){\n\t\tprintf(\"please input corr"
},
{
"path": "articals/c/Demo/test41.c",
"chars": 282,
"preview": "#include <stdio.h>\nfloat addff(float f1, float f2);\nint main(){\n\tfloat num1, num2;\n\twhile ( scanf(\"%f%f\", &num1, &num2) "
},
{
"path": "articals/c/Demo/test42.c",
"chars": 310,
"preview": "#include <stdio.h>\nint main(){\n\tint a, b;\n\tprintf(\"Enter lower and upper integer limits:\");\n\tscanf(\"%d%d\", &a, &b);\n\twhi"
},
{
"path": "articals/c/Demo/test43.c",
"chars": 409,
"preview": "#include <stdio.h>\n#define LEN 8\nvoid swap(int *a, int *b);\nint main()\n{\n\tint i, j, a[LEN];\n\tfor (i = 0; i < LEN; ++i)\n\t"
},
{
"path": "articals/c/Demo/test44.c",
"chars": 385,
"preview": "#include <stdio.h>\nint main(){\n\tfloat f1 = 1.0, f2 = 1.0, sum1 = 0, sum2 = 0;\n\tint i, n;\n\tscanf(\"%d\", &n);\n\twhile( n > 0"
},
{
"path": "articals/c/Demo/test45.c",
"chars": 214,
"preview": "#include <stdio.h>\n#define LEN 8\nint main(){\n\tint arr[LEN];\n\tint i, tem = 1;\n\tfor (i = 0; i < LEN; ++i)\n\t{\n\t\ttem *= 2;\n\t"
},
{
"path": "articals/c/Demo/test46.c",
"chars": 405,
"preview": "#include <stdio.h>\n#define LEN 8\nint main(){\n\tdouble a[LEN], b[LEN], tem = 0;\n\tint i;\n\tfor (i = 0; i < LEN; ++i)\n\t{\n\t\tpr"
},
{
"path": "articals/c/Demo/test47.c",
"chars": 186,
"preview": "#include <stdio.h>\n#include <string.h>\n#define MAX_LEN 255\nint main(){\n\tchar a[MAX_LEN];\n\tscanf(\"%s\", a);\n\tint len = str"
},
{
"path": "articals/c/Demo/test48.c",
"chars": 259,
"preview": "#include <stdio.h>\nint main(){\n\tint start = 5, week, weekfds, i = 0;\n\tprintf(\"start friends is %d\\n\", start);\n\tscanf(\"%d"
},
{
"path": "articals/c/Demo/test49.c",
"chars": 277,
"preview": "#include <stdio.h>\n#include <ctype.h>\nint main(){\n\tchar ch;\n\tint nblank = 0, nt = 0, n = 0;\n\twhile( (ch = getchar()) != "
},
{
"path": "articals/c/Demo/test5.c",
"chars": 121,
"preview": "#include <stdio.h>\nint main(){\n\tint toes = 10;\n\tprintf(\"toes*2 = %d, toes^2 = %d\\n\", toes * 2, toes * toes);\n\treturn 0;\n"
},
{
"path": "articals/c/Demo/test50.c",
"chars": 187,
"preview": "#include <stdio.h>\nint main(){\n\tchar ch;\n\tint n = 0;\n\twhile( (ch = getchar()) != '#' ){\n\t\tputchar(ch);\n\t\tprintf(\" %d \", "
},
{
"path": "articals/c/Demo/test51.c",
"chars": 183,
"preview": "#include <stdio.h>\nint main(){\n\tchar ch, pre;\n\tint n = 0;\n\twhile( (ch = getchar()) != '#' ){\n\t\tif(pre == 'e' && ch == 'i"
},
{
"path": "articals/c/Demo/test52.c",
"chars": 659,
"preview": "#include <stdio.h>\n#define BASIC_SALARY 10.00\n#define LOVER_RATE 0.15\n#define MIDDLE_RATE 0.2\n#define HIGH_RATE 0.25\n\nin"
},
{
"path": "articals/c/Demo/test53.c",
"chars": 1238,
"preview": "#include <stdio.h>\n#define LOVER_RATE 0.15\n#define MIDDLE_RATE 0.2\n#define HIGH_RATE 0.25\n\nint main(){\n\tfloat work_hours"
},
{
"path": "articals/c/Demo/test54.c",
"chars": 504,
"preview": "#include <stdio.h>\n#include <math.h>\n#include <ctype.h>\n_Bool isPrime(int n);\nint main(){\n\tunsigned a, i;\n\tprintf(\"Enter"
},
{
"path": "articals/c/Demo/test55.c",
"chars": 867,
"preview": "#include <stdio.h>\n#define NORMAL_TAX 0.15\n#define EXT_TAX 0.28\nvoid menu();\nint main(){\n\tint choice;\n\tfloat salary, ext"
},
{
"path": "articals/c/Demo/test56.c",
"chars": 2168,
"preview": "#include <stdio.h>\nint main(){\n\tchar choice;\n\tfloat fweight = 0, sweight = 0, tweight = 0;\n\tfloat fcharge = 0, scharge ="
},
{
"path": "articals/c/Demo/test57.c",
"chars": 216,
"preview": "#include <stdio.h>\n#include <ctype.h>\nint main(){\n\tchar ch;\n\tint count = 0;\n\twhile( (ch = getchar()) != EOF )\n\t{\n\t\tif(is"
},
{
"path": "articals/c/Demo/test58.c",
"chars": 409,
"preview": "#include <stdio.h>\nvoid dealSpecial(char sp);\nint main(){\n\tchar ch;\n\twhile( (ch = getchar()) != EOF ){\n\t\t// if( ch == '\\"
},
{
"path": "articals/c/Demo/test59.c",
"chars": 279,
"preview": "#include <stdio.h>\n#include <ctype.h>\nint main(){\n\tchar ch;\n\tint lower = 0, upper = 0;\n\twhile( (ch = getchar()) != EOF "
},
{
"path": "articals/c/Demo/test6.c",
"chars": 99,
"preview": "#include <stdio.h>\nint main(){\n\tint age = 23;\n\tprintf(\"my day in life:%d\\n\", age*365);\n\treturn 0;\n}"
},
{
"path": "articals/c/Demo/test60.c",
"chars": 196,
"preview": "#include <stdio.h>\nint main(){\n\tchar ch;\n\tint count = 0;\n\twhile( (ch = getchar()) != EOF ){\n\t\tcount++;\n\t\tif(ch == ' ' ||"
},
{
"path": "articals/c/Demo/test61.c",
"chars": 400,
"preview": "#include <stdio.h>\nint main(){\n\tint ran, lower = 1, upper = 100, i = 0;\n\tint smart = (lower + upper) / 2;\n\tprintf(\"pleas"
},
{
"path": "articals/c/Demo/test62.c",
"chars": 1100,
"preview": "#include <stdio.h>\nvoid count();\nint get_int();\nchar get_first();\nchar get_choice();\nint main(){\n\tchar choice;\n\tcount();"
},
{
"path": "articals/c/Demo/test63.c",
"chars": 45,
"preview": "#include <stdio.h>\nint main(){\n\t\n\treturn 0;\n}"
},
{
"path": "articals/c/Demo/test64.c",
"chars": 45,
"preview": "#include <stdio.h>\nint main(){\n\t\n\treturn 0;\n}"
},
{
"path": "articals/c/Demo/test65.c",
"chars": 292,
"preview": "#include <stdio.h>\nvoid show(char, int, int);\nint main(void){\n\tchar a;\n\tint b, c;\n\tscanf(\"%c%d%d\", &a, &b, &c);\n\tshow(a,"
},
{
"path": "articals/c/Demo/test66.c",
"chars": 208,
"preview": "#include <stdio.h>\ndouble avg(double, double);\nint main(){\n\tdouble a, b;\n\tscanf(\"%lf%lf\", &a, &b);\n\tprintf(\"%.2lf\", avg("
},
{
"path": "articals/c/Demo/test67.c",
"chars": 298,
"preview": "#include <stdio.h>\nvoid large_of(double *, double *);\nint main(void){\n\tdouble a, b;\n\tscanf(\"%lf%lf\", &a, &b);\n\tlarge_of("
},
{
"path": "articals/c/Demo/test68.c",
"chars": 414,
"preview": "#include <stdio.h>\nvoid order(double *, double *, double *);\nvoid swap(double *, double *);\nint main(void){\n\tdouble a, b"
},
{
"path": "articals/c/Demo/test69.c",
"chars": 301,
"preview": "#include <stdio.h>\ndouble power(double, int);\nint main(){\n\tdouble n;\n\tint c;\n\tscanf(\"%lf%d\", &n, &c);\n\tprintf(\"%.2lf\\n\","
},
{
"path": "articals/c/Demo/test7.c",
"chars": 189,
"preview": "#include <stdio.h>\nvoid smile();\nint main(){\n\tint i, j;\n\tfor(i = 3; i > 0; i--)\n\t{\n\t\tfor(j = i; j > 0; j--)\n\t\t\tsmile();\n"
},
{
"path": "articals/c/Demo/test70.c",
"chars": 257,
"preview": "#include <stdio.h>\ndouble power(double, int);\nint main(){\n\tdouble n;\n\tint c;\n\tscanf(\"%lf%d\", &n, &c);\n\tprintf(\"%.2lf\\n\","
},
{
"path": "articals/c/Demo/test71.c",
"chars": 229,
"preview": "#include <stdio.h>\nvoid to_base_n(int, int);\nint main(void){\n\tint x, n;\n\tscanf(\"%d%d\", &x, &n);\n\tto_base_n(x, n);\n\tretur"
},
{
"path": "articals/c/Demo/test72.c",
"chars": 488,
"preview": "#include <stdio.h>\nint fibonacciRec(int); //递归\nint fibonacci(int); //非递归\nint main(void){\n\tint n;\n\tscanf(\"%d\", &n);\n\tp"
},
{
"path": "articals/c/Demo/test73.c",
"chars": 1050,
"preview": "#include <stdio.h>\n#define N 5\nvoid cp_arr(double [], const double [], int);\nvoid cp_ptr(double [], const double *, int)"
},
{
"path": "articals/c/Demo/test74.c",
"chars": 568,
"preview": "#include <stdio.h>\n#define SIZE 10\nvoid sort(double [], int);\nvoid swap(double *, double *);\nvoid show_arr(const double "
},
{
"path": "articals/c/Demo/test75.c",
"chars": 796,
"preview": "#include <stdio.h>\n#define COLS 3\n#define ROWS 2\nvoid cp_arr(double [], const double [], int);\nvoid cp2_arr2(double [][C"
},
{
"path": "articals/c/Demo/test76.c",
"chars": 1078,
"preview": "#include <stdio.h>\n#define N 7\n#define M 3\nvoid cp_arr(double [], const double [], int);\nvoid cp_ptr(double [], const do"
},
{
"path": "articals/c/Demo/test77.c",
"chars": 523,
"preview": "#include <stdio.h>\nvoid show_vla(int, int, double [*][*]);\nint main(void){\n\tint i, j;\n\tconst int rows = 3;\n\tconst int co"
},
{
"path": "articals/c/Demo/test78.c",
"chars": 1151,
"preview": "#include <stdio.h>\n#define YEAR 5\n#define MONTH 12\nvoid perYearFall(const double [][MONTH], int);\nvoid perMonthFall(cons"
},
{
"path": "articals/c/Demo/test79.c",
"chars": 1592,
"preview": "#include <stdio.h>\n#define ROWS 3\n#define COLS 5\nvoid getArr(double [][COLS], int);\nvoid averageGroup(double [], const d"
},
{
"path": "articals/c/Demo/test8.c",
"chars": 232,
"preview": "#include <stdio.h>\nvoid one_three();\nvoid two();\nint main(){\n\tprintf(\"starting now:\\n\");\n\tone_three();\n\tprintf(\"done\\n\")"
},
{
"path": "articals/c/Demo/test80.c",
"chars": 47,
"preview": "#include <stdio.h>\nint main(void){\n\treturn 0;\n}"
},
{
"path": "articals/c/Demo/test81.c",
"chars": 198,
"preview": "#include <stdio.h>\n#define N 50\nvoid getStr(char *, int );\nint main(void){\n\tchar a[N];\n\tgetStr(a, N);\n\tputs(a);\n\treturn "
},
{
"path": "articals/c/Demo/test82.c",
"chars": 278,
"preview": "#include <stdio.h>\n#define N 50\nvoid getStr(char *, int );\nint main(void){\n\tchar a[N];;\n\tgetStr(a, N);\n\tputs(a);\n\treturn"
},
{
"path": "articals/c/Demo/test83.c",
"chars": 331,
"preview": "#include <stdio.h>\n#include <string.h>\nvoid reStr(char *, int);\nint main(void){\n\tchar str[20];\n\twhile( fgets(str, 20, st"
},
{
"path": "articals/c/Demo/test84.c",
"chars": 49,
"preview": "#include <stdio.h>\nint main(void){\n\t\n\treturn 0;\n}"
},
{
"path": "articals/c/Demo/test85.c",
"chars": 470,
"preview": "#include <stdio.h>\n#include <ctype.h>\n#define N 10\nint main(void){\n\tchar a[N];\n\tint i, word, up, low, num, pun;\n\tint cou"
},
{
"path": "articals/c/Demo/test86.c",
"chars": 400,
"preview": "#include <stdio.h>\nint main(int argc, char * argv[]){\n\tint i = argc;\n\tprintf(\"%d\\n\", argc);\n\twhile( i-- > 1 ) \n\t\tputs("
},
{
"path": "articals/c/Demo/test87.c",
"chars": 0,
"preview": ""
},
{
"path": "articals/c/Demo/test88.c",
"chars": 947,
"preview": "#include <stdio.h>\n#include <ctype.h>\n#define N 10\nvoid pf(char * , int);\nvoid toUpper(char * , int);\nvoid toLower(char "
},
{
"path": "articals/c/Demo/test89.c",
"chars": 194,
"preview": "#include <stdio.h>\n// int units = 0;\nvoid critic(int );\nint main(){\n\tint units = 0;\n\tscanf(\"%d\", &units);\n\tif(units != 5"
},
{
"path": "articals/c/Demo/test9.c",
"chars": 220,
"preview": "#include <stdio.h>\nint main(){\n\tint n = 2147483647;\n\tfloat f = 1e+20;\n\tfloat f1 = -f;\n\tprintf(\"n = %d, n+1 = %d\\n\", n, "
},
{
"path": "articals/c/Demo/test90.c",
"chars": 278,
"preview": "#include <stdio.h>\nint main(void){\n\tint mode;\n\tprintf(\"enter 0 for metric, 1 for Us mode:\\n\");\n\twhile(scanf(\"%d\", &mode)"
},
{
"path": "articals/c/Demo/test91.c",
"chars": 288,
"preview": "#include \"test91.h\"\nvoid set_mode(int mode){\n\tif(mode == 0)\n\t\tfule = distance/kalub;\n\tif(mode == 1)\n\t\tfule = distance/k"
},
{
"path": "articals/c/Demo/test91.h",
"chars": 125,
"preview": "#include <stdio.h>\ndouble kalub;\ndouble distance;\ndouble fule;\nvoid set_mode(int);\nvoid show_info(void);\nvoid get_info(v"
},
{
"path": "articals/c/Demo/test92.c",
"chars": 143,
"preview": "#include <stdio.h>\nstatic int i = 0;\nint a(void);\nint main(){\n\tint n = 10;\n\twhile( n-- ) \n\t\tprintf(\"%d\\n\", a());\n}\nint "
},
{
"path": "articals/c/Demo/test93.c",
"chars": 0,
"preview": ""
},
{
"path": "articals/c/Demo/test94.c",
"chars": 513,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\n#define N 1000\nint rand1(int);\nvoid count(const int *, int);\nin"
},
{
"path": "articals/c/Demo/test95.c",
"chars": 678,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\n#define N 100\nint rand1(int);\nvoid sort(int *, int);\nvoid show("
},
{
"path": "articals/c/Demo/test96.c",
"chars": 727,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#define SIZE 20\nint get_n(){\n\tint words;\n\tif(scanf(\"%d\", &words) == 1 && words > "
},
{
"path": "articals/c/Demo/test97.c",
"chars": 488,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#define SIZE 512\nint main(int argc, char * argv[]){\n\tFILE *in, *out;\n\tchar buff[S"
},
{
"path": "articals/c/Demo/test98.c",
"chars": 528,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#include <ctype.h>\n#define SIZE 512\nint main(){\n\tchar *infile, *outfile;\n\tFILE *i"
},
{
"path": "articals/c/Demo/test99.c",
"chars": 20,
"preview": "#include <stdio.h>\n\n"
},
{
"path": "articals/c/Demo/testDice_d.c",
"chars": 664,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\n#include \"testRandom.c\"\nint main(void){\n\tint dice, roll;\n\tint s"
},
{
"path": "articals/c/Demo/testFgets.c",
"chars": 178,
"preview": "#include <stdio.h>\nint main(void){\n\tchar a[10];\n\tfgets(a, 7, stdin); //读了dsfdsf个字符+'\\0'\n\tfputs(a, stdout); //输出dsfds"
},
{
"path": "articals/c/Demo/testFgets2.c",
"chars": 161,
"preview": "#include <stdio.h>\n#define N 10\nint main(void){\n\tchar word[N];\n\twhile( fgets(word, N, stdin) != NULL && word[0] != '\\n' "
},
{
"path": "articals/c/Demo/testFgets3.c",
"chars": 368,
"preview": "#include <stdio.h>\n#define N 10\nint main(){\n\tchar word[N];\n\tint i;\n\twhile( fgets(word, N, stdin) != NULL && word[0] != '"
},
{
"path": "articals/c/Demo/testFileIO.c",
"chars": 105,
"preview": "#include <stdio.h>\nint main(){\n\tchar ch;\n\twhile( (ch = getchar()) != EOF){\n\t\tputchar(ch);\n\t}\n\treturn 0;\n}"
},
{
"path": "articals/c/Demo/testGets.c",
"chars": 129,
"preview": "#include <stdio.h>\nint main(void){\n\tchar name[10];\n\tgets(name);\n\tputs(name);\n\treturn 0;\n}\n//fgdfgdfgdfgfdgfdg\n//fgdfgdfg"
},
{
"path": "articals/c/Demo/testIO.c",
"chars": 475,
"preview": "#include <stdio.h>\n#include <stdlib.h>\nint main(int argc, char * argv[]){\n\tint ch; //读取文件,存储每个字符的地方\n\tFILE *fp; "
},
{
"path": "articals/c/Demo/testP02.c",
"chars": 650,
"preview": "#include <stdio.h>\nint a[2] = {1, 2};\nint main(){\n\tint *p1, *p2, *p3;\n\tp1 = p2 = p3 = a;\n\tprintf(\"%d,%d,%d\\n\", *p1, *p1+"
},
{
"path": "articals/c/Demo/testPntAdd.c",
"chars": 396,
"preview": "#include <stdio.h>\n#define SIZE 10\nint main(){\n\tshort a[SIZE] = {1,2,3,4,5,6,7,8,9,10};\n\tdouble b[SIZE] = {1,2,3,4,5,6,7"
},
{
"path": "articals/c/Demo/testPo.c",
"chars": 371,
"preview": "#include <stdio.h>\n#define SIZE 4\nint sum(int * start, int * end){\n int sum = 0;\n while(start < end){\n sum "
},
{
"path": "articals/c/Demo/testPoint.c",
"chars": 165,
"preview": "#include <stdio.h>\nint arr(int);\nint main(void){\n\tint (* p)(int);\n\tp = arr;\n\tprintf(\"%p,%p\\n\", p, arr);\n\treturn 0;\n}\nint"
},
{
"path": "articals/c/Demo/testPrintfScanf.c",
"chars": 326,
"preview": "#include <stdio.h>\nint main(){\n\tint a = 0, b =0;\n\tint pn1 = printf(\"ok!\\n\"); // pn1 = 4\n\tint pn2 = printf(\"ok"
},
{
"path": "articals/c/Demo/testR_d.c",
"chars": 254,
"preview": "#include <stdio.h>\nextern unsigned int rand0(void);\nextern void changeNext(unsigned int);\nint main(void){\n\tunsigned int "
},
{
"path": "articals/c/Demo/testRand.c",
"chars": 221,
"preview": "#include <stdio.h>\nstatic unsigned long int next = 1; //种子\nunsigned int rand0(void){\n\tnext = next * 1103515245 + 12345;\n"
},
{
"path": "articals/c/Demo/testRandom.c",
"chars": 521,
"preview": "#include <stdio.h>\n#include <stdlib.h>\t\t\nint roll_count = 0;\nint roll_n_dice(int, int);\nint rollem(int);\n// int main(voi"
},
{
"path": "articals/c/Demo/testRecursion.c",
"chars": 325,
"preview": "#include <stdio.h>\nint up_and_down(int);\nint main(void){\n\tup_and_down( 1 );\n\treturn 0;\n}\nint up_and_down(int n){\n\tprintf"
},
{
"path": "articals/c/Demo/testReducto.c",
"chars": 789,
"preview": "#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#define N 40\nint main(int argc, char * argv[]){\n\tFILE *in, *o"
},
{
"path": "articals/c/Demo/testScope.c",
"chars": 203,
"preview": "#include <stdio.h>\nint main(void){\n\tint i = 1 ;\n\t// for (int i = 0; i < 10; ++i)\n\t// {\n\t// \t// int i = 6;\n\t// \tprintf(\"%"
},
{
"path": "articals/c/Demo/testStrSort.c",
"chars": 1061,
"preview": "#include <stdio.h>\n#include <string.h>\n#define SIZE 81 //字符串长度\n#define LIM 20 //最大行数\n#define HALT \"\" //读到空字符结束\nvoid "
},
{
"path": "articals/c/Demo/testSwap.c",
"chars": 207,
"preview": "#include <stdio.h>\nvoid swap(int *, int *);\nint main(void){\n\tint a = 1, b =2;\n\tswap(&a, &b);\n\tprintf(\"%d, %d\\n\", a, b);\n"
},
{
"path": "articals/c/Demo/testToBinary.c",
"chars": 218,
"preview": "#include <stdio.h>\nvoid to_binary(int);\nint main(void){\n\tint n;\n\tscanf(\"%d\", &n);\n\tto_binary(n);\n\treturn 0;\n}\n\nvoid to_b"
},
{
"path": "articals/c/Demo/words",
"chars": 43,
"preview": "Apple Banana\nOrager HongKong\nSHANGHAI wuhan"
},
{
"path": "articals/c/Demo/words.red",
"chars": 15,
"preview": "AlBa\naroKgHGIun"
},
{
"path": "articals/c/array.md",
"chars": 7832,
"preview": "# 数组\n### 一维数组\n- 声明:和声明变量一样,但是数组不能直接赋值给它,可以初始化\n```\nint a[10];\n```\n- 初始化:声明并初始化并非赋值,不允许先声明后直接赋值\n\n```\nint a[10] = {1,2,3,4,"
},
{
"path": "articals/c/data.md",
"chars": 10507,
"preview": "# C与数据\n### 11种数据类型\n- 整型类:int,short(短整型),long(长整型),unsigned(无符号),char(字符整型)\n- 浮点类:float(单精度),double(双精度)\n- C90新增:signed(有"
},
{
"path": "articals/c/fileIO.md",
"chars": 4315,
"preview": "# 文件输入输出\n### 文件通信\n- 重定向:books > bklist 可能会把不必要的东西输出到文件\n- 文件:一系列连续的字节,文本模式,二进制模式\n- 文件模式:所有文件内容都以二进制形式存储\n- 文本文件:最初使用二进制编码的"
},
{
"path": "articals/c/function.md",
"chars": 2378,
"preview": "# 函数\n### 复习函数\n- 什么是函数:完成特定任务的独立程序代码单元\n- 函数的作用:省去重复多于代码,提高代码可读性,方便修改\n- 函数的构成:\n- - 函数原型:声明函数,告诉编译器函数的类型\n- - 函数调用:使用函数\n- - "
},
{
"path": "articals/c/memory.md",
"chars": 5453,
"preview": "# 内存管理\n### 存储类别\n- 对象(object):被存储的值占有一定的物理内存\n> 此对象非面向对象中的对象\n- 访问(access):声明变量来访问对象,也可以通过其他方式指定对象\n```\nint entity = 3; "
},
{
"path": "articals/c/string.md",
"chars": 6080,
"preview": "# 字符串\n### 表示字符串和字符串IO\n \n```c\n#define MSG = \"hello world!\";\nchar a[MAX] = \"hello world!\";\nchar * p = \"hello world!\";\np"
},
{
"path": "articals/c++/class.md",
"chars": 2059,
"preview": "# 类(7.14)\n> 基本思想:数据抽象,封装。数据抽象是一种依赖于接口于实现分离式编程技术\n\n### 抽象数据类型\n- 设计类\n- 改进类\n- 定义成员函数\n- 引入this\n- 引入const成员函数\n- 类作用域和成员函数\n- 外部"
},
{
"path": "articals/c++/function.md",
"chars": 3003,
"preview": "# 函数\n### 函数基础:兼容C\n- 典型的函数:返回类型,函数名字,0个或多个形参组成的列表,函数体\n- 函数调用:实参初始化形参,控制权转移给被调函数\n- 实参与形参:实参是形参的初始值,实参类型必须与形参类型匹配,至少可以隐式的转换"
},
{
"path": "articals/c++/oop.md",
"chars": 1760,
"preview": "# 面向对象程序设计(7.16)\n### oop\n- 概述\n- 动态绑定\n\n### 基类派生类\n- 定义基类\n\n```\nclass A{};\n```\n\n- 定义派生类\n\n```\nclass B : public A{};\n```\n\n- 类型"
},
{
"path": "articals/c++/reload.md",
"chars": 871,
"preview": "# 重载运算符\n\n### 理论\n- 来源:对于自定义的数据类型,需要和自带的运算符的相同功能的运算,实质是函数重载\n- 语法:operator关键词\n\n```\nComplex operator+(Complex c2){\n Compl"
},
{
"path": "articals/c++/str_map_arr.md",
"chars": 1755,
"preview": "\n# 字符串、向量、数组\n### 名字空间\n- 作用域操作符\n\n```\nstd:: cout << i; //左侧的作用域中找出右侧的名字,头文件不应包含\n```\n- 使用using声明:最安全的方法\n\n```\nusing namespac"
},
{
"path": "articals/c++/var.md",
"chars": 2189,
"preview": "# 变量和基本类型\n### 变量\n### 复合类型:基于其他类型定义的类型\n- 引用:为对象起的别名,已经存在的对象的另一个名字\n\n```\nint ival = 1024;\nint &refVal = ival; //引用定义时必须被初始化"
},
{
"path": "articals/h5/0001.md",
"chars": 8477,
"preview": "# 前言\n\n\n最近在写移动端 H5 应用,遇到一个值得记录下来的点。现在从它的由来到实现,我们来聊一下移动端 1px,说 1px 不够准确,应该说成 1 **物理像素**。\n\n通过阅读下面文章,你将会理解以下问题:\n## 问题\n\n- **为"
},
{
"path": "articals/h5/0002.md",
"chars": 5956,
"preview": "# 前言\n最近写第三个移动端 H5 的项目了,准备记录下自己在 H5 项目中的一些实践探索。移动端 H5 与 PC 端开发最大的区别之一,大概就是**响应式布局**问题。\n\n那么下面我们来聊聊移动端响应式布局,了解他的来龙去脉,对现有的最佳"
},
{
"path": "articals/h5/0003.md",
"chars": 15600,
"preview": "# 前言\n\n作为一个开发了多个 H5 项目的前端工程师,在开发过程中难免会遇到一些兼容性等**爬过坑**的问题。现在我将这些问题一一汇总一下,并在后面给出**坑产生的原理**,和**现阶段常规的填坑方案**。由此来做一个阶段性的总结。\n\n>"
},
{
"path": "articals/interview/0001.md",
"chars": 6754,
"preview": "首先呢,统计一下情况:\n\n本人校招进入新三板上市企业工作一年,并有半年多一线互联网实习经验\n\n来到杭州投出简历 24 封,收到面试邀约 10 次\n\n`result = 正式offer * 2 + 口头offer * 1`\n\n令人头疼的是并没"
},
{
"path": "articals/js/0001.md",
"chars": 11094,
"preview": "对写文章这件事已经阁了3个月了,工作太忙很难抽出大块时间来总结写作。现在稍微闲赋些,准备好好对以前的技术做一下总结。为什么要写关于 `Promise` 呢?有以下 3 点\n\n1. 之前面试时候,面试官问 `Promise` 问的比较多,实在"
},
{
"path": "articals/js/0002.md",
"chars": 3576,
"preview": "Promise 处理异步代码相对于纯回调函数比较有序明了,但是对于同步函数写法还是挺繁琐的,下面有两种语法糖让异步更加清晰简洁\n\n### 生成器\n\n#### generator 函数\n\n像指针一样下移,有点像在debug代码\n\n```js\n"
},
{
"path": "articals/react/0001.md",
"chars": 17007,
"preview": "2019年7月3日 天气小晴\n\n\n现在早上9点,准时开始学习 React\n\n### 半个小时过一遍 React 官方文档和教程 (9:00 - 9:30)\n\n ( stature( (x).lChild ) == stature( (x).rChild ) )\n#define BalFac(x) ( stature( (x).lChild ) - statur"
},
{
"path": "booknotes/demo/BST.class.cpp",
"chars": 2307,
"preview": "template <typename T> class BST: public public BinTree<T> {\n\tpublic: //二叉树派生\n\t\tvirtual BinNodePosi(T) & search( const T "
},
{
"path": "booknotes/demo/BTNode.h",
"chars": 420,
"preview": "template <typename T> struct BTNode {\n\tBTNodePosi(T) parent; //父\n\tVector<T> key; //数值向量\n\tVector< BTNodePosi(T) > child; "
},
{
"path": "booknotes/demo/BTree.class.cpp",
"chars": 0,
"preview": ""
},
{
"path": "booknotes/demo/BinNode.h",
"chars": 877,
"preview": "#define BinNodePosi(T) BinNode<T>*\ntemplate <typename T> struct BinNode {\n\tBinNodePosi(T) parent, lChild, rChild; //父亲孩子"
},
{
"path": "booknotes/demo/BinTree.class.cpp",
"chars": 3221,
"preview": "#define stature ((p) ? (p)->height : -1)\ntemplate <typename T> class BinTree {\n\tprotected:\n\t\tint _size; //规模\n\t\tBinNodePo"
},
{
"path": "booknotes/demo/Edge.h",
"chars": 242,
"preview": "typedef enum { UNDETERMINED, TREE, CROSS, FORWORD, BACKWAED } EStatus;\ntemplate <typename Te> struct Edge {\n\tTe data; /"
},
{
"path": "booknotes/demo/Graph.class.cpp",
"chars": 452,
"preview": "template <typename Tv, typename Te> class Graph {\n\tprivate:\n\t\tvoid reset() {\n\t\t\tfor (int i = 0; i < n; ++i){ //顶点\n\t\t\t\tst"
},
{
"path": "booknotes/demo/GraphMatrix.class.cpp",
"chars": 1639,
"preview": "template <typename Te, typename Tv> class GraphMatrix : public Graph<Tv, Te> {\n\tprivate:\n\t\tVector< Vertex<Tv> > V; //顶"
},
{
"path": "booknotes/demo/Lcs.cpp",
"chars": 1462,
"preview": "/* \n * 最长公共子序列\n * 可行---->递归策略---->减而治之---->平凡情况\n * 效率---->动态规划---->自底而上---->迭代策略\n * 对于序列A[0,n],B[0,m], LCS(A,B)无非3种情况\n *"
},
{
"path": "booknotes/demo/List.class.cpp",
"chars": 3252,
"preview": "#include \"ListNode.h\"\ntemplate <typename T> class List {\nprivate:\n\tint _size;\n\tPosi(T) header; //头元素(不可见)\n\tPosi(T) trai"
},
{
"path": "booknotes/demo/ListNode.h",
"chars": 691,
"preview": "#define Post(T) ListNode<T>*\n#define sPost(T) sListNode<T>*\ntemplate <typename T> struct ListNode { //完全开放,不再过度封装\n\tT da"
},
{
"path": "booknotes/demo/Node.h",
"chars": 88,
"preview": "typedef *Node<T> node(T);\ntemplate <typename T> struct Node {\n\tT data;\n\tnode(T) next; \n}"
},
{
"path": "booknotes/demo/PQ.class.cpp",
"chars": 316,
"preview": "template <typename T> struct PQ{\n\tvirtual void insert(T) = 0; //按优先级插入词条\n\tvirtual T getMax() = 0; //取出优先级最高的词条\n\tvirtual "
},
{
"path": "booknotes/demo/PQ_ComplHeap.class.cpp",
"chars": 378,
"preview": "template <typename T> class PQ_ComplHeap : public PQ<T> , public Vector<T> {\n\tprotected: \n\t\tRank percolateDown( Rank n, "
},
{
"path": "booknotes/demo/Queue.class.cpp",
"chars": 210,
"preview": "template <typename T> class Queue : public List<T>{\n\tpublic:\n\t\tvoid enqueue(T const &e) { insertAsLast(e); } //入队\n\t\tT de"
},
{
"path": "booknotes/demo/RedBlack.class.cpp",
"chars": 308,
"preview": "template <typename T> class RedBlack: public BST<T> {\n\tpublic: \n\t\tBinNodePosi(T) insert( const T & e); //插入重写\n\t\tbool rem"
},
{
"path": "booknotes/demo/SList.class.cpp",
"chars": 186,
"preview": "#include \"Node.h\"\ntemplate <typename T> class SList {\n\tSList(int size);\n\t~List();\n\tvoid ClearSList();\n\tbool SListEmoty()"
},
{
"path": "booknotes/demo/Splay.class.cpp",
"chars": 265,
"preview": "template <typename T> class Splay : public BST<T> {\nprotected: \n\tBinNodePosi(T) splay( BinNodePosi(T) v); //将v伸展至根\npubli"
},
{
"path": "booknotes/demo/Stack.class.cpp",
"chars": 218,
"preview": "template <typename T> class Stack :public Vector<T> {\n\tpublic:\n\t\tvoid push(T const & e) { insert(size(), e); } //入栈\n\t\tT "
},
{
"path": "booknotes/demo/Vector.class.cpp",
"chars": 6081,
"preview": "typedef int Rank; //秩\n#define DEFAULT_CAPACITY 3 //默认容量\ntemplate <typename T> class Vector{\nprivate: \n\tRank _si"
},
{
"path": "booknotes/demo/VectorTest.cpp",
"chars": 307,
"preview": "#include <iostream>\n#include <stdio.h>\n#include <vector>\n#include <stack>\nusing namespace std;\n\nint main() {\n\t// vector<"
},
{
"path": "booknotes/demo/Vertex.h",
"chars": 380,
"preview": "typedef enum { UNDISCOVERED, DISCOVERED, VISITED} VStatus;\ntemplate <typename Tv> struct Vertex {\n\tTc data; //数据\n\tint in"
},
{
"path": "booknotes/demo/a_bubbleSort.cpp",
"chars": 257,
"preview": "#include <iostream>\nusing namespace std;\n//起泡排序\nvoid bubblesort(int A[], int n){\n\tfor( bool sorted = false; sorted = !so"
},
{
"path": "booknotes/demo/a_convert.cpp",
"chars": 416,
"preview": "#include <stdio.h>\n#include <iostream>\n#include <stack>\nusing namespace std;\n//进制转换\nvoid convert( Stack<char> & S, __int"
},
{
"path": "booknotes/demo/a_evaluate.cpp",
"chars": 789,
"preview": "#include <stdio.h>\n#include <ctype.h>\n#include <iostream>\n#include <stack>\nusing namespace std;\nconst char pri[N_][] = {"
},
{
"path": "booknotes/demo/a_fib.cpp",
"chars": 295,
"preview": "#include <iostream>\n//递归\nint fib(int n){\n\treturn (2 > n) ? n : fib(n-1) + fib(n-2);\n}\n//迭代\nint fib2(int n){\n\tint f = 0, "
},
{
"path": "booknotes/demo/a_hailstone.cpp",
"chars": 255,
"preview": "/**\n * Hailstone问题\n */\n#include <iostream>\nusing namespace std;\nint hailstone(int n) {\n\tint length = 1;\n\twhile(1 < n){\t\n"
},
{
"path": "booknotes/demo/a_paren.cpp",
"chars": 346,
"preview": "#include <stdio.h>\n#include <iostream>\n#include <stack>\nbool paren(const char exp[], int lo, int hi) {\n\tStack<char> S;\n\t"
},
{
"path": "booknotes/demo/a_sum.cpp",
"chars": 518,
"preview": "#include <iostream>\nusing namespace std;\nint SumI(int A[], int n){\n\tint sum = 0;\n\tfor (int i = 0; i < n; ++i)\n\t{\n\t\tsum +"
},
{
"path": "booknotes/demo/a_vector.cpp",
"chars": 111,
"preview": "#include <iostream>\n#include <vector>\nusing namespace std;\n\nint main(void){\n\tvector<int> v(10, 0);\n\treturn 0;\n}"
},
{
"path": "booknotes/demo/sort.cpp",
"chars": 587,
"preview": "template <typename T> void Verctor<T>::quickSort( Rank lo, Rank hi) {\n\tif( hi - lo < 2) return 0; //平凡解\n\tRank mi = parti"
},
{
"path": "booknotes/graph.md",
"chars": 3752,
"preview": "# 图(Graph)\n### 概述\n- 邻接:邻接关系,顶点与顶点的关系\n- 关联:关联关系,顶点与边的关系\n- 无向图:次序无所谓\n- 有向图(digraph):有次序,起点尾(tail),终点头 (head)\n- 路径(path):一系"
},
{
"path": "booknotes/hash.md",
"chars": 1354,
"preview": "# 词典\n### 散列(Hash)\n> 新的访问方式 \n\n```\n寻秩访问:向量\n寻位置:列表\n寻关键码:BST\n```\n- 访问方式:寻值访问\n- 电话\n\n### 原理\n- 桶Bucket:直接存放或者间接指向一个词条\n- 桶数组Bu"
},
{
"path": "booknotes/list.md",
"chars": 6784,
"preview": "# 列表(List)\n### 接口与实现\n> 列表是采用**动态存储**策略的典型结构,其中的元素称作节点(node)\n> 各节点通过指针或者引用彼此联结,在**逻辑**上构成一个线性序列\n\n- 从静态到动态操作\n- 1)静态:get O("
},
{
"path": "booknotes/proqueue.md",
"chars": 1051,
"preview": "# 优先级队列\n### 需求动机\n- 门诊的队列\n- 电脑中cup的调度\n\n### 实现\n- 接口\n```\ntemplate <typename T> struct PQ{\n\tvirtual void insert(T) = 0; //按优"
},
{
"path": "booknotes/sort.md",
"chars": 2040,
"preview": "# 排序\n### 快速排序(QuickSort)\n- 分而治之\n- - 将序列分为2个子序列:S = Sl = Sr //O(n)\n- - 规模独立:max { |Sl| , |Sr| } < n\n- - 彼此独立:max( Sl ) <="
},
{
"path": "booknotes/string.md",
"chars": 67,
"preview": "# 串\n### ADT\n### 串匹配\n### 蛮力匹配\n### KMP算法\n### BM_BC算法\n### Krap-Rabin算法"
},
{
"path": "booknotes/sum.md",
"chars": 742,
"preview": "# 归纳整理\n### 数据结构(Data Structure)\n- 数组(Array):物理上紧邻的定长线性序列(元素为数)\n- 向量(Vector):物理上紧邻的一组不定长线性序列(元素不限)\n- 列表(List):逻辑上紧邻的一组线性序"
},
{
"path": "booknotes/superBST.md",
"chars": 2080,
"preview": "# 高级搜索树\n### 伸展树\n#### 伸展树\n- 局部性:刚被访问的数据,极有可能很快的再次被访问,这一现象在信息处理过程中屡见不鲜\n- 连续m次查找( m >>n = | BST | ) 时间 O(mlogn)\n- 逐层伸展:使用zi"
},
{
"path": "booknotes/tree.md",
"chars": 7081,
"preview": "# 二叉树(BinTree)\n> 半线性结构,二维的列表,特殊的图\n\n### 树(tree)\n- 有根树:指定任一节点r 属于 V作为根后,T即称有根树(rooted tree)\n- 有序树:\n- - 子树树根称孩子,同一父亲的子树之间称兄"
},
{
"path": "booknotes/vector.md",
"chars": 9591,
"preview": "# 向量(Vector)\n### 接口与实现\n> 抽象数据类型(ADT:Abstract Data Type) = 数据模型 + 一组操作 \n> 数据结构(DS:Data Structure) = 基于某种特定语言 + 实现ADT的一整套"
},
{
"path": "package.json",
"chars": 725,
"preview": "{\n \"name\": \"suo-blog\",\n \"version\": \"1.0.0\",\n \"main\": \"index.js\",\n \"repository\": \"https://github.com/suoyuesmile/suo-"
},
{
"path": "public/html/demo-box-model.html",
"chars": 562,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n\t<title></title>\n\t<style type=\"text/css\">\n\n.main {\n\tbackground: #000;\n\twidth: 500px;\n\theig"
},
{
"path": "public/html/demo-display.html",
"chars": 749,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n\t<title></title>\n\t<link rel=\"stylesheet\" href=\"laout.css\">\n</head>\n<body>\n<!-- 块级元素 -->\n<d"
},
{
"path": "public/html/demo-float.html",
"chars": 419,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n\t<title></title>\n\t<style type=\"text/css\">\nimg {\n\tfloat: right;\n\tmargin: 0 0 1em 1em;\n}\n\t</"
},
{
"path": "public/html/demo-position.html",
"chars": 587,
"preview": "<!DOCTYPE html>\n<html>\n<head>\n\t<title></title>\n\t<style type=\"text/css\">\n\n.demo {\n\twidth: 300px;\n\theight: 300px;\n\tleft: 3"
},
{
"path": "public/html/layout.css",
"chars": 41,
"preview": ".main {\n\twidth: 100px;\n\tmargin: 0 auto;\n}"
}
]
// ... and 189 more files (download for full content)
About this extraction
This page contains the full source code of the suoyuesmile/full-stack-developer GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 389 files (14.3 MB), approximately 264.4k tokens, and a symbol index with 513 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.