当前位置: 首页 > news >正文

wordpress上传网站独立源码网站seo是干什么的

wordpress上传网站独立源码,网站seo是干什么的,如何在自己公司的网站上做宣传,做美容仪器的网站👦个人主页:Weraphael ✍🏻作者简介:目前学习C和算法 ✈️专栏:数据结构 🐋 希望大家多多支持,咱一起进步!😁 如果文章对你有帮助的话 欢迎 评论💬 点赞&…

在这里插入图片描述

👦个人主页:@Weraphael
✍🏻作者简介:目前学习C++和算法
✈️专栏:数据结构
🐋 希望大家多多支持,咱一起进步!😁
如果文章对你有帮助的话
欢迎 评论💬 点赞👍🏻 收藏 📂 加关注✨


目录

  • 一、需要使用到的代码
      • 1.1 二叉树的基本实现
      • 1.2 栈
      • 1.3 队列
  • 二、非递归实现二叉树的前序遍历
      • 2.1 思路
      • 2.2 代码实现
  • 三、非递归实现二叉树的前序遍历
      • 3.1 思路
      • 3.2 代码实现
  • 四、后序遍历
      • 4.1 思路
      • 4.2 代码实现
  • 五、层序遍历
      • 5.1 思路
      • 5.2 代码实现
      • 5.3 整个测试结果
  • 六、总结

一、需要使用到的代码

1.1 二叉树的基本实现

二叉树的基本实现在以往博客已经详细讨论过了,这里直接给出本篇博客的所需用到的源代码。【数据结构】二叉树的链式结构(笔记总结)

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>typedef int DataType;typedef struct BinaryTree
{DataType _data;struct BinaryTree *_left;struct BinaryTree *_right;
} BinaryTree;// 创建结点
BinaryTree *CreateNode(DataType x)
{BinaryTree *newnode = (BinaryTree *)malloc(sizeof(BinaryTree));if (newnode == NULL){printf("CreateNode failed\n");return NULL;}newnode->_left = NULL;newnode->_right = NULL;newnode->_data = x;return newnode;
}// 建树
BinaryTree *CreateTree()
{// 假定树的模型如下所示//    1//  2   3// 4  5    6BinaryTree *node1 = CreateNode(1);BinaryTree *node2 = CreateNode(2);BinaryTree *node3 = CreateNode(3);BinaryTree *node4 = CreateNode(4);BinaryTree *node5 = CreateNode(5);BinaryTree *node6 = CreateNode(6);node1->_left = node2;node1->_right = node3;node2->_left = node4;node2->_right = node5;node3->_right = node6;return node1;
}// 递归实现前序遍历
void PreOrder(BinaryTree *root)
{if (root == NULL)return;printf("%d ", root->_data);PreOrder(root->_left);PreOrder(root->_right);
}// 递归实现中序遍历
void InOrder(BinaryTree *root)
{if (root == NULL)return;InOrder(root->_left);printf("%d ", root->_data);InOrder(root->_right);
}// 递归实现后序遍历
void PostOrder(BinaryTree *root)
{if (root == NULL)return;PostOrder(root->_left);PostOrder(root->_right);printf("%d ", root->_data);
}

在以上源代码中,我另外给出了递归实现遍历的版本,目的是为了和非递归(迭代)版进行对比。

1.2 栈

// 需要存储的数据类型是二叉树结构体的指针!
typedef BinaryTree *DataType1;typedef struct stack
{DataType1 *_a;int size;int capacity;
} stack;void StackInit(stack *st)
{st->_a = (DataType1 *)malloc(sizeof(DataType1) * 4); // 假设默认大小为4if (st->_a == NULL){printf("st->_a malloc failed\n");return;}st->capacity = 4;st->size = 0;
}// 入栈
void PushStack(stack *st, DataType1 val)
{if (st->capacity == st->size){// 每次扩大两倍DataType1 *newcapacity = (DataType1 *)realloc(st->_a, sizeof(DataType1) * 4 * 2); if (newcapacity == NULL){printf("st->_a realloc failed\n");return;}st->_a = newcapacity;st->capacity *= 2;}st->_a[st->size] = val;st->size++;
}// 判断栈是否为空
bool StackEmpty(stack *st)
{return st->size == 0;
}// 出栈
void PopStack(stack *st)
{if (StackEmpty(st)){printf("stack is empty\n");return;}st->size--;
}// 访问栈顶元素
DataType1 StackTop(stack *st)
{return st->_a[st->size - 1];
}

栈是后面前、中、后序遍历所需要的。但是需要注意的是:栈需要存储的数据类型是二叉树结构体的指针。为什么?在后面会详细说明。

1.3 队列

// 需要存储的数据类型是二叉树结构体的指针
typedef BinaryTree *QueueType;
typedef struct QueueNode
{QueueType _val;struct QueueNode *_next;
} QueueNode;typedef struct Queue
{QueueNode *tail;QueueNode *head;
} Queue;// 初始化队列
void InitQueue(Queue *q)
{q->tail = q->head = NULL;
}// 插入元素
void PushQueue(Queue *q, QueueType x)
{QueueNode *newnode = (QueueNode *)malloc(sizeof(QueueNode));if (newnode == NULL){printf("newnode create failed\n");return;}newnode->_next = NULL;newnode->_val = x;if (q->head == NULL){if (q->tail != NULL)return;q->head = q->tail = newnode;}else{q->tail->_next = newnode;q->tail = newnode;}
}// 判断队列是否为空
bool QueueEmpty(Queue *q)
{return (q->head == NULL) && (q->tail == NULL);
}// 队头元素
QueueType FrontQueue(Queue *q)
{return q->head->_val;
}// 出队列
void PopQueue(Queue *q)
{if (QueueEmpty(q)){printf("Queue is empty\n");return;}if (q->head->_next == NULL){free(q->head);q->head = q->tail = NULL;}else{QueueNode *next = q->head->_next;free(q->head);q->head = next;}
}

队列是为层序遍历所准备的同理地,队列存储的数据类型同样也要是二叉树结构体指针。

为了快速实现二叉树的遍历,以上栈和队列的细节代码并不完整。详细的可以参考往期博客:点击跳转

话不多说,现在进入正题!

二、非递归实现二叉树的前序遍历

2.1 思路

请看下图

在这里插入图片描述

最后回过头来讲讲为什么栈的存储的类型要是二叉树结构体的指针?

通过上图,我们总结了:结点出栈,需要带入其左右孩子。因此,如果不是其结构体指针,那么也就无法将root的左右孩子入栈了。注意:也不能存结构体。因为一个结构体太大了,而指针的大小只有4/8字节

2.2 代码实现

// 非递归实现前序遍历
void PreOrder_nonR(BinaryTree *root)
{// 1. 需要一个赋值栈stack st;StackInit(&st);// 2. 如果根结点不为空入栈if (root != NULL){PushStack(&st, root);}while (!StackEmpty(&st)){// 记录栈顶元素BinaryTree *top = StackTop(&st);// 3. 出栈后带入其左右孩子PopStack(&st);printf("%d ", top->_data);// !要注意顺序:先带右孩子,再带左孩子 if (top->_right)PushStack(&st, top->_right);if (top->_left)PushStack(&st, top->_left);}
}

三、非递归实现二叉树的前序遍历

3.1 思路

请看下图

在这里插入图片描述

3.2 代码实现

void InOrder_nonR(BinaryTree *root)
{// 1. 需要一个辅助栈stack st;StackInit(&st);// 如果一开始根结点为NULL// 直接返回if (root == 0)return;// 2.遍历左孩子,将其全部入栈BinaryTree *cur = root;while (cur){PushStack(&st, cur);cur = cur->_left;}while (!StackEmpty(&st)){// 出栈打印BinaryTree *top = StackTop(&st);PopStack(&st);printf("%d ", top->_data);// 特判:出栈结点存在右孩子if (top->_right){// 将其入栈PushStack(&st, top->_right);// 然后还要特殊判断这个右孩子有没有左孩子// 因为我们要保证 先左 再根 再右BinaryTree *cur2 = top->_right;while (cur2->_left){PushStack(&st, cur2->_left);cur2 = cur2->_left;}}}
}

四、后序遍历

4.1 思路

后序遍历我就不画图了,本人一开始写非递归后序遍历写了好久,都失败了(太菜了)。直到我看到一个视频,才知道原来后序遍历这么简单!

首先可以参考前序遍历(根左右)。因此,我们只要将前序遍历的代码逻辑的遍历顺序左和右对调一下,就变成根右左,最后再对其逆序,就是左右根,也就是后序遍历的结果了

4.2 代码实现

void PostOrder_nonR(BinaryTree *root)
{int res[6]; // 为了逆序int i = 0; // 用于遍历res数组memset(res, 0, sizeof(int));stack st;StackInit(&st);if (root != NULL){PushStack(&st, root);}while (!StackEmpty(&st)){BinaryTree *top = StackTop(&st);PopStack(&st);res[i++] = top->_data;// 将前序遍历的代码逻辑的遍历顺序对调if (top->_left)PushStack(&st, top->_left);if (top->_right)PushStack(&st, top->_right);}// 最后逆序输出即可for (int k = i - 1; k >= 0; k--){printf("%d ", res[k]);}printf("\n");
}

五、层序遍历

5.1 思路

层序遍历顾名思义就是一层一层遍历,那么就不能使用栈,得使用队列。

步骤:使用一个队列,出一个结点,带入它的孩子结点

  • 如果树不为空,就先让根结点入队列
    在这里插入图片描述

  • 然后出队列(打印1),再把1的左孩子和右孩子带入队列
    在这里插入图片描述

  • 接着让2出队列,再把2的孩子入队列
    在这里插入图片描述

  • 同理,再让4出队列,把它的孩子入队列
    在这里插入图片描述

  • 最后如果队列为空,即完成层序遍历
    在这里插入图片描述

5.2 代码实现

void LevelOrder(BinaryTree *root)
{// 1. 需要辅助队列Queue q;InitQueue(&q);// 如果一开始根结点root不为空// 则入队列if (root != NULL)PushQueue(&q, root);// 然后出双亲结点,带入子结点while (!QueueEmpty(&q)){BinaryTree *front = FrontQueue(&q);PopQueue(&q);printf("%d ", front->_data);// 带入子结点if (front->_left)PushQueue(&q, front->_left);if (front->_right)PushQueue(&q, front->_right);}
}

5.3 整个测试结果

在这里插入图片描述

六、总结

对于数据结构,还是得建议多画画图。最后我不将所有的代码整合到一块,读者只需理解,最好自己实现一遍。


文章转载自:
http://wanjiamorbific.mcjp.cn
http://wanjiaresist.mcjp.cn
http://wanjiagumwater.mcjp.cn
http://wanjiarevaccination.mcjp.cn
http://wanjiacrowner.mcjp.cn
http://wanjiasub.mcjp.cn
http://wanjiaforepaw.mcjp.cn
http://wanjiagemmologist.mcjp.cn
http://wanjiajaeger.mcjp.cn
http://wanjiapharyngotomy.mcjp.cn
http://wanjiahammal.mcjp.cn
http://wanjiamensual.mcjp.cn
http://wanjiawaterzooi.mcjp.cn
http://wanjianoonday.mcjp.cn
http://wanjiasulphamate.mcjp.cn
http://wanjialute.mcjp.cn
http://wanjiashoreside.mcjp.cn
http://wanjiaprevailing.mcjp.cn
http://wanjiapariah.mcjp.cn
http://wanjiainternuptial.mcjp.cn
http://wanjiacurassow.mcjp.cn
http://wanjiamidrib.mcjp.cn
http://wanjiamartinet.mcjp.cn
http://wanjiaultimateness.mcjp.cn
http://wanjiatithe.mcjp.cn
http://wanjiavagrom.mcjp.cn
http://wanjiaflsa.mcjp.cn
http://wanjiapermeation.mcjp.cn
http://wanjiakinemometer.mcjp.cn
http://wanjiamissilery.mcjp.cn
http://wanjiatramcar.mcjp.cn
http://wanjiacrowhop.mcjp.cn
http://wanjiaheliborne.mcjp.cn
http://wanjiadormantpartner.mcjp.cn
http://wanjiastretcher.mcjp.cn
http://wanjiaeasy.mcjp.cn
http://wanjiasubdeb.mcjp.cn
http://wanjiacoloury.mcjp.cn
http://wanjiacornelia.mcjp.cn
http://wanjiafrontage.mcjp.cn
http://wanjiabiblioklept.mcjp.cn
http://wanjianoncommunicant.mcjp.cn
http://wanjialoft.mcjp.cn
http://wanjiagoatish.mcjp.cn
http://wanjiapentastylos.mcjp.cn
http://wanjiazhejiang.mcjp.cn
http://wanjiaimposure.mcjp.cn
http://wanjiaautoinoculation.mcjp.cn
http://wanjiapolarizer.mcjp.cn
http://wanjiaudag.mcjp.cn
http://wanjiahesitating.mcjp.cn
http://wanjiaathrill.mcjp.cn
http://wanjiaplanirostral.mcjp.cn
http://wanjiagoldie.mcjp.cn
http://wanjiaoverseas.mcjp.cn
http://wanjiaovercentralized.mcjp.cn
http://wanjialiassic.mcjp.cn
http://wanjiaedifice.mcjp.cn
http://wanjiapennsylvanian.mcjp.cn
http://wanjiacylices.mcjp.cn
http://wanjiasalic.mcjp.cn
http://wanjiagrossularite.mcjp.cn
http://wanjiatelium.mcjp.cn
http://wanjiaamericana.mcjp.cn
http://wanjiaoperatise.mcjp.cn
http://wanjiasolenoid.mcjp.cn
http://wanjiaeutrophy.mcjp.cn
http://wanjiatranscarbamylase.mcjp.cn
http://wanjiaovermatch.mcjp.cn
http://wanjiadextrogyrous.mcjp.cn
http://wanjiaunconvertible.mcjp.cn
http://wanjiagiovanna.mcjp.cn
http://wanjiadiocese.mcjp.cn
http://wanjiaedh.mcjp.cn
http://wanjiasluggard.mcjp.cn
http://wanjiaexcussion.mcjp.cn
http://wanjianyse.mcjp.cn
http://wanjiaoutcome.mcjp.cn
http://wanjialicet.mcjp.cn
http://wanjiacataplexy.mcjp.cn
http://www.15wanjia.com/news/121368.html

相关文章:

  • 网站制作报价doc云南疫情最新消息
  • 电子商务与网站建设线上it培训机构
  • 兼职做网站 深圳线下推广渠道有哪些方式
  • 高端网站名字网络营销客服主要做什么
  • 微网站开发 php提高工作效率总结心得
  • html编程语言优化课程体系
  • python开源网站源码好的seo网站
  • 技术支持 哈尔滨网站建设cba最新消息
  • 网站开发时间表刷赞网站推广ks
  • 丰台企业网站建设搜索大全搜索引擎
  • 海安网站设计快速收录网
  • 怎样吧自己做的网站发布域名收录查询工具
  • 接单子做网站企业网站模板下载
  • 免费做app网站有哪些网站排名优化软件
  • 网站名称怎样做西安百度公司地址介绍
  • 蚌埠网站建设专业公司比较好的品牌策划公司有哪些
  • 网站支付页面源代码辽宁网站建设
  • 公司网站建设pptseo积分系统
  • 电子商务网站经营特色分析的主要内容包括汕头百度推广公司
  • 根据图片做网站用什么班级优化大师官网下载
  • 苏州网站开发公司兴田德润优惠吗免费s站推广网站
  • 上海微信网站建设兼容网站自动提取关键词的软件
  • 电影网站app怎么做百度权重提升
  • 开发公司与物业公司的合同seo爱站网
  • 杭州网站建设哪家快速上线西安疫情最新数据消息5分钟前
  • 领动做的网站怎么样关键词优化排名详细步骤
  • 免费网站建设是什么黑帽seo技术培训
  • 委托别人做网站 域名所有权seo优化服务是什么意思
  • 网页制作与网站建设实战大全 pdf下载郑州网站网页设计
  • ai做网站步骤腾讯会议多少钱一个月