正在加载图片...
《数据结构》实验指导/实验-:顺序表的存储及操作 2 七、实验内容及步骤 1、任务一:对于含有n个元素的顺序表L,设计一个算法将其中所有元素逆置,并分析算法的 时间复杂度和空间复杂度。 实验步骤: (1)启动 isual Studio2010,创建窗体应用程序。 (2)增加顺序表类,代码参考如下 class SqlistClass const int MaxSize =100 public stringl data ∥放顺序表中元素 public int length ∥放顺序表的长度 public Sqlistclasso data=new string[ MaxSizel ∥-顺序表的基本运算算法 public void CreateList( string[ split)∥由splt中的元素建立顺序表 for(i=0; 1< split. Length; 1++) data1]=split[1 public string DispListo ∥将顺序表L中的所有元素构成一个字符串返回 for(i=1,i< length;i+)∥扫描顺序表中各元素值 mystr +="" datai 管理科学与工程学科/共6页第2页《数据结构》实验指导 / 实验一:顺序表的存储及操作 2 管理科学与工程学科 / 共6页,第2页 七、实验内容及步骤 1、任务一:对于含有 n 个元素的顺序表 L,设计一个算法将其中所有元素逆置,并分析算法的 时间复杂度和空间复杂度。 实验步骤: (1) 启动 Visual Studio 2010,创建窗体应用程序。 (2) 增加顺序表类,代码参考如下: class SqListClass { const int MaxSize = 100; public string[] data; //存放顺序表中元素 public int length; //存放顺序表的长度 public SqListClass() { data = new string[MaxSize]; length = 0; } //-----------------顺序表的基本运算算法-------------------------------- public void CreateList(string[] split) //由 split 中的元素建立顺序表 { int i; for (i = 0; i < split.Length; i++) data[i] = split[i]; length = i; } public string DispList() //将顺序表 L 中的所有元素构成一个字符串返回 { int i; if (length > 0) { string mystr = data[0]; for (i = 1; i < length; i++) //扫描顺序表中各元素值 mystr += " " + data[i];
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有