




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
_数据结构实验报告说明:本软件在win7 64位系统测试通过,需要安装.net 3.5以上版本七、数制转换问题1.问题描述对于输入的任意一个非负十进制整数,输出与其等值的其他进制数(二进制、八进制或十六进制)。2.任务要求 建立模型,确定存储结构; 对任意十进制数,实现进制转换问题。 3.实验指导(1) 实验类型:设计实验。本实验要求同学们针对“数制转换”这个经典的问题,应用栈的存储结构,自己设计一个方案,并上机实现。此实验的目的是培养学生对数据结构的简单应用能力。(2) 预备知识:栈的基本定义、栈的基本操作算法、栈的存储结构。(3) 实现方法提示:1) 以十进制转换为八进制为例。将十进制数整除8,计算过程中得到的余数依次进栈,按出栈序列输出栈中的内容即为与输入的十进制数对应的八进制数。设Conversion函数执行数制转换的操作,对(1348)10 转换为8进制的过程如下:NN div 8N mod 81348168416821021252022) 设计数制转换的算法。4.实现方案1) 方案描述: 本方案采用语言实现,实现十进制与其他进制直接的转换2) 实现代码:主要实现代码如下using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace 进制转换器 public partial class MainFrm : Form public MainFrm() InitializeComponent(); private void MainFrm_Load_1(object sender, EventArgs e) txtStart.Focus(); / / 十进制转换为八进制 / / / private void radio_dto_Click_1(object sender, EventArgs e) txtEnd.Text = ; if (txtStart.Text.Length != 0) / TODO: 十进制转为八进制。 Int32 i; try i = Convert.ToInt32(txtStart.Text.Trim(); lblTitle.Text = 十进制转为八进制; txtEnd.Text = Convert.ToString(i, 8); catch MessageBox.Show(请输入合法的十进制数, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show(请提供转换数据!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtStart.Focus(); / / 十进制转换为十六进制 / / / private void radio_dth_Click(object sender, EventArgs e) txtEnd.Text = ; if (txtStart.Text.Length != 0) / TODO: 十进制转换为十六进制。 Int32 i; try i = Convert.ToInt32(txtStart.Text.Trim(); lblTitle.Text = 十进制转换为十六进制; txtEnd.Text = Convert.ToString(i, 16); catch MessageBox.Show(请输入合法的十进制数, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show(请提供转换数据!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtStart.Focus(); / / 十进制转换为二进制 / / / private void radio_dtb_Click(object sender, EventArgs e) txtEnd.Text = ; if (txtStart.Text.Length != 0) / TODO: 十进制转换为二进制。 Int32 i; try i = Convert.ToInt32(txtStart.Text.Trim(); lblTitle.Text = 十进制转换为二进制; txtEnd.Text = Convert.ToString(i, 2); catch MessageBox.Show(请输入合法的十进制数, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show(请提供转换数据!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtStart.Focus(); / / 八进制到十进制 / / / private void radio_otd_Click(object sender, EventArgs e) txtEnd.Text = ; if (txtStart.Text.Length != 0) / TODO: 八进制到十进制。 try lblTitle.Text = 八进制到十进制; txtEnd.Text = Convert.ToString(Convert.ToInt32(txtStart.Text.Trim(), 8);/八进制转为十进制 catch MessageBox.Show(请提供合法的八进制数, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show(请提供转换数据!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtStart.Focus(); / / 十六进制到十进制 / / / private void radio_htd_Click(object sender, EventArgs e) txtEnd.Text = ; if (txtStart.Text.Length != 0) try / TODO: 十六进制到十进制。 lblTitle.Text = 十六进制到十进制; txtEnd.Text = Convert.ToString(Convert.ToInt32(txtStart.Text, 16); catch MessageBox.Show(请提供合法的十六进制数!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show(请提供转换数据!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtStart.Focus(); / / 二进制到十进制 / / / private void radio_btd_Click(object sender, EventArgs e) txtEnd.Text = ; if (txtStart.Text.Length != 0) try / TODO: 二进制到十进制。 lblTitle.Text = 二进制到十进制; txtEnd.Text = Convert.ToString(Convert.ToInt32(txtStart.Text, 2); catch MessageBox.Show(请提供合法的二进制数!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); else MessageBox.Show(请提供转换数据!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtStart.Focus(); private void reset_Click(object sender, EventArgs e) txtStart.Text = ; txtEnd.Text = ; txtStart.Focus(); private void close_Click(object sender, EventArgs e) this.Close(); 3) 测试过程:1. 不输入数据,软件会温馨提示2输入数据选择转换模式3.测试完成,结果正确十四、Huffman编码1.问题描述设某编码系统共有个字符,使用频率分别为,设计一个不等长的编码方案,输出每个字符对应的编码,使得该编码系统的空间效率最好。2.任务要求 掌握Huffman树的概念、特点和存储结构; 掌握Huffman树的构造算法; 运用Huffman树解决编码问题。 3.实验指导(1) 实验类型:设计实验。本实验要求同学们针对“Huffman树”这个经典的问题,应用二叉树这种数据结构,自己设计一个解决方案,并上机实现。此实验目的是培养学生对数据结构的简单应用能力。(2) 预备知识:二叉树的定义、二叉树的基本操作算法。(3) 实现方法提示:1) 以字符出现的次数为权值,个结点作为根结点分别构成棵二叉树;2) 所有二叉树中选取两棵根结点权值最小的树作为左右子树构造一棵新二叉树,新二叉树根结点的权值为左右子树上根结点的权值之和,并删除原先的两棵二叉树;3) 重复上述步骤,直到只剩一棵二叉树为止。4) Huffman树的存储结构如下: struct unsigned int weight; unsigned int parent, lchild, rchild;HTNode, *HuffmanTree;4.实现方案1) 方案描述: 本方案采用语言实现数据的Huffman编码与解码2) 实现代码:主要实现代码如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Collections.Specialized;namespace HuffmanCode public partial class Form1 : Form class Node public char code; public uint prioirry; public Node lchild; public Node rchild; public Form1() InitializeComponent(); private Dictionary dictcode = new Dictionary(); private Node huffTree; private int comparisonNode(Node n1, Node n2) return (int)(n1.prioirry - n2.prioirry); private string encode(string str) dictcode.Clear(); huffTree = null; if (string.IsNullOrEmpty(str) return ; Dictionary priorityQueue = new Dictionary(); for (int i = 0; i str.Length; i+) if (priorityQueue.ContainsKey(stri) priorityQueuestri+; else priorityQueue.Add(stri, 1); List listpc = new List(); foreach (var item in priorityQueue) listpc.Add(new Node() prioirry = item.Value, lchild = null, rchild = null, code = item.Key ); listpc.Sort(comparisonNode); while (listpc.Count 1) Node n = new Node(); n.prioirry = listpc0.prioirry + listpc1.prioirry; n.lchild = listpc0; n.rchild = listpc1; listpc.RemoveAt(0); listpc.RemoveAt(0); int index = -1; for (int i = 0; i listpc.Count; i+) if (n.prioirry = listpci.prioirry) index = i; break; if (index = -1) index = listpc.Count; listpc.Insert(index, n); string encodestr = ; viewTree(listpc0, ); huffTree = listpc0; for (int i = 0; i str.Length; i+) encodestr += dictcodestri; return encodestr; private void viewTree(Node n, string v) if (n.code != 0) dictcode.Add(n.code, v); else if (n.lchild != null) string vl = v + 0; viewTree(n.lchild, vl); if (n.rchild != null) string vr = v + 1; viewTree(n.rchild, vr); private string decode(string str) Node root = huffTree; string result = ; for (int i = 0; i str.Length; i+) if (root
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025福建师范大学招聘管理助理、教学助理岗位人员28人笔试模拟试题及答案解析
- 2025天津汇融商业管理有限公司招聘1人笔试模拟试题及答案解析
- 2025下半年浙江温州市永嘉县事业单位招聘34人笔试参考题库附答案解析
- 2025浙江绍兴市强制医疗所招聘1名编外人员笔试备考题库及答案解析
- 工厂安全生产操作规程指南
- 2025重庆渝海物业管理有限责任公司外包岗位招聘1人考试备考试题及答案解析
- 2025云南省招募秋季学期基础教育银龄教师(719人)笔试参考题库附答案解析
- 2025安徽宿州灵璧县大学生乡村医生专项计划招聘8人笔试模拟试题及答案解析
- 2025四川九洲电器集团有限责任公司招聘天线测试岗1人笔试备考题库及答案解析
- 2025浙江湖州市南浔区乡镇(街道)专职消防队人员招聘3人考试参考题库附答案解析
- GB∕T 9286-2021 色漆和清漆 划格试验
- 【英语】人教版英语八年级英语下册阅读理解专题复习练习(含解析)
- 《植物生理学》课件第四章+植物的呼吸作用
- 720全景照片制作方案及发布流程
- 2022年出差管理制度员工出差管理制度
- 工作责任心主题培训ppt课件(PPT 26页)
- 完整解读新版《英语》新课标2022年《义务教育英语课程标准(2022年版)》PPT课件
- 国家公交都市评价指标体系
- 田湾核电站常规岛系统培训教材VVER
- 一规定两守则题库
- 手诊纹路课件
评论
0/150
提交评论