程序编译系统构成:预处理器、编译器、汇编器、连接器
代码执行的过程:源代码->编译器->汇编代码->汇编器->目标代码->连接器->可执行程序
程序的构成:输入+算法+程序设计+输出
Unicode 指定标准语言
Cs50 编程手册:https://manual.cs50.io/
Pseudo code 伪代码
程序调试的方法:
1.控制台打日志printf
2.debugger
3.rubber duck-头脑风暴与同伴讨论代码
动态内存分配技术,自动扩大或缩小阵列
提倡使用快捷键、shell命令编程,提高开发效率
c语言非零即真
strcmp:字符串比较
值类型交换,变量值不变;引用类型交换,变量值改变。
Scanf(“%i”,&x) :从键盘输入
c语言编译 :make xx.c 执行 ./xx
#include
#include
/**
*link list实现
*/
typedef struct node
{
int number;
struct node *next;
} node;
int main(void)
{
// list of size
node *list = NULL;
// add a nuber to list
node *n = malloc(sizeof(node));
if (n == NULL)
{
return 1;
}
n->number = 1;
n->next = NULL;
// update list to point to new node
list = n;
// add a number to list
n = malloc(sizeof(node));
if (n == NULL)
{
free(list);
return 1;
}
n->number = 2;
n->next = NULL;
list->next = n;
// add a nuber to list
n = malloc(sizeof(node));
if (n == NULL)
{
free(list->next);
free(list);
return 1;
}
n->number = 3;
n->next = NULL;
list->next->next = n;
// print numbers
// for(node *tmp =list;tmp!=NULL;tmp=tmp->next){
// printf(“%i\n”,tmp->next);
// }
// free list
while (list != NULL)
{
node *tmp = list->next;
free(list);
list = tmp;
}
return 0;
}
typedef struct node
{
int number;
struct node *left;
struct node *right;
} node;
void free_tree(node *root);
void print_tree(node *root);
int main(void)
{
// tree of the size 0
node *tree = NULL;
// add number to list
node *n = malloc(sizeof(node));
if (n == NULL)
{
// free the memory
return 1;
}
n->number = 1;
n->left = NULL;
tree = n;
// add number to list
n = malloc(sizeof(node));
if (n == NULL)
{
return 1;
}
n->number = 1;
n->left = NULL;
n->right = NULL;
tree->left = n;
// print tree
print_tree(tree);
// free tree
free_tree(tree);
}
void print_tree(node *root)
{
if (root == NULL)
{
return;
}
print_tree(root->left);
printf(“%i\n”, root->number);
print_tree(root->right);
free_tree(root);
}
/**
*** @brief
** 二分查找树*
*/
bool search(node *tree, int number)
{
if (tree == NULL)
{
return 1;
}
else if (number < tree->number)
{
return search(tree->left, number);
}
else if (number > tree->number)
{
return search(tree->right, number);
}
else if (number == tree->number)
{
return 0;
}
}
AVL或红黑树
Graph
Queues 队列 先进先出(FIFO)
Enqueue/dequeue
Stack 后进先出 LIFO
push/pop
Abstract data structures
python中定义的main函数,必须在程序最后一行调用。
docs.python.org
google & stackoverflow 检索问题
Pip python包安装管理,类似java中maven/gradle
pip install xx
命令行携带参数
from sys import argv
#命令行携带参数
if len(argv) == 2:
print(f"hello,{argv[1]}")
else:
print(“hello,world”)
with关键字使用
python 数据分析
python 人脸识别
face_recoginition模块
微服务springcloud/springcloudalibaba sidecar 调用python api
python生成二维码(QR)
python 代码范例:
agree.py
s = input(" Do you agree? ")
print("s:"+s)
s.lower()
if s == "Y" or s == "y":
print("Agree")
elif s == "N" or s == "n":
print("No agreement")
argv.py
from sys import argv
# 命令行携带参数
# if len(argv) == 2:
# print(f"hello,{argv[1]}")
# else:
# print("hello,world")
for arg in argv[2:]:
print(arg)
blur.py
from PIL import Image, ImageFilter
# 图片滤镜
before = Image.open("vscode.jpg")
# after = before.filter(ImageFilter.CONTOUR)
after = before.filter(ImageFilter.BoxBlur(10))
after.save("cp2vscode.jpg")
caculator.py
try:
x = int(input("x: "))
y = int(input("y: "))
print(x/y)
except ValueError:
print("that is not an int")
exit()
crackPwd.py
from string import ascii_letters, digits, punctuation
from itertools import product
# 暴力破解
for passcode in product(ascii_letters + digits + punctuation, repeat=8):
print(passcode)
dic.py
# 字典 hashtable set 去重
words = set()
def check(word):
if word.lower() in words:
return True
else:
return False
def load(dictionary):
file = open(dictionary, "r")
for line in file:
word = line.rstrip() # /n分割单词
words.add(word)
file.close()
return True
def size():
return len(words)
def unload(): # 释放内存
return True
edges.py
from PIL import Image, ImageFilter
# 滤镜处理
before = Image.open("vscode.jpg")
after = before.filter(ImageFilter.FIND_EDGES)
after.save("cp3vscode.jpg")
mario.py
print("?"*4)
for i in range(4):
print("?"+str(i), end="$") # 使用$进行分割字符串
meow.py
def main():
for i in range(3):
meow(8)
def meow(n):
print("meow"+str(n))
main() # python中必须调用定义的入口函数main
phonebook.py
# 数据结构hashtable&线性查找
people = {
"mark": "110",
"steve": "112"
}
name = input("name: ")
if name in people:
num = people[name]
print(f"Number:{num}")
qrcode.py
import os
import qrcode
#二维码生成
img = qrcode.make(
"https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png")
img.save("qr.png", "PNG")
os.system("open qr.png") # 调用系统命令open 打开二维码
scores.py
scores = [33, 55, 75]
# 求和
avg = sum(scores) / len(scores)
# print("avg"+str(avg))
print(f"avg:{avg}")
scores2.py
scores = []
for i in range(3):
score = int(input("score: "))
# scores.append(score)
scores += [score]
avg = sum(scores) / len(scores)
print(f"avg:{avg}")
Httpserver
安装flask: pip install flask
flask框架
flask项目启动: flask run
web开发必须有个应用框架模型,连接各种技术与业务在一起
http+json 接口格式数据
代码质量评估=正确性+设计+代码风格
git
命令行工具:xcode
vscode
Host a web side (网站托管)
https://pages.github.com/
https://www.netlify.com/
Balanced Binary search Tree平衡二叉树
Unicode->emoji(表情符号)