complete the code: Lock lock;
Node(int item) f this.key = item; this.next=null; this.lock
void lock() (lock.lock();)
void unlock() flock.unlock();)
new Reentrantlock();
blic boolean add(int item) (// Insert Operation
Node pred=null, curr=null;
int key = item;
head.lock();
try
pred = head;
curr= pred.next;
curr.lock();
while (curr.key key) f // if curr.key >= key then come out
pred.unlock();
pred
curr;
curr = curr.next;
I
curr.lock();|
if (curr.key == key)f return false; ) // Unseccessful insertion
Node newNode = new Node(item); // if key is not present then insert
newNode.next = curr;
pred.next= newNode;// LP of add() method
return true;
Successful insertion
)finally f curr.unlock(); pred.unlock(); )// unlock both nodes (i.e., curr and pred)
public boolean remove(int item) (// Remove Operation
Node pred null, curr
null;FineList.javat/
port java.util.concurrent locks.Lock;
port java.util.concurrent.locks.Reentrantlock;
blic class Finelist(
private Node head;
public FineList() (
head = new Node(Integer.MIN_VALUE);
head.next new Node(Integer.MAX_VALUE);
ivate class Node // Node Class
int key;
Node next;
Node (int item) ( this.key = item; this.nextenull; this.lock
Lock lock;
void lock() flock.lock();)
void unlock() (lock.unlock();)
new Reentrantlock(); )
blic boolean add(int item) (// Insert Operation
Node pred=null, curr=null;
int key = item;
head.lock();
try
pred
head;
curr
pred.next;
while (curr.key key) f// if curr.key >= key then come out
curr.lock();
pred.unlock();
pred
curr;
curr= curr.next;pred.unlock();

pred curr; curr curr.next, curr.lock();

if (curr.key key) { return false; } // Unseccessful insertion

Node newNode = new Node(item); // if key is not present then insert

newNode.next = curr; pred next newNode;// LP of add() method return true; // Successful insertion

finally { curr.unlock(); pred.unlock(); } // unlock both nodes (1.e., curr and pred)

public boolean remove(int item) {// Remove Operation

Node pred null, curr = null;

int key item;

head.lock();

try { pred head; curr pred.next; curr.lock();

while (curr.key key) (

pred.unlock(); pred curr;

curr curr.next;

curr.lock();

if (curr.key key) { pred.next curr.next; // LP of remove (curr.key == key)
pred.next curr.next; // LP of remove
return true;
return false;
finally ( curr.unlock(); pred.unlock(); )// Unlock both nodes
public boolean contains(int item) (//Contains Operation
Node pred = null, curr = null;
int key = item;
head.lock();
try
pred
head; curr
pred.next;
//curr.lock();
while (curr.key key)
// pred.unlock();
pred
curr;
curr = curr.next;
//curr.lock();
I
return (curr.key == key); // LP of contains
finally /*curr. unlock(); pred unlock();*/ M1 Unlock both nodes
public void display()
Node temp=head;
while(temp.next!=null)fpublic boolean contains(int item) (//Contains Operation

Node pred null, curr null;

int key item;

// head.lock();

try { pred head; curr pred.next;

//curr.lock();

while (curr.key < key) {

// pred.unlock(); pred = curr;

curr curr.next;

//curr.lock();

return (curr.key = key); // LP of contains

} finally (curr.unlock(); pred.unlock();*/ }// Unlock both nodes

public void display()

Node temp=head;

while(temp.next!=null){

System.out.print("\t"+temp.key);

tempstemp.next;