-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeList.java
More file actions
127 lines (122 loc) · 2.82 KB
/
Copy pathTimeList.java
File metadata and controls
127 lines (122 loc) · 2.82 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
public class TimeList
{
public static void main(String[] args)
{
if(args.length != 2)
System.out.println("Usage: java TimeList list-type head-or-tail ");
System.exit(1);
}
// First argument is either linked or array and specifies whether a List12
// singly-linked list impletation or an ArrayList will be used
String S = String.parse(args[0]);
// Second argument: either front or back
// Specifies whether elements will be added to the front or the back of
// the list
String I = Integer.parseInt(args[1]);
int N = 2000;
int Max = 50000;
int Incre = 1000;
if(S.equalsIgnoreCase("linked")==true && I.equalsIgnoreCase("front")==true)
{
List<String> theL = new List12<String>();
for(int i = 0; i < N; i++)
{
theL.add(0, null);
}
}
if(S.equalsIgnoreCase("linked")==true && I.equalsIgnoreCase("back")==true)
{
List<String> theL = new List12<String>();
for(int i = 0; i < N; i++)
{
theL.add(i, null);
}
}
if(S.equalsIgnoreCase("array")==true && I.equalsIgnoreCase("front")==true)
{
List<String> theA = new ArrayList<String>();
for(int i = 0; i < N; i++)
{
theA.add(0, null);
}
}
if(S.equalsIgnoreCase("array")==true && I.equalsIgnoreCase("back")==true)
{
List<String> theA = new ArrayList<String>();
for(int i = 0; i < N; i++)
{
theA.add(i, null);
}
}
/**
if(S.equalsIgnoreCase("linked")==true)
{
List<String> theL = new List12<String>();
if(I.equalsIgnoreCase("front")==true)
{
for(int i = 0; i < N; i++)
{
theL.add(0, null);
}
}
if(I.equalsIgnoreCase("back") == true)
{
for(int i = 0; i<N; i++)
{
theL.add(i, null);
}
}
}
*/
/**
if(S.equalsIgnoreCase("array") == true)
{
List<String> theA = new ArrayList<String>();
if(I.equalsIgnoreCase("front") == true)
{
for(int i = 0; i < N; i++)
{
theA.add(0, null);
}
}
if(I.equalsIgnoreCase("back") == true)
{
for(int i = 0; i < N; i++)
{
theA.add(i, null);
}
}
}
*/
for(int j = 2000; j < 50000; j+=1000)
{
IntegerList myList = new IntegerList(j);
double exTime[] = new double [T];
for(int k = 0; k < T; k++)
{
for(int l = 0; l < j; l++)
{
myList.add(1);
}
long start = System.nanoTime();
myList.removeRangeV2(0, j/2);
long end = System.nanoTime();
double diff = (double)((end - start)/1.0e9);
exTime[k] = diff;
myList.clear();
System.gc();
}
computeAndDisplay(exTime, j/2);
}
}
public static void computeAndDisplay(double arr[], int rem)
{
double sum = 0;
int len = arr.length;
for(int i = 0; i< len; i++)
{
sum += arr[i];
}
double mean = sum/len;
System.out.format("%d %.5f \n", rem, mean);
}