import java.io.*;
class ArrayImpl
{
int arr[] = newint[15];
ArrayImpl()
{
for(int i=0;i<10;i++)
{
arr[i]=i+1;
}
}
synchronized void insert(int ele,int pos)
{
System.out.println("Insert element 15 at position 2");
pos = pos - 1;
for(int i=11;i>pos;i--)
arr[i] = arr[i-1];
arr[pos] = ele;
}
synchronized void delet(int pos)
{
System.out.println("Delete element at position 5");
pos = pos - 1;
for(int i=pos ; i< 10 ;i++)
arr[i] = arr[i+1];
}
synchronized void Search(int pos)
{
System.out.println("search element at position 6");
pos = pos - 1;
int v=arr[pos];
System.out.println("position " + (pos+1) + " value is ::" + v);
}
synchronized void display(int len)
{
for(int i=0;i<len;i++)
{
System.out.print(arr[i] + " ");
}
System.out.println();
}
}
class ThreadInsert implements Runnable
{
Thread t;
ArrayImpl a;
int e,p;
ThreadInsert(ArrayImpl aa,int ele,int pos)
{
a=aa;
e=ele;
p=pos;
t = new Thread(this);
t.start();
}
publicvoid run()
{
try
{
a.insert(e,p);
a.display(11);
}catch (Exception e)
{
System.out.print("InterruptedException");
}
}
}
class ThreadDelete implements Runnable
{
Thread t;
ArrayImpl a;
int p;
ThreadDelete(ArrayImpl aa,int pos)
{
a=aa;
p=pos;
t = new Thread(this);
t.start();
}
publicvoid run()
{
try
{
a.delet(p);
a.display(10);
}catch (Exception e)
{
System.out.print("InterruptedException");
}
}
}
class ThreadSearch implements Runnable
{
Thread t;
ArrayImpl a;
int p;
ThreadSearch(ArrayImpl aa,int pos)
{
a=aa;
p=pos;
t = new Thread(this);
t.start();
}
publicvoid run()
{
try
{
a.Search(p);
}catch (Exception e)
{
System.out.print("InterruptedException");
}
}
}
class Array
{
publicstaticvoid main(String args[])
{
ArrayImpl a = new ArrayImpl();
a.display(10);
new ThreadInsert(a,15,2);
new ThreadDelete(a,5);
new ThreadSearch(a,6);
}
}
/*
Output
1 2 3 4 5 6 7 8 9 10
Insert element 15 at position 2
1 15 2 3 4 5 6 7 8 9 10
Delete element at position 5
1 15 2 3 5 6 7 8 9 10
search element at position 6
position 6 value is ::6
*/