class EmpNode{
public int id;
public String name;
public EmpNode pNext;//默认为null//构造器
public EmpNode(int id, String name){
this.id = id;
this.name = name;}
@Override
public String toString(){return"EmpNode{"+"id="+ id +", name='"+ name +'\''+'}';}}
class EmpList{//头指针,指向第一个雇员
private EmpNode head;//默认为空//成员方法//插入,直接插入到链表最后
public voidadd(EmpNode newNode){//如果链表为空if(null == head){
head = newNode;return;}//链表不为空else{
EmpNode cur = head;while(null != cur.pNext){
cur = cur.pNext;}
cur.pNext = newNode;}}//遍历
public voidtraverse(int no){if(null == head){
System.out.println(no +"号链表为空!");}else{//链表不为空
System.out.println(no +"号链表的信息为:");
EmpNode cur = head;while(null != cur){
System.out.println(cur);
cur = cur.pNext;}
System.out.println("当前链表遍历完毕!");}}//查找
public voidfindById(int id){if(null == head){
System.out.println("链表为空,查找失败");return;}
EmpNode cur = head;while(null != cur){if(cur.id == id){
System.out.println("找到了,员工信息为:"+cur);return;}
cur = cur.pNext;}
System.out.println("该员工不存在");}}
class HashTab{
private EmpList[] empListArray;
private int size;//共有多少条链表//构造器
public HashTab(int size){
this.empListArray = new EmpList[size];for(int i =0; i < size; i ++){
empListArray[i]= new EmpList();}
this.size = size;}//散列函数
public inthashFun(int id){return id % size;}//插入
public voidadd(EmpNode newNode){//根据员工id添加
empListArray[hashFun(newNode.id)].add(newNode);}//遍历
public voidtraverse(){for(int i =0; i < size; i++){
empListArray[i].traverse(i);}}//查找
public voidfindById(int id){
empListArray[hashFun(id)].findById(id);}}
文章目录实现代码实现代码class EmpNode{ public int id; public String name; public EmpNode pNext;//默认为null //构造器 public EmpNode(int id, String name){ this.id = id; this.name = name; } @Override public String toString()