File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
src/me/ramswaroop/linkedlists Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 12
12
*/
13
13
public class RemoveMiddlePointsFromLineSegments {
14
14
15
- public static < E extends Comparable < E >> void removeMiddlePointsFromLineSegments (SingleLinkedNode <E > node ) {
15
+ public static void removeMiddlePointsFromLineSegments (SingleLinkedNode <Point > node ) {
16
16
17
- }
17
+ SingleLinkedNode < Point > curr1 = node , curr2 = node ;
18
18
19
+ while (curr1 != null && curr1 .next != null ) {
20
+ // vertical line
21
+ if (curr1 .item .x == curr1 .next .item .x ) {
22
+ while (curr2 .next != null && curr2 .next .item .x == curr1 .item .x ) {
23
+ curr2 = curr2 .next ;
24
+ }
25
+ curr1 .next = curr2 ;
26
+ } else if (curr1 .item .y == curr1 .next .item .y ) { // horizontal line
27
+ while (curr2 .next != null && curr2 .next .item .y == curr1 .item .y ) {
28
+ curr2 = curr2 .next ;
29
+ }
30
+ curr1 .next = curr2 ;
31
+ } else {
32
+ return ;
33
+ }
34
+ curr1 = curr1 .next ;
35
+ }
36
+ }
19
37
20
38
public static void main (String a []) {
21
39
SingleLinkedList <Point > linkedList = new SingleLinkedList <>();
@@ -34,6 +52,7 @@ public static void main(String a[]) {
34
52
}
35
53
36
54
class Point implements Comparable <Point > {
55
+
37
56
int x , y ;
38
57
39
58
Point (int x , int y ) {
You can’t perform that action at this time.
0 commit comments