RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
java项目如何使用链表-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

创新互联建站2013年至今,是专业互联网技术服务公司,拥有项目网站设计、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元如皋做网站,已为上家服务,为如皋各地企业和个人服务,联系电话:13518219792

今天就跟大家聊聊有关java项目如何使用链表,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

java 中链表的定义与使用方法

Java实现链表主要依靠引用传递,引用可以理解为地址,链表的遍历多使用递归,这里我存在一个疑问同一个类的不同对象的的相同方法的方法内调用算不算递归.

这里我写的是单向链表;

实例代码:

package com.example.java;

public class MyLink {

public static void main(String [] args){ 

Link l=new Link(); 
  mytype[] la; 
  mytype dsome=new mytype("韩敏","dsome",21); 
  mytype shao=new mytype("邵晓","john",45); 
  mytype hua=new mytype("华晓风","jam",46); 
  mytype duo=new mytype("余小风","duo",1000); 
  mytype wang=new mytype("王秋","jack",21); 
  mytype shi=new mytype("韩寒","bob",3000); 
  mytype yu=new mytype("于冬","keven",30); 

l.add(dsome);//测试增加节点 
  l.add(shao); 
  l.add(hua); 
  l.add(wang); 
  l.add(shi); 
  l.add(duo); 
  l.add(yu); 

  System.out.println("链表长度:"+l.length());//链表长度 
  la=l.toArray(); 
  for(int i=0;i=this.count||index<0){ 
     System.out.print("越界错误");//测试用 
     return null; 
    }else{ 
     this.foot=0; 
     return this.root.getNode(index); 
    } 
   } 

   public boolean contains(mytype data){//判断链表数据是否含data 
    if(data==null) 
     return false; 
    return this.root.iscontain(data); 
   } 

   public void remove(mytype data){//删除指定数据节点 
    if(this.contains(data)){ 
     if(this.root.data.equals(data)){ 
      this.root=this.root.next; 
      this.count--;   
     } 
     else{ 
      this.count--; 
      this.root.next.removeNode(root,data); 
     } 
    }else{ 
     System.out.print("删除错误");//测试用     
    } 
   } 

   public mytype[] toArray(){//把链表转化成对象数组 
    if(this.count==0){ 
     return null; 
    } 
     this.foot=0; 
     this.Larray=new mytype [this.count]; 
     this.root.toArrayNode(); 
     return this.Larray;     
   }     
}


package com.example.java;

public class mytype {

private String name; 
private String people; 
private int age;

public mytype(String name,String people,int age){//链表中的数据(可自定义) 
  this.name=name; 
  this.people=people; 
  this.age=age; 
 } 
 public boolean equals(mytype data){//判断数据是否相同 
  if(this==data){ 
   return true; 
  } 
  if(data==null){ 
   return false; 
  } 
  if(this.name.equals(data.name)&&this.people.equals(data.people)&&this.age==data.age){ 
   return true; 
  }else{ 
   return false; 
  } 
 }
public String getName() {
  return name;
}
public void setName(String name) {
  this.name = name;
}
public String getPeople() {
  return people;
}
public void setPeople(String people) {
  this.people = people;
}
public int getAge() {
  return age;
}
public void setAge(int age) {
  this.age = age;
} 

public String getInfo(){ 
  return "名字 :"+this.name+"\n"+ 
      "人物 :"+this.people+"\n"+ 
      "年龄 :"+this.age; 
 }   
}

网站标题:java项目如何使用链表-创新互联
分享链接:http://sczitong.cn/article/cdsepj.html