/**
 * 超级简单的数组加单链表实现Map
 * @author jlj
 *
 */
public class MyHashMap {
	
	public MyList[] lists;
	public int initSize = 10;
	
	public MyHashMap(){
		lists = new MyList[initSize];
	}
	
	public void addNode(Node node){
		int id = node.id;
		MyList list = lists[id % initSize];
		
		if(list == null){
			MyList l = new MyList();
			l.headNode = node;
			lists[id % 10] = l;
		} else {
			Node headNode = list.headNode;
			while(headNode.next != null){
				headNode = headNode.next;
			}
			headNode.next = node;
		}
	}
	
	public static void main(String[] args) {
		MyHashMap map = new MyHashMap();
		map.addNode(new Node(1));
		map.addNode(new Node(0));
		map.addNode(new Node(3));

		map.addNode(new Node(10));
		System.out.println(map.lists.length);
		System.out.println(map.lists[0]);
	}
	
	
}


class Node{
	public int id;
	public Node next;
	public Node(int id) {
		super();
		this.id = id;
	}
	@Override
	public String toString() {
		return "Node [;
	}
	
	
	
}

class MyList{
	public Node headNode;

	@Override
	public String toString() {
		return "MyList [headNode=" + headNode + "]";
	}
	
	
}

相关文章:

  • 2021-08-11
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2021-11-29
  • 2022-12-23
  • 2021-08-31
猜你喜欢
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案