jasmine
BAN USERpublic class ReverseLinkedListRecursion {
public Node reverse(Node head) {
return reverse(head, head, null);
}
public Node reverse(Node temp, Node current, Node prev) {
if (current.next == null) {
current.next = prev;
return current;
} else {
Node t = current.next;
current.next = prev;
return reverse(t, temp, current);
}
}}
- jasmine August 11, 2015public class ReverseLinkedList {
public Node reverse(Node head) {
Node prev = null;
Node temp = head;
Node current = head;
while (current.next != null) {
temp = current.next;
current.next = prev;
prev = current;
current = temp;
}
current.next = prev;
return current;
}
}
- jasmine August 11, 2015package number.manipulation;
/* write a function that takes two numbers a and b and returns a.b eg: a=7 and b=24 output will be 7.24 */
public class NumberManipulation {
public double create(int a, int b) {
int n = b;
int count = 0;
while (n > 0) {
count++;
n /= 10;
}
return (double) a + ((double) b / Math.pow(10, count));
}
public static void main(String[] args) {
NumberManipulation nm = new NumberManipulation();
double result = nm.create(7, 24);
System.out.println(result);
}
}
- jasmine August 06, 2015/*Reverse words : "I love to play" becomes "play to love I" in place.*/
public class ReverseWords {
public char[] reverse(char[] input) {
reverseWord(input, 0, input.length);
int start = 0;
int end = 0;
while (end < input.length) {
if (input[end] == ' ') {
reverseWord(input, start, end);
start = end + 1;
}
end++;
}
reverseWord(input, start, end);
return input;
}
public char[] reverseWord(char[] input, int start, int end) {
int init = start;
int mid = (start + end) / 2;
for (int i = start; i < mid; i++) {
char temp = input[i];
input[i] = input[end - 1 - (i - init)];
input[end - 1 - (i - init)] = temp;
}
return input;
}
public static void main(String[] args) {
ReverseWords rw = new ReverseWords();
char[] output = rw.reverse("all love to play".toCharArray());
String print = String.valueOf(output);
System.out.println(print);
}
}
- jasmine August 06, 2015
}}
- jasmine August 11, 2015