Datasets:

ArXiv:
License:
File size: 990 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
public class Ch{

  static int size = 7;
  // should be prime number 

  
  static class Node{
    int data;
    Node next;

    Node(int d){
      data = d;
      next = null;
    }
  }

  static Node chain[] = new Node[size];
 static void arr(){

    for(int i=0; i<size; i++){
      chain[i] = null;
    }
  }

  static void insert(int key){
   Node t = new Node(key);

   int index = key%size;
   if(chain[index]==null){
     chain[index] = t;
   }
   else{
     Node temp = chain[index];
     while(temp.next!=null){
       temp = temp.next;
     }
     temp.next = t;
   }
  }

  static void print(){
    for(int i=0;i<size;i++){
      Node temp = chain[i];
      System.out.print("Chain "+i+" -->");

      while(temp!=null){
        System.out.print(temp.data+" -->");
        temp = temp.next;
      }

    System.out.println("EMpty");
    }
  }

  public static void main(String[] args){
    arr();
    insert(4);
    insert(2);
    insert(5);
    insert(12);

    print();
  }
}