-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeData.java
60 lines (45 loc) · 1.08 KB
/
makeData.java
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
/*
* Brett Waugh
* 3 December 2019
* makeData.java
* Creates random data in both
* arrays and linked lists.
*/
public class makeData {
/*
* Creates random data and fills it into an array.
*/
public static int[] randomArr(int max) {
// Allocate space for array data.
int[] data = new int[max];
// Creates the maximum number of random data points from one to one-thousand.
for (int i = 0; i < data.length; i++) {
data[i] = (int) (Math.random() * 1000 + 1);
}
return data;
}
/*
* Takes the random data from the array and fills it into a linked list.
*/
public static linked randomLi(int[] data) {
linked li = new linked();
for (int i = 0; i < data.length; i++) {
li.push(data[i]);
}
return li;
}
/*
* Takes the random data from the array and fills it into a heap.
*/
public static Heap randomHeap(int[] data, int max) {
Heap theHeap = new Heap(max);
int temp = 0;
for (int i = 0; i < max; i++) {
temp = data[i];
Hnode newNode = new Hnode(temp);
theHeap.insertAt(i, newNode);
theHeap.incrementSize();
}
return theHeap;
}
}