【vc++精品源码栏目提醒】:网学会员为广大网友收集整理了,计算机软件设计实验报告 - 其它资料,希望对大家有所帮助!
中国矿业大学实验报告课程________________实验名称_______________第 页 共 页系 别_________________________________ 实 验 日 期 年 月 日专业班级________________组别_____________ 实 验 报 告 日 期 年 月 日姓 名________________学号_____________ 报 告 退 发 订正 、 重做 一.题目 链表(多项式加法)及二叉树应用(二叉树的遍历、二叉排序树的生成)二.环境Windows XP 操作系统,VC6.0三.逻辑框图 链表(多项式加法) 开始 静态输入数据,用自定义 数据结构 headaheadb 存 pq 储, 分别指向 papb 中 下一结点 N qNULL qNULL pNULL pre-nextq 结束 freepb Y p-expexpq p-expq -exp -exp -exp xp-coefq-coef q 结 点是 和 pp-next 多 项 式中 的 p 结点是和 一项将 q 插 多 项 式中 的 N X0 在 p 之前q 一 项 后移 q 后移p 不动 不动 Y p-coefx prep pre-next p-next 二叉树的遍历先序遍历 中序遍历 后序遍历 开 始 开 始 开 始 输入二叉 输入二叉 输入二叉 树各结点 树各结点 树各结点 遍历左子树 遍历左子树 访问根结点 访问根结点 遍历右子树 遍历左子树 遍历右子树 访问根结点 遍历右子树 输出遍历结果 输出遍历结果输出遍历结果 结 束 结 束 结 束 二叉排序树的生成 开 始 输入数值 b N 根结点指针 GETNODEtt 申 请 一 块 tNULL 空 间 的 首 地 t-datab t-lchildt-rchildNU LL Y N bdata 插入右子树 InsertBSTt-rchildb Y 插入左子树 InsertBSTt-lchildb 返 回 根结 点 returnt 四. 程序源代码includeincludetypedef struct node int coefexp struct node nextJDvoid add_polyJD paJD pb JD pqupre int x ppa-next qpb-next prepa whilepNULL qNULL ifp-expexp prep pp-next else ifp-expq-exp xp-coefq-coef ifx0 p-coefx prep else pre-nextp-next freep ppre-next uq qq-next freeu else uq-nextq-nextppre-nextq preq qu ifqNULL pre-nextq freepbJD dlbjlint aint n JD sh int i hJDmallocsizeofJD h-coefh-exp-1 h-nextNULL forini0i-- sJDmallocsizeofJD s-coefa2i-2 s-expa2i-1 s-nexth-next h-nexts return hvoid dlbxsJD h JD p ph-next whilepNULL printfddtp-coefp-exp pp-next printfnvoid main static int a703198517 static int b81227-98 JD headaheadb int na4nb3 headadlbjlana dlbxsheada headbdlbjlbnb dlbxsheadb add_polyheadaheadb dlbxsheada二叉树的遍历includeincludetypedef struct node char data struct node lchildrchildJDvoid preorderJD bt ifbtNULL printfc bt-data preorderbt-lchild preorderbt-rchild void inorderJD bt ifbtNULL inorderbt-lchild printfc bt-data inorderbt-rchild void postorderJD bt ifbtNULL postorderbt-lchild postorderbt-rchild printfc bt-data JD crt_bt_preJD bt char ch printfch scanfcch getchar ifch btNULL else btJD mallocsizeofJD bt-datach bt-lchildcrt_bt_prebt-lchild bt-rchildcrt_bt_prebt-rchild returnbtvoid main JD headNULL headcrt_bt_prehead preorderhead printfn inorderhead printfn postorderhead printfn二叉排序树的生成includeusing namespace stdstruct treeint datatree rightleftclass Btreetree rootpublic:Btree rootNULLvoid create_btreeintvoid display inorderroot coutleft NULLnewnode-right NULLifrootNULL rootnewnodeelse tree back tree current currentroot whilecurrentNULL backcurrent ifcurrent-datat currentcurrent-left else currentcurrent-right ifback-datat back-left newnode else back-right newnodevoid Btree::inorder tree tmpiftmpNULL inordertmp-left cout