您的位置:首页 > 健康 > 美食 > 电商小程序开发多少钱_优化是什么工作_软件推广方案经典范文_北京seo网络推广

电商小程序开发多少钱_优化是什么工作_软件推广方案经典范文_北京seo网络推广

2025/4/16 11:51:38 来源:https://blog.csdn.net/2503_91320379/article/details/147000935  浏览:    关键词:电商小程序开发多少钱_优化是什么工作_软件推广方案经典范文_北京seo网络推广
电商小程序开发多少钱_优化是什么工作_软件推广方案经典范文_北京seo网络推广

实验目的及要求:
通过深入学习树(Tree)和二叉树(Binary Tree)这两种重要的数据结构,掌握它们的基本概念、性质和操作,提高对树形结构的理解和应用能力。通过本实验,学生将深化对树和二叉树等数据结构的理解,提高编程能力和问题解决能力,为进一步学习复杂数据结构和算法打下基础。

实验设备环境:
1.微型计算机
2.DEV C++(或其他编译软件)

任务:
编写程序,建立如图 8-10(b) 所示的带头结点的二叉链存储结构二叉树,首先打印该二叉树,然后分别输出按照前序遍历、中序遍历和后序遍历方法访问各结点的信息,最后,查找字符'E是否在该二叉树中。
[输出显示函数设计] 按照某种遍历方法输出二叉树各结点的信息,其实就是把上述各遍历二叉树函数中的 Visit0 设计成输出结点信息的函数。Visit0 设计如下:

void Visit(DataType item){
printf("%c",item);
}


[设计]
设二叉树的结点定义以及带头结点二叉树的初始化操作、左结点插入操作、右结点插入操作、左子树删除操作、右子树删除操作的实现函数存放在文件 BiTree.h 中,设二叉树遍历操作和撤销操作的实现函数存放在文件 BiTreeTraverse.h 中。

代码如下:

头文件BiTree:#include<stdio.h>
#include<stdlib.h>
typedef char DataType;
typedef struct Node {DataType data;struct Node *leftChild;struct Node *rightChild;
} BiTreeNode;
void Initiate(BiTreeNode **root) {*root = (BiTreeNode*)malloc(sizeof(BiTreeNode));(*root)->leftChild = NULL;(*root)->rightChild = NULL;
}
BiTreeNode *InsertLeftNode(BiTreeNode *curr,DataType x) {BiTreeNode *s, *t;if(curr == NULL)return NULL;t = curr->leftChild;s = (BiTreeNode*)malloc(sizeof(BiTreeNode));s->data = x;s->leftChild = t;s->rightChild = NULL;curr->leftChild = s;return curr->leftChild;
}
BiTreeNode *InsertRightNode(BiTreeNode *curr,DataType x) {BiTreeNode *s, *t;if(curr == NULL)return NULL;t = curr->rightChild;s = (BiTreeNode*)malloc(sizeof(BiTreeNode));s->data = x;s->rightChild = t;s->leftChild = NULL;curr->rightChild = s;return curr->rightChild;
}
void Destroy(BiTreeNode **root) {if((*root) != NULL && (*root)->leftChild != NULL)Destroy(&(*root)->leftChild);if((*root) != NULL && (*root)->rightChild != NULL)Destroy(&(*root)->rightChild);free(*root);
}头文件BiTreeTraverse:#include"BiTree.h"
void Visit(DataType item) {printf("%c ",item);
}
void PrintBiTree(BiTreeNode *root, int n) {int i;if(root == NULL)return;PrintBiTree(root->rightChild,n + 1);for(i = 0; i < n-1 ; i++)printf(" ");if(n>0) {printf("---");printf("%c\n",root->data);}PrintBiTree(root->leftChild,n + 1);
}
BiTreeNode *Search(BiTreeNode *root,DataType x) {BiTreeNode *find=NULL;if(root!=NULL) {if(root->data==x)find=root;else {find=Search(root->leftChild,x);if(find==NULL)find=Search(root->rightChild,x);}}return find;
}
void PreOrder(BiTreeNode *t,void Visit(DataType item)) {if(t != NULL) {Visit(t->data);PreOrder(t->leftChild, Visit);PreOrder(t->rightChild, Visit);}
}
void InOrder(BiTreeNode *t,void Visit(DataType item)) {if(t != NULL) {InOrder(t->leftChild, Visit);Visit(t->data);InOrder(t->rightChild, Visit);}
}
void PostOrder(BiTreeNode *t,void Visit(DataType item)) {if(t != NULL) {PostOrder(t->leftChild, Visit);PostOrder(t->rightChild, Visit);Visit(t->data);}
}8-2:#include"BiTreeTraverse.h"
int main() {BiTreeNode *root,*p,*find;char x='E';Initiate(&root);p=InsertLeftNode(root,'A');p=InsertLeftNode(p,'B');p=InsertLeftNode(p,'D');p=InsertRightNode(p,'G');p=InsertRightNode(root->leftChild,'C');InsertLeftNode(p,'E');InsertRightNode(p,'F');PrintBiTree(root,0);printf("前序遍历:");PreOrder(root->leftChild,Visit);printf("\n中序遍历:");InOrder(root->leftChild,Visit);printf("\n后序遍历:");PostOrder(root->leftChild,Visit);find=Search(root,x);if(find!=NULL)printf("\n数据元素%c在二叉树中",x);elseprintf("\n数据元素%c不在二叉树中",x);Destroy(&root);return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com