File tree Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Original file line number Diff line number Diff line change
1
+ package dataStructures ;
2
+
3
+ import java .util .Arrays ;
4
+
5
+ public class MyList <E > {
6
+ private int size = 0 ;
7
+ private static final int DEFAULT_CAPACITY = 10 ;
8
+ private Object elements [];
9
+
10
+ public MyList () {
11
+ elements = new Object [DEFAULT_CAPACITY ];
12
+ }
13
+
14
+ public void add (E e ) {
15
+ if (size == elements .length ) {
16
+ ensureCapa ();
17
+ }
18
+ elements [size ++] = e ;
19
+ }
20
+
21
+
22
+ private void ensureCapa () {
23
+ int newSize = elements .length * 2 ;
24
+ elements = Arrays .copyOf (elements , newSize );
25
+ }
26
+
27
+ @ SuppressWarnings ("unchecked" )
28
+ public E get (int i ) {
29
+ if (i >= size || i <0 ) {
30
+ throw new IndexOutOfBoundsException ("Index: " + i + ", Size " + i );
31
+ }
32
+ return (E ) elements [i ];
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ package dataStructures ;
2
+
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
6
+ //import org.junit.Test;
7
+ //
8
+ //import static org.junit.Assert.assertTrue;
9
+
10
+ public class MyListTest {
11
+
12
+
13
+ // @Test(expected=IndexOutOfBoundsException.class)
14
+ // public void testMyList() {
15
+ // MyList<Integer> list = new MyList<Integer>();
16
+ // list.add(1);
17
+ // list.add(2);
18
+ // list.add(3);
19
+ // list.add(3);
20
+ // list.add(4);
21
+ // assertTrue(4 == list.get(4));
22
+ // assertTrue(2 == list.get(1));
23
+ // assertTrue(3 == list.get(2));
24
+ //
25
+ // list.get(6);
26
+ // }
27
+
28
+
29
+ // @Test(expected=IndexOutOfBoundsException.class)
30
+ // public void testNegative() {
31
+ // MyList<Integer> list = new MyList<Integer>();
32
+ // list.add(1);
33
+ // list.add(2);
34
+ // list.add(3);
35
+ // list.add(3);
36
+ // list.add(4);
37
+ // list.get(-1);
38
+ // }
39
+ //
40
+ // @Test(expected=IndexOutOfBoundsException.class)
41
+ // public void testList() {
42
+ // List<Integer> list = new ArrayList<Integer>();
43
+ // list.add(1);
44
+ // list.add(2);
45
+ // list.add(3);
46
+ // list.add(3);
47
+ // list.add(4);
48
+ // assertTrue(4 == list.get(4));
49
+ // assertTrue(2 == list.get(1));
50
+ // assertTrue(3 == list.get(2));
51
+ //
52
+ // list.get(6);
53
+ // }
54
+
55
+
56
+
57
+ }
Original file line number Diff line number Diff line change
1
+ package dataStructures .sorting ;
2
+
3
+ public class MergeSort {
4
+ public static void main (String [] args ) {
5
+
6
+ System .out .println ("data" );
7
+
8
+ }
9
+
10
+ public String [] merge (String [] data ) {
11
+ String [] sortedData ;
12
+
13
+
14
+ return null ;
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments