数据结构实验2线性表.docVIP

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
  4. 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
  5. 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们
  6. 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
  7. 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
数据结构实验2线性表

实验报告二 线性表 班级: 姓名: 学号: 专业: 实验目的: 理解线性表的逻辑结构、两种存储结构和数据操作; 应用顺序表的基本算法实现集合A=AUB算法,应用顺序表的基本算法实现两有序顺序表的归并算法; 掌握单链表的遍历、插入和删除等操作算法,实现多项式相加。 实验内容: 1、设有线性表 LA=(3,5,8,11)和 LB=(2,6,8,9,11,15,20); ① 若LA和LB分别表示两个集合A和B,求新集合 A=A U B(‘并’操作,相同元素不保留); 预测输出:LA=(3,5,8,11,2,6,9,15,20) 实现代码: package Ex1; public class Point { int a=0; public Point next=null; public Point(int a){ this(a,null); } public Point(int a, Point next) { this.a=a; this.next=next; } } ----------------------------------- package Ex1; public class SeqList { private Point head=null; private Point tail=null; public SeqList(){ head=null; tail=null; } public boolean isEmpty(){ return head==null; } public void addHead(int a){ head=new Point(a,head); if(tail==null) tail=head; } public void addTail(int a){ if(isEmpty()){ this.addHead(a); } else{ Point temp=new Point(a); tail.next=temp; tail=tail.next; } } public boolean Find(int a){ if(isEmpty()) return false; else{ for(Point temp=head;temp!=null;temp=temp.next){ if(temp.a==a) return true; } } return false; } public void addList(SeqList list){ for(Point temp=list.head;temp!=null;temp=temp.next){ if(Find(temp.a)){ continue; } else{ Point temp1=new Point(temp.a); tail.next=temp1; tail=tail.next; } } } public void Pri() { // TODO Auto-generated method stub for(Point temp=head;temp!=null;temp=temp.next){ System.out.printf(%4d,temp.a); } } } ------------------------ package Ex1; public class Test { static int[] x={3,5,8,11}; static int[] x1={2,6,8,9,11,15,20}; static SeqList List1=new SeqList(); static SeqList List2=new SeqList(); public static void Def(){ for(int i=0;ix.length;i++){ List1.addTail(x[i]); } for(int i=0;ix1.length;i++){ List2.addTail(x1[i]); } } public static void Pri(){ System.out.println(链表内容为:); List1.Pri(); System.out.println(); List2.Pri()

文档评论(0)

jdy261842 + 关注
实名认证
文档贡献者

分享好文档!

1亿VIP精品文档

相关文档