File tree Expand file tree Collapse file tree 7 files changed +197
-0
lines changed
group17/116665530/homework/src/com/coding/basic Expand file tree Collapse file tree 7 files changed +197
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class MyArrayList implements MyList {
4
+ private int size = 0 ;
5
+ private Object [] elementData = new Object [100 ];
6
+
7
+ public void add (Object o ){
8
+ elementData [size ++] = o ;
9
+ }
10
+ public void add (int index , Object o ){
11
+ for (int i = size ; i > index ; i --)
12
+ {
13
+ elementData [i ] = elementData [i - 1 ];
14
+ }
15
+ elementData [index ] = o ;
16
+ size ++;
17
+ }
18
+
19
+ public Object get (int index ){
20
+ return elementData [index ];
21
+ }
22
+
23
+ public Object remove (int index ){
24
+ Object obj = elementData [index ];
25
+ for (int i = index ; i < size (); i ++)
26
+ {
27
+ elementData [i ] = elementData [i + 1 ];
28
+ }
29
+ size --;
30
+ return elementData ;
31
+ }
32
+
33
+ public int size (){
34
+ return size ;
35
+ }
36
+
37
+ public MyIterator myIterator (){
38
+ return null ;
39
+ }
40
+
41
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class MyBinaryTreeNode {
4
+ private Object data ;
5
+ private MyBinaryTreeNode left ;
6
+ private MyBinaryTreeNode right ;
7
+
8
+ public Object getData () {
9
+ return data ;
10
+ }
11
+ public void setData (Object data ) {
12
+ this .data = data ;
13
+ }
14
+ public MyBinaryTreeNode getLeft () {
15
+ return left ;
16
+ }
17
+ public void setLeft (MyBinaryTreeNode left ) {
18
+ this .left = left ;
19
+ }
20
+ public MyBinaryTreeNode getRight () {
21
+ return right ;
22
+ }
23
+ public void setRight (MyBinaryTreeNode right ) {
24
+ this .right = right ;
25
+ }
26
+
27
+ public MyBinaryTreeNode insert (Object o ){
28
+ return null ;
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public interface MyIterator {
4
+ public boolean hasNext ();
5
+ public Object next ();
6
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class MyLinkedList implements MyList {
4
+ private Node head ;
5
+
6
+ public void add (Object o ){
7
+
8
+ }
9
+ public void add (int index , Object o ){
10
+
11
+ }
12
+ public Object get (int index ){
13
+ return null ;
14
+ }
15
+ public Object remove (int index ){
16
+ return null ;
17
+ }
18
+
19
+ public int size (){
20
+ return -1 ;
21
+ }
22
+
23
+ public void addFirst (Object o ){
24
+
25
+ }
26
+ public void addLast (Object o ){
27
+
28
+ }
29
+ public Object removeFirst (){
30
+ return null ;
31
+ }
32
+ public Object removeLast (){
33
+ return null ;
34
+ }
35
+ public MyIterator iterator (){
36
+ return null ;
37
+ }
38
+
39
+
40
+ private static class Node {
41
+ Object data ;
42
+ Node next ;
43
+
44
+ }
45
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public interface MyList {
4
+ public void add (Object o );
5
+ public void add (int index , Object o );
6
+ public Object get (int index );
7
+ public Object remove (int index );
8
+ public int size ();
9
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class MyQueue {
4
+ private Object [] elementData ;
5
+ private int elementCount ;
6
+ private int head ;
7
+ private int next ;
8
+ public void enQueue (Object o ){
9
+ elementData [next ] = o ;
10
+ elementCount ++;
11
+ next ++;
12
+ }
13
+
14
+ public Object deQueue (){
15
+ Object obj = elementData [head ];
16
+ elementData [head ] = null ;
17
+ elementCount --;
18
+ head ++;
19
+ return obj ;
20
+ }
21
+
22
+ public boolean isEmpty (){
23
+ if (elementData .length ==0 ){
24
+ return true ;
25
+ }
26
+ return false ;
27
+ }
28
+
29
+ public int size (){
30
+ return elementData .length ;
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class MyStack {
4
+ Object [] elementData ;
5
+ private int size ;
6
+
7
+ public void push (Object o ){
8
+ elementData [size ++]=o ;
9
+ }
10
+
11
+ public Object pop (){
12
+ if (size >0 )
13
+ {
14
+ elementData [--size ]=null ;
15
+ }
16
+ return null ;
17
+ }
18
+
19
+ public Object peek (){
20
+ if (elementData .length == 0 ){
21
+ return null ;
22
+ }
23
+ return elementData [size - 1 ];
24
+ }
25
+ public boolean isEmpty (){
26
+ if (elementData .length == 0 ){
27
+ return true ;
28
+ }
29
+ return false ;
30
+ }
31
+ public int size (){
32
+ return elementData .length ;
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments