* BAEL-1861 Replaced real tests with demo test "placeholders"

* BAEL-1861 Moved code from new module into existing ones

* BAEL-1861 Renamed main() classes to not violate PMD rules
This commit is contained in:
Predrag Maric
2018-08-07 18:50:33 +02:00
committed by GitHub
parent ddc106ccd9
commit e730b0d8f8
13 changed files with 91 additions and 213 deletions
@@ -1,41 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class ListNode {
private int value;
private ListNode next;
public ListNode(int v) {
value = v;
}
public ListNode(int v, ListNode next) {
value = v;
this.next = next;
}
public int getValue() {
return value;
}
public ListNode getNext() {
return next;
}
public void setNext(ListNode next) {
this.next = next;
}
public String toString() {
String result = "";
ListNode tmp = this;
while (tmp.next != null) {
result += tmp.value + "->";
tmp = tmp.next;
}
result += tmp.value;
return result.toString();
}
}
@@ -1,22 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class MergeLists {
public ListNode merge(ListNode list1, ListNode list2) {
if (list1 == null) {
return list2;
}
if (list2 == null) {
return list1;
}
if (list1.getValue() <= list2.getValue()) {
list1.setNext(merge(list1.getNext(), list2));
return list1;
} else {
list2.setNext(merge(list2.getNext(), list1));
return list2;
}
}
}
@@ -1,26 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class RemovedNthElement {
public ListNode removeNthFromEnd(ListNode head, int n) {
ListNode start = new ListNode(0);
start.setNext(head);
ListNode fast = start;
ListNode slow = start;
for (int i = 0; i < n + 1 && fast != null; i++) {
fast = fast.getNext();
}
while (fast != null) {
fast = fast.getNext();
slow = slow.getNext();
}
slow.setNext(slow.getNext()
.getNext());
return start.getNext();
}
}
@@ -1,30 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class RotateList {
public ListNode rotateRight(ListNode list, int n) {
if (list == null || list.getNext() == null) {
return list;
}
ListNode tmpList = new ListNode(0);
tmpList.setNext(list);
ListNode fast = tmpList;
ListNode slow = tmpList;
int listLength;
for (listLength = 0; fast.getNext() != null; listLength++) {
fast = fast.getNext();
}
for (int j = listLength - n % listLength; j > 0; j--) {
slow = slow.getNext();
}
fast.setNext(tmpList.getNext());
tmpList.setNext(slow.getNext());
slow.setNext(null);
return tmpList.getNext();
}
}
@@ -1,33 +0,0 @@
package com.baeldung.junit.runfromjava.listnode;
public class SwapNodes {
public ListNode swapPairs(ListNode listHead) {
ListNode result = new ListNode(0);
result.setNext(listHead);
ListNode current = result;
while (current.getNext() != null && current
.getNext()
.getNext() != null) {
ListNode first = current.getNext();
ListNode second = current
.getNext()
.getNext();
first.setNext(second.getNext());
current.setNext(second);
current
.getNext()
.setNext(first);
current = current
.getNext()
.getNext();
}
return result.getNext();
}
}