正在加载图片...
《数据结构》实验指导/实验八:查找方法的实现 七、实验内容及步骤 任务:代码实现顺序表的创建、显示、查找:编写应用程序,用相关数据验证运算算法。 实验步骤: (1)启动 sual studio2010,创建窗体应用程序。 (2)创建顺序表的存储结构,包括创建、显示、查找等方法,代码参考如下: struct RecType ∥记录类型 放关键字 i public string data; ∥存放其他数据 class SqlistSearch Class const int max Size 100 ∥顺序表中最多元素个数 public RecTypell r; ∥顺序表 public int length; ∥放顺序表的长度 string sstr 用于返回结果 public sqlistSearchClasso ∥构造函数,用于顺序表的初始化 R=new RecType MaxSizel ∥--0顺序表的基本运算算法一 public void Createlist(stringl split) /由 split中的元素建立顺序表 for(i=0; i< split Length; i++) RIi.key=Convert.Tolnt32(split public string DisplistO 将顺序表L中的所有元素构成一个字符串返回 if (length>0) string mystr= RIO. key ToString(; for(i=1: i< length; i++) 描顺序表中各元素值 mystr+=+ Ri. key ToString(; return mystr; else return"空串"; 管理科学与工程学科/共5页第2页《数据结构》实验指导 / 实验八:查找方法的实现 2 管理科学与工程学科 / 共5页,第2页 七、实验内容及步骤 任务:代码实现顺序表的创建、显示、查找;编写应用程序,用相关数据验证运算算法。 实验步骤: (1) 启动 Visual Studio 2010,创建窗体应用程序。 (2) 创建顺序表的存储结构,包括创建、显示、查找等方法,代码参考如下: struct RecType //记录类型 { public int key; //存放关键字 public string data; //存放其他数据 } class SqListSearchClass { const int MaxSize = 100; //顺序表中最多元素个数 public RecType[] R; //顺序表 public int length; //存放顺序表的长度 string sstr; //用于返回结果 public SqListSearchClass() //构造函数,用于顺序表的初始化 { R = new RecType[MaxSize]; length = 0; } //-----------------顺序表的基本运算算法-------------------------------- public void CreateList(string[] split) //由 split 中的元素建立顺序表 { int i; for (i = 0; i < split.Length; i++) R[i].key = Convert.ToInt32(split[i]); length = i; } public string DispList() //将顺序表 L 中的所有元素构成一个字符串返回 { int i; if (length > 0) { string mystr = R[0].key.ToString(); for (i = 1; i < length; i++) //扫描顺序表中各元素值 mystr += " " + R[i].key.ToString(); return mystr; } else return "空串";
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有