数据结构试验-线性表精要.doc

数据结构试验-线性表精要

实验目的和要求: 1.熟练掌握连表的实现, 2,编写出可执行的程序 内容和步骤: 1、 ? ?需求分析 程序的功能; 用户输入记录的name和索引,程序将记录加到连表里,用户输入记录的索引,可以 进行查找和删除,可在用户想要得位置插入记录。 2. ? ?输入输出的要求; 主要有三项输入,为记录的名称,索引,插入的位置。名称为字符串,索引和位置为 整数。 3. ? ?测试数据。 要求输入必须符合输入要求,否则显示消息。 2、 ? ?概要设计 本程序所用的抽象数据类型的定义; 连表类的定义如下 连表的初始化,查找,删除,追加 原码如下 1 如果在链式线性表中加入统计功能,例如统计存储记录中姓氏的数量,请用C#完成这个功能; namespace h { /// 1 如果在链式线性表中加入统计功能,例如统计存储记录中姓氏的数量,请用C#完成这个功能; class Class1 { static void Main(string[] args) { stu824 l=new stu824() ; student A=new student (); A._name =李玮; A._ID =10; A.next=null; l.Append_stu824 (l,A); A._name =赵龙山; A._ID =10; A.next=null; l.Append_stu824 (l,A); A._name =潘天路; A._ID =10; A.next=null; l.Append_stu824 (l,A); A=l.get_value (l,1); string s; char[] a=new char [10]; A._name .CopyTo(0,a,0,1); Console.WriteLine ( {0},a[0] ); l.test_familyname (l); } } class student { //元素定义 private int ID private string name; public student next; public int _ID { get{return ID} set{ID=value;} } public string _name { get{return name;} set{name=value;} } public student() { ID=0; name=; next=null; } } class stu824 { student head =new student (); student tail=new student (); int lenth; public stu824() { head.next =tail; tail =head; lenth=0; } public int get_lenth(stu824 l) { return l.lenth ; } public student get_value(stu824 l,int n) { student stu=new student (); stu=l.head ; for(int i=0;in;i++) { if (stu!=null) stu=stu.next ; } return stu; } public bool Append_stu824(stu824 l,student A) { student stu=new student (); stu._ID =A._824; stu._name =A._name ; stu.next =null; l.tail.next=stu ; l.tail =stu ; l.lenth ++; return true; } public bool test_familyname(stu824 l) {//完成姓氏统计功能 student A=new student (); char[] s=new char [10]; int [] n=new int [10]; A=l.head .next ; int i=0

文档评论(0)

1亿VIP精品文档

相关文档