-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayTest.java
More file actions
113 lines (107 loc) · 2 KB
/
Copy pathArrayTest.java
File metadata and controls
113 lines (107 loc) · 2 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// version 1.3
class ArrayTest
{
int a[];
void input(int size)
{
a=new int[size];
for(int i=0 ; i<a.length ; i++)
{
a[i]=(int)(Math.random()*30);
}
System.out.println("array craeted and initialized");
}
void output()
{
for(int i=0 ; i<a.length ; i++)
{
System.out.println(a[i]);
}
}
void sort()
{
for(int i=0 ; i<a.length-1 ;i++)
{
for(int j=i+1 ; j<a.length ; j++)
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
int search(int val)
{
for(int i=0; i<a.length ;i++)
{
if(a[i]==val)
return(i);
}
return(-1);
}
void delete(int val)
{
/*1.search the element
2.create a new array object with size -1
3.copy all the elements into new array except the element to be deleted
4.copy the reference of new array object into a[]*/
}
boolean insert(int val , int loc)
{
if(loc<0 || loc>=a.length)
return(false);
int temp[]=new int[a.length+1];
for(int i=0 ; i<loc-1 ; i++)
{
temp[i]=a[i];
}
temp[loc-1]=val;
for(int i=loc-1 ; i<a.length ; i++)
{
temp[i+1]=a[i];
}
a=temp;
return(true);
}
int[] merge(int b[])
{
int c[]=new int[a.length + b.length];
System.out.println("functionality is not ready");
return(null);
}
int[] union(int b[])
{
System.out.println("method is not ready");
return(null);
}
int[] intersect(int c[])
{
System.out.println("method is not ready");
return(null);
}
}
class ArrayOperationTest
{
public static void main(String s[])
{
int x=Integer.parseInt(s[0]);
ArrayTest al=new ArrayTest();
al.input(x);
System.out.println("List of values: ");
al.output();
al.sort();
System.out.println("sorted list of values: ");
al.output();
if(al.search(25)==-1)
System.out.println("25 not found in the array");
else
System.out.println("25 is exist");
System.out.println("\n Inserting 35 at 3 location");
al.insert(35,3);
System.out.println("list of values after the insertion: ");
al.output();
}
}