File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed
yoonexample/src/main/java/list Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,41 @@ public E get(int index) {
97
97
98
98
@ Override
99
99
public E remove (int index ) {
100
- return null ;
100
+ if (isEmpty ()) {
101
+ return null ;
102
+ }
103
+
104
+ Node <E > cur ;
105
+
106
+ // 절반을 나눠서 가까운 부분에서 접근하도록 합니다.
107
+ if (index < (this .size / 2 ) + 1 ) { // 중간 값보다 작은 경우 앞에서부터 탐색합니다.
108
+ cur = this .head .next ;
109
+
110
+ for (int i = 0 ; i < index ; i ++) {
111
+ if (cur .next == null ) {
112
+ return null ;
113
+ }
114
+ cur = cur .next ;
115
+ }
116
+ } else {
117
+ cur = this .tail ;
118
+ int reversedIndex = this .size - index ;
119
+
120
+ if (reversedIndex < 1 ) { // 현재 조회 가능한 index보다 조회한 index가 큰 경우
121
+ return null ;
122
+ }
123
+ for (int i = 0 ; i < reversedIndex ; i ++) {
124
+ if (cur .prev == null ) {
125
+ return null ;
126
+ }
127
+ cur = cur .prev ;
128
+ }
129
+ }
130
+ cur .prev .next = cur .next ;
131
+ cur .next .prev = cur .prev ;
132
+ this .size --;
133
+
134
+ return cur .data ;
101
135
}
102
136
103
137
private static class Node <T > {
You can’t perform that action at this time.
0 commit comments