- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeycount.java
More file actions
Latest commit
51 lines (49 loc) · 833 Bytes
/
Copy pathKeycount.java
File metadata and controls
51 lines (49 loc) · 833 Bytes
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
//counting the number of keys in the linked list
classKeycount
{ Nodehead;
staticclassNode
{
intdata;
Nodenext;
Node(intd)
{
data = d; //using this pointer
next=null;
}
}
publicvoidinsert(intelement)
{
Noden = newNode(element);
n.next=head;
head=n;
}
intcountkey(intkey)
{
Nodepresent=head;
intc=0; //initializing variable for count
while(present!=null)
{
if(present.data==key)
{
c++;
}
present=present.next;
}
returnc;
}
publicstaticvoidmain(Stringargs[])
{
Keycountkn = newKeycount();
kn.insert(100);
kn.insert(99);
kn.insert(98);
kn.insert(97);
kn.insert(100);
kn.insert(99);
kn.insert(100);
kn.insert(96);
kn.insert(100);
kn.insert(98);
System.out.println("Count of 100 in the key list is "+kn.countkey(100));
}
}