forked from sensei-thundercleese/closet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperArray_v1.java
More file actions
73 lines (54 loc) · 1.74 KB
/
Copy pathSuperArray_v1.java
File metadata and controls
73 lines (54 loc) · 1.74 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
/*==================================================
class SuperArray
Wrapper class for array. Facilitates resizing,
getting and setting element values.
==================================================*/
public class SuperArray {
private int[] _data;
private int _lastPos;
private int _size;
//default constructor
//initializes 10-item array
public SuperArray() {
// *** YOUR IMPLEMENTATION HERE ***
}
//output array in [a,b,c] format
//eg, for int[] a = {1,2,3} ...
//toString() -> "[1,2,3]"
public String toString() {
// *** YOUR IMPLEMENTATION HERE ***
return "foo"; //placeholder
}
//double capacity of this instance of SuperArray
private void expand() {
// *** YOUR IMPLEMENTATION HERE ***
}
//accessor method -- return value at specified index
public int get( int index ) {
// *** YOUR IMPLEMENTATION HERE ***
return -1;
}
//mutator method -- set index to newVal, return old value at index
public int set( int index, int newVal ) {
// *** YOUR IMPLEMENTATION HERE ***
return -1;
}
//main method for testing
public static void main( String[] args ) {
/*===========================================
SuperArray curtis = new SuperArray();
System.out.println( "Printing empty SuperArray curtis..." );
System.out.println( curtis );
for( int i = 0; i < curtis._data.length; i++ ) {
curtis.set( i, i * 2 );
}
System.out.println("Printing populated SuperArray curtis...");
System.out.println(curtis);
for( int i = 0; i < 3; i++ ) {
curtis.expand();
System.out.println("Printing expanded SuperArray curtis...");
System.out.println(curtis);
}
===========================================*/
}
}//end class SuperArray