File tree Expand file tree Collapse file tree 10 files changed +325
-0
lines changed Expand file tree Collapse file tree 10 files changed +325
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <classpath >
3
+ <classpathentry kind =" src" path =" src" />
4
+ <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER" />
5
+ <classpathentry kind =" output" path =" bin" />
6
+ </classpath >
Original file line number Diff line number Diff line change
1
+ /bin /
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <projectDescription >
3
+ <name >1664823950</name >
4
+ <comment ></comment >
5
+ <projects >
6
+ </projects >
7
+ <buildSpec >
8
+ <buildCommand >
9
+ <name >org.eclipse.jdt.core.javabuilder</name >
10
+ <arguments >
11
+ </arguments >
12
+ </buildCommand >
13
+ </buildSpec >
14
+ <natures >
15
+ <nature >org.eclipse.jdt.core.javanature</nature >
16
+ </natures >
17
+ </projectDescription >
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class ArrayList implements List
4
+ {
5
+
6
+ private int size = 0 ;
7
+
8
+
9
+ private Object [] elementData = new Object [100 ];
10
+
11
+ public void add (Object o )
12
+ {
13
+ elementData [size ] = o ;
14
+ size ++;
15
+ }
16
+
17
+ public void add (int index , Object o )
18
+ {
19
+ if (index > size || index < 0 )
20
+ {
21
+ return ;
22
+ }
23
+ else
24
+ {
25
+ for (int i = size -1 ; i > index ; i --)
26
+ {
27
+ elementData [i +1 ] = elementData [size ];
28
+ }
29
+ elementData [index ] = o ;
30
+ size ++;
31
+ }
32
+
33
+ }
34
+
35
+ public Object get (int index )
36
+ {
37
+ if (index < size || index >= 0 )
38
+ {
39
+ return elementData [index ];
40
+ }
41
+ return null ;
42
+ }
43
+
44
+ public Object remove (int index )
45
+ {
46
+ Object removedObj ;
47
+ if (index >= size || index < 0 )
48
+ {
49
+ removedObj = null ;
50
+ }
51
+ else
52
+ {
53
+ removedObj = elementData [index ];
54
+ for (int j = index ; j < elementData .length ; j ++)
55
+ {
56
+ elementData [j ] = elementData [j +1 ];
57
+ }
58
+ size --;
59
+ }
60
+ return removedObj ;
61
+ }
62
+
63
+ public int size ()
64
+ {
65
+ return size ;
66
+ }
67
+
68
+ public Iterator iterator ()
69
+ {
70
+ return null ;
71
+ }
72
+
73
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class BinaryTreeNode
4
+ {
5
+
6
+ private Object data ;
7
+ private BinaryTreeNode left ;
8
+ private BinaryTreeNode right ;
9
+
10
+ public Object getData ()
11
+ {
12
+ return data ;
13
+ }
14
+
15
+ public void setData (Object data )
16
+ {
17
+ this .data = data ;
18
+ }
19
+
20
+ public BinaryTreeNode getLeft ()
21
+ {
22
+ return left ;
23
+ }
24
+
25
+ public void setLeft (BinaryTreeNode left )
26
+ {
27
+ this .left = left ;
28
+ }
29
+
30
+ public BinaryTreeNode getRight ()
31
+ {
32
+ return right ;
33
+ }
34
+
35
+ public void setRight (BinaryTreeNode right )
36
+ {
37
+ this .right = right ;
38
+ }
39
+
40
+ public BinaryTreeNode insert (Object o )
41
+ {
42
+ return null ;
43
+ }
44
+
45
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public interface Iterator
4
+ {
5
+ public boolean hasNext ();
6
+ public Object next ();
7
+
8
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class LinkedList implements List
4
+ {
5
+
6
+ private Node head ;
7
+ private Node tail ;
8
+
9
+ public void add (Object o )
10
+ {
11
+ Node n = new Node (o );
12
+ tail .next = n ;
13
+ tail = n ;
14
+ }
15
+
16
+ public void add (int index , Object o )
17
+ {
18
+ Node n = new Node (o );
19
+ getNode (index -1 ).next = n ;
20
+ n .next = getNode (index );
21
+ }
22
+
23
+ private Node getNode (int index )
24
+ {
25
+ Node n = head ;
26
+ int counter = 0 ;
27
+ while (counter <index )
28
+ {
29
+ counter ++;
30
+ n = n .next ;
31
+ }
32
+ return n ;
33
+ }
34
+
35
+ public Object get (int index )
36
+ {
37
+ return getNode (index ).data ;
38
+ }
39
+
40
+ public Object remove (int index )
41
+ {
42
+ Object o = getNode (index ).data ;
43
+ getNode (index -1 ).next = getNode (index +1 );
44
+ return o ;
45
+ }
46
+
47
+ public int size ()
48
+ {
49
+ Node n = head ;
50
+ int counter = 0 ;
51
+ while (n .next != tail )
52
+ {
53
+ counter ++;
54
+ n = n .next ;
55
+ }
56
+ counter ++;
57
+ return counter ;
58
+ }
59
+
60
+ public void addFirst (Object o )
61
+ {
62
+ Node n = new Node (o );
63
+ n .next = head ;
64
+ head = n ;
65
+ }
66
+
67
+ public void addLast (Object o )
68
+ {
69
+ add (o );
70
+ }
71
+
72
+ public Object removeFirst ()
73
+ {
74
+ Object o = head .data ;
75
+ head = head .next ;
76
+ return o ;
77
+ }
78
+
79
+ public Object removeLast ()
80
+ {
81
+ Object o = tail .data ;
82
+ Node n = head ;
83
+ while (n .next != tail )
84
+ {
85
+ n = n .next ;
86
+ }
87
+ tail = n ;
88
+ return o ;
89
+ }
90
+
91
+
92
+ public Iterator iterator ()
93
+ {
94
+ return null ;
95
+ }
96
+
97
+
98
+ private static class Node
99
+ {
100
+ Object data ;
101
+ Node next ;
102
+
103
+ public Node (Object data )
104
+ {
105
+ this .data = data ;
106
+ }
107
+ }
108
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public interface List
4
+ {
5
+ public void add (Object o );
6
+ public void add (int index , Object o );
7
+ public Object get (int index );
8
+ public Object remove (int index );
9
+ public int size ();
10
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class Queue
4
+ {
5
+ private LinkedList elementData = new LinkedList ();
6
+
7
+ public void enQueue (Object o )
8
+ {
9
+ elementData .addLast (o );
10
+ }
11
+
12
+ public Object deQueue ()
13
+ {
14
+ return elementData .removeFirst ();
15
+ }
16
+
17
+ public boolean isEmpty ()
18
+ {
19
+ return elementData .size () == 0 ;
20
+ }
21
+
22
+ public int size ()
23
+ {
24
+ return elementData .size ();
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ package com .coding .basic ;
2
+
3
+ public class Stack
4
+ {
5
+ private LinkedList elementData = new LinkedList ();
6
+
7
+ public void push (Object o )
8
+ {
9
+ elementData .addLast (o );
10
+ }
11
+
12
+ public Object pop ()
13
+ {
14
+ return elementData .removeLast ();
15
+ }
16
+
17
+ public Object peek ()
18
+ {
19
+ return elementData .get (elementData .size ());
20
+ }
21
+
22
+ public boolean isEmpty ()
23
+ {
24
+ return elementData .size () == 0 ;
25
+ }
26
+
27
+ public int size ()
28
+ {
29
+ return elementData .size ();
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments