正在加载图片...
《数据结构》实验指导/实验九:排序方法的实现 2 七、实验内容及步骤 任务:代码实现顺序表的创建、显示、排序;编写应用程序,用相关数据验证算法。 实验步骤: (1)启动 sual studio2010,创建窗体应用程序。 (2)创建顺序表的存储结构,包括创建、显示、直接插入排序、快速排序、直接选择排序 等方法,代码参考如下 struct RecType public int key; public string data; }; class InterSort class const int MaxSize 10000: public RecTypell r; public int length string sstr; public InterSortClasso R=new recType MaxSize; h= new Radixnodeo; 顺序表的基本运算和排序算法 public void Createlist(stringl l split) for(i=0; i< split Length; i++) RIil key=Convert. Tolnt16(splitiD) public string Displisto ∥将顺序表L中的所有元素构成一个字符串返回 if (length >0) string mystr= RO.key. ToString0; for(i=1;i<length; i++) 描顺序表中各元素值 mystr+=+RIi. keyToString 0; return mystr; 管理科学与工程学科/共5页第2页《数据结构》实验指导 / 实验九:排序方法的实现 2 管理科学与工程学科 / 共5页,第2页 七、实验内容及步骤 任务:代码实现顺序表的创建、显示、排序;编写应用程序,用相关数据验证算法。 实验步骤: (1) 启动 Visual Studio 2010,创建窗体应用程序。 (2) 创建顺序表的存储结构,包括创建、显示、直接插入排序、快速排序、直接选择排序 等方法,代码参考如下: struct RecType { public int key; public string data; }; class InterSortClass { const int MaxSize = 10000; public RecType[] R; public int length; string sstr; public InterSortClass() { R = new RecType[MaxSize]; length = 0; h = new RadixNode(); } //-----------------顺序表的基本运算和排序算法-------------------------------- public void CreateList(string[] split) { int i; for (i = 0; i < split.Length; i++) R[i].key = Convert.ToInt16(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; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有