每周专业学习周记-1(代码片段)

xxxxxxxxxx xxxxxxxxxx     2022-12-04     521

关键词:

每周专业学习周记-1

标签(空格分隔): 周记


说明:接下来的每一周都将会跟新我的专业学习周记,内容包括代码+总结。目前主要除了课程内的《数据结构与算法》课程之外,还有Python语言学习,Python作为现在比较热门并且易入门的编程语言,学习它无论是用作工具还是提升自己都会有很好的帮助,教材使用【美】《Python编程从入门到实践》。
接下来的每周我将会持续更新我的学习情况。

数据结构篇

#include <stdio.h>
#include <stdlib.h>
#define DataType char
int count;
typedef struct Node

    DataType data;
    struct Node* LChild;
    struct Node* RChild;
BiTNode,*BiTree;

void GreateBiTree(BiTree *root)

    char ch;
    ch = getchar();
    if(ch==‘#‘)
        *root = NULL;
    else
    
        *root = (BiTree)malloc(sizeof(BiTNode));
        (*root)->data = ch;
        GreateBiTree(&((*root)->LChild));
        GreateBiTree(&((*root)->RChild));
    
    


void PreOrder(BiTree root)

    
    if(root==NULL)
        return;
    else
    
        printf("%c",root->data);
        PreOrder(root->LChild);
        PreOrder(root->RChild);
    


void InOrder(BiTree root)

    if(root == NULL)
        return;
    else
    
        InOrder(root->LChild);
        printf("%c",root->data);
        InOrder(root->RChild);
    


void PostOrder(BiTree root)

    if(root == NULL)
        return;
    else
    
        PostOrder(root->LChild);
        PostOrder(root->RChild);
        printf("%c",root->data);
    


void PreLeaf(BiTree root)

    if (root!=NULL)
    
        if (root->LChild==NULL && root->RChild==NULL)
            printf("%c",root->data);
        PreLeaf(root->LChild);
        PreLeaf(root->RChild);
    



void InLeaf(BiTree root)

    if (root!=NULL)
    
        InLeaf(root->LChild);
        if (root->LChild==NULL && root->RChild==NULL)
            printf("%c",root->data);
        InLeaf(root->RChild);
    
    


void PostLeaf(BiTree root)

    if (root!=NULL)
    
        PostLeaf(root->LChild);
        PostLeaf(root->RChild);
        if (root->LChild==NULL && root->RChild==NULL)
            printf("%c",root->data);
    


void LeafCount(BiTree root)

    if (root!=NULL)
    
        LeafCount(root->LChild);
        LeafCount(root->RChild);
        if (root->LChild==NULL && root->RChild==NULL)
            count++;
    


int LeafCountB(BiTree root)

    int Count;
    if (root==NULL)
        Count = 0;
    else if(root->LChild==NULL && root->RChild==NULL)
        Count = 1;
    else
        Count = LeafCountB(root->LChild) + LeafCountB(root->RChild);
    return (Count);


int PostTreeDepth(BiTree root)

    int left,right,max;
    if (root!=NULL)
    
        left = PostTreeDepth(root->LChild);
        right = PostTreeDepth(root->RChild);
        max = left>right?left:right;
        return(max+1);
    
    else
        return(0);


int PreTreeDepth(BiTree root)

    int depth=0,h=1;
    h++;
    if(root != NULL) 
    
        
        if (h>depth) depth = h;
        PreTreeDepth(root->LChild);
        PreTreeDepth(root->RChild);
    
    return(h);


int main()

    BiTree root;
    GreateBiTree(&root);
    printf("先序遍历是:");
    PreOrder(root);
    printf("
中序遍历是:");
    InOrder(root);
    printf("
后序遍历是:");
    PostOrder(root);
    printf("
前序遍历打印叶子节点:");
    PreLeaf(root);
    printf("
中序遍历打印叶子节点:");
    InLeaf(root);
    printf("
后序遍历打印叶子节点:");
    PostLeaf(root);
    
    LeafCount(root);
    printf("
全局变量统计叶子节点个数为:");
    printf("%d",count);
    printf("
分治算法统计叶子节点个数为:");
    printf("%d",LeafCountB(root));
    
    printf("
后续遍历求二叉树的高度为:");
    printf("%d",PostTreeDepth(root));
    printf("
先序遍历求二叉树高度的递归算法:");
    printf("%d ",PreTreeDepth(root));
    return 0;

数据结构小结

以上代码题目分别是:
(1)按照课本中二叉树的链式存储的定义,实现二叉树的链式定义,实现以下二叉树的创建(二叉树中存储的数据为字符类型数据,输入数据时候空子树用“#”):root指向根结点
(2)分别采用先序、中序、后序输出上述二叉树的结点数据信息。
(3)-(7)选作
(3)假设二叉树采用链接存储结构进行存储,root指向根结点,输出二叉树中的叶子结点。(先序,中序,后序)
(4)假设二叉树采用链接存储结构进行存储,root指向根结点,统计叶子结点数目(全局变量,分治算法)。
(5)假设二叉树采用链接存储结构进行存储,root指向根结点,求二叉树的高度。
递归算法的理解始终是有些难度,需要一层一层的慢慢通过栈的方式出栈入栈.

Python篇

#4.11遍历整个列表
magicians = [‘alice‘,‘david‘,‘carolian‘]
for magician in magicians:
	print(magician)
#4.1.2 在for循环中执行更多的操作
magicians = [‘alice‘,‘david‘,‘carolian‘]
for magician in magicians:
	print(magician.title()+",that was a great trick!")
	print("I can‘t wait to see your next trick, "+magician.title()+".
")
#4.1.3在for循环之后执行一些操作
magicians = [‘alice‘,‘david‘,‘carolian‘]
for magician in magicians:
	print(magician.title()+",that was a great trick!")
	print("I can‘t wait to see your next trick, "+magician.title()+".
")
print("Thank you,everyone.That was a great magic show!")

#4.2.1 忘记缩进
# magicians = [‘alice‘,‘david‘,‘carolian‘]
# for maician in magicians:
# print("I can‘t wait to see your next trick, "+magician.title()+".
")
#IndentationError: expected an indented block 这个提示就是没有缩进

#4.2.2 忘记缩进额外的代码行
magicians = [‘alice‘,‘david‘,‘carolian‘]
for magician in magicians:
	print(magician.title()+",taht was a great trick!")
print("I can‘t wait to see your next trick, "+magician.title()+".
")

#4.2.3 不必要的缩进
# message = "Hello python world!"
# 	print(message)
#IndentationError: unexpected indent 这个提示是有不必要的缩进

#4.2.5 遗漏了冒号
# magicians = [‘alice‘,‘david‘,‘carolian‘]
# for magician in magicians
# 	print(magician)
#SyntaxError: invalid syntax 语法错误,这里是for后面没有加封号

#4-1 披萨
pizzas = [‘durian pizza‘,‘apple pizza‘,‘banana pizza‘]
for pizza in pizzas:
	print("I like "+pizza+".")

print("I really love banana pozza!")

#4-2 动物
dogs = [‘teddy‘,‘husky‘,‘chinese rural dog‘]
for dog in dogs :
	print(dog.title()+" would like a great pet.")
print("Any of these animals would make a great pet!")

#4.3.1 使用range()函数
for value in range(1,5):
	print(value)

for value in range(1,6):
	print(value," ",end="")
print()
#4.3.2 用range()创建数字列表
numbers = list(range(1,6))
print(numbers)
#设置步长
even_numbers = (list(range(1,11,2)))
print(even_numbers)

squares = []
for value in range(1,11):
	square = value**2
	squares.append(square) 
print(squares)

squares = []
for value in range(1,11):
	squares.append(value**2)
print(squares)

#4.3.3 对数字列表执行简单的统计计算
digits = [10,2,3,4,5,6,65]
print(sum(digits),max(digits),min(digits))

#4.3.4 列表解析
squares = [value**2 for value in range(1,21)]
print(squares)

#4-3 数到二十
for value in range(1,21):
	print(value,end=" ")
print()
#4-4 一百万
# for value in range(1,1000000):
# 	print(value)

#4-5 计算1-1000000
#

#4-6 奇数
for value in range(1,20,2):
	print(value,end=" ")
print()

#4-7 三的倍数
number = [value for value in range(3,30,3)]
for num in number:
	print(num,end=" ")
print()
number = [value for value in range(1,30)]
for value in number:
	if value % 3 == 0:
		print(value,end=" ")
print()
#4-8 立方
number = []
for num in range(1,11):
	number.append(num**3)
for value in number:
	print(value,end=" ")

#4-9 立方解析
print()
number = [value**3 for value in range(1,11)]
print(number)

#4.4.1 切片
players = [‘charles‘,‘martina‘,‘michael‘,‘florence‘,‘eli‘] 
print(players[0:3])
print(players[1:4])
#如果没有指定第一个索引,python将自动从头开始
print(players[:4])
#同样的如果没有指定后一个索引,Python将自动从第一个索引开始访问后面的所有列表值
print(players[2:])
#如果想要输出最后三名队员的名字
print(players[-3:])
#如果想要输出倒数第三个队员之前的名字
print(players[:-3])

#4.4.2 遍历切片
players = [‘charles‘,‘martina‘,‘michael‘,‘florence‘,‘eli‘]
print(‘Here are the first three players on my team.‘)
for player in players:
	print(player.title(),end=",")

#4.4.2 复制列表
my_foods = [‘pizza‘,‘falafel‘,‘carrot cake‘]
friend_foods = my_foods[:]
print("
my favorite food are:")
print(my_foods)

print("my friend‘s favorite food are:")
print(friend_foods)
#这是从my_food里面提取了一个切片

#用切片的方式复制才能
my_foods = [‘pizza‘,‘falafel‘,‘carrot cake‘]
friend_foods = my_foods[:]

my_foods.append(‘cannoli‘)
friend_foods.append(‘ice cream‘)

print("my favorite food are:")
print(my_foods)

print("my friend favorite food are:")
print(friend_foods)

print()
#用赋值的方式得到的效果只是两次都一样
my_foods = [‘pizza‘,‘falafel‘,‘carrot cake‘]
friend_foods = my_foods
#python只是把两个变量关联起来了,而不是向上面一样做成一个副本
my_foods.append(‘cannoli‘)
friend_foods.append(‘ice cream‘)

print("my favorite food are:")
print(my_foods)

print("my friend favorite food are:")
print(friend_foods)

#4-10 切片
fruits = [‘banana‘,‘apple‘,‘pear‘,‘tomato‘,‘watermelon‘]
print("The first there items in the list are:")
print(fruits[:3])
print(fruits[1:4])
print(fruits[-3:])

#4-11 披萨
my_pizzas = [‘durian pizza‘,‘apple pizza‘,‘banana pizza‘]
friend_pizzas = my_pizzas[:]

my_pizzas.append("pear pizza")
friend_pizzas.append("tomato pizza")

print("My favorite pizzas are:")
for pizza in my_pizzas:
	print(pizza,end=",")
print()
print("My friend‘s favorite pizzas are:")
for pizza in friend_pizzas:
	print(pizza,end=",")
print()

#4.5.1 定义元组
dimensions = (200,50)
print(dimensions[0])
print(dimensions[1])
#修改元组的操作事被禁止的,python指出不能给元组的元素赋值
#dimensions[0] = 250

#4.5.2 遍历元组中的所有值
dimensions = (200,50)
for dimension in dimensions:
	print(dimension)

#4.5.3 修改元组变量
dimensions = (200,50)
print("Original dimensions:",end=" ")
for dimension in dimensions:
	print(dimension,end = " ")
print()

dimensions = (400,100)
print("modified dimensions:",end=" ")
for dimension in dimensions:
	print(dimension,end=" ")
#不能单独改变元组中的元素,但是可以使用元组的变量重新定义

#4-13 自助餐
print()
foods = (‘milk‘,‘bread‘,‘egg‘,‘rice‘,‘apple‘)
for food in foods:
	print(food,end=" ")

#foods[0] = ‘banana‘
print()
foods = (‘milk‘,‘bread‘,‘meat‘,‘rice‘,‘banana‘)
for food in foods:
	print(food,end=" ")

Python小结

在本章中,学习了:如何高效的处理列表中的元素;如何使用for循环遍历列表,python如何根据缩进来确定程序的结构以及如何避免一些常见的缩进错误;如何创建简单的数字列表,以及可对数字列表执行的一些操作;如何通过切片来使用列表的一部分和复制列表。还学习了元组(它对不应变化的值提供了一定程度的保护),以及在代码变的越来越复杂时如何设置格式,使其易于阅读。









考研周记-week4

...前几天的心情没有很好,但是周天又出去散了散心,发现每周拿出半天遛弯散步对于心态的调节异常有用,准备每周找个固定的时间遛遛弯,放松放松。  查看详情

嵌入式大杂烩周记|第10期(代码片段)

...。嵌入式大杂烩周记主要是一些实用项目学习分享,每周一篇,每篇一个主题。内容主要来源于我们之前收集的资料:https://gitee.com/zhengnianli/EmbedSummary本期主角:inihinih:一个C语言编写的INI文件解析器。配置... 查看详情

java入门学习周记week01

...为学习就是一个积累的过程。所以我决定在这里记录下我每周学习的内容和一些总结,为以后的自己提供一些参考。1.Java语言跨平台原理平台:指的是操作系统(Windows,Linux,Mac)跨平台:Java程序可以在任意操作系统上运行一次编... 查看详情

前端每周学习分享--第2期(代码片段)

1.项目工具相关1.1.ESLint代码检测工具ESLint属于一种QA工具,是一个ECMAScript/JavaScript语法规则和代码风格的检查工具,可以用来保证写出语法正确、风格统一的代码。ESLint旨在完全可配置,它的目标是提供一个插件化的javascript代码... 查看详情

2018/5/28~2018/6/1周记(代码片段)

       本周来泉州出差,所做的任务是在27上布一个定时器,定时每天早上六点下载微信支付宝的对账单,并将数据以Json的格式传到72上。       创建一个WindowsService,在上面写... 查看详情

实习周记1:跨vlan通信(代码片段)

跨vlan通信1.拓扑图:2.要求:不同vlan的两台pc通过二层交换机实现二层互通3.命令:[H3C-GigabitEthernet2/0/1]portlink-typehybrid把端口模式改为hydrid[H3C-GigabitEthernet2/0/1]porthybridvlan2untaggedVLAN2的帧以Untagged的方式通过接口。& 查看详情

实习周记1:跨vlan通信(代码片段)

跨vlan通信1.拓扑图:2.要求:不同vlan的两台pc通过二层交换机实现二层互通3.命令:[H3C-GigabitEthernet2/0/1]portlink-typehybrid把端口模式改为hydrid[H3C-GigabitEthernet2/0/1]porthybridvlan2untaggedVLAN2的帧以Untagged的方式通过接口。& 查看详情

周记3(代码片段)

数据结构#include<stdio.h>#include<stdlib.h>intsearch(intarr[],intlen,intkey)intmid,low=1; inthigh=len; //printf("%d!",high); while(low<=high) mid=(low+high)/2; //printf("%d",mid); if( 查看详情

2018-2019-1《信息安全专业导论》教学进程(代码片段)

《信息安全专业导论》教学进程目录考核方式教学进程第01周学习任务和要求第02周学习任务和要求第03周学习任务和要求第04周学习任务和要求第05周学习任务和要求第06周学习任务和要求第07周学习任务和要求第08周学习任务和... 查看详情

嵌入式大杂烩周记|第16期(代码片段)

...xff0c;我是杂烩君。嵌入式大杂烩周记主要是一些实用项目学习分享,每篇一个主题。内容主要来源于我们之前收集的资料:https://gitee.com/zhengnianli/EmbedSummary本期主角:boaboa是一个小巧的web服务器,可执行代码只有7... 查看详情

嵌入式大杂烩周记|第16期(代码片段)

...xff0c;我是杂烩君。嵌入式大杂烩周记主要是一些实用项目学习分享,每篇一个主题。内容主要来源于我们之前收集的资料:https://gitee.com/zhengnianli/EmbedSummary本期主角:boaboa是一个小巧的web服务器,可执行代码只有7... 查看详情

链表篇牛客刷题周记(代码片段)

 题目1:JZ3 从尾到头打印链表/***structListNode*intval;*structListNode*next;*ListNode(intx):*val(x),next(NULL)**;*/classSolutionpublic:vector<int>printListFromTailToHead(ListNode*head)//std::co 查看详情

周记2(代码片段)

  书中第介绍了有根树,简单介绍了二叉树和分支数目无限制的有根树的存储结构,而没有关于二叉树的遍历过程。为此对二叉树做个简单的总结,介绍一下二叉树基本概念、性质、二叉树的存储结构和遍历过程,主要包括先... 查看详情

嵌入式大杂烩周记|第9期(代码片段)

...。嵌入式大杂烩周记主要是一些实用项目学习分享,每周一篇,每篇一个主题。内容主要来源于我们之前收集的资料:https://gitee.com/zhengnianli/EmbedSummary本期主角:nanopbnanopb是也是一个轻量的、支持C语言的Protobuf... 查看详情

嵌入式大杂烩周记|第3期(代码片段)

...N。嵌入式大杂烩周记主要是一些实用项目学习分享,每周一篇,每篇一个主题。内容主要来源于我们之前收集的资料:https://gitee.com/zhengnianli/EmbedSummary本期主角:sys/queue.hqueue.h是Linux、FreeBSD中的一个头文件。FreeBS... 查看详情

[周记]8.7~8.16

...,与众多大佬坐在同一个机房中确实是诚惶诚恐。平时的学习还有提升主要分为两部分吧,一是建好数学模型和找对算法,二是实现。前者靠打比赛,后者靠刷题和代码量【比赛】 5场(ST)SRM+洛谷1场民间noip模拟赛+1场atcoder(beg... 查看详情

9.16周记(代码片段)

PHPCSPHPcodeSniffer下载:https://squizlabs.github.io/PHP_CodeSniffer/phpcs.pharhttps://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar这个是代码修复工具PHPCS负责检查代码风格错误PHPCBF负责按照指定标准修复代码错误使用方式://检查phpcs安装了哪些规范phpc 查看详情

周记(第三周)

1.在看书籍和视频学习中成功调试了Java环境和eclipse,并且在eclipse中完成了helloWorld.Java并且在javac中完成了helloworld.java,每天依然坚持打字的训练,并且不间断地学习java语言和一些相关的知识,问题暂时还没有遇到特别难的,因... 查看详情