Found this harder than expected as I knocked out the list in 5 minutes, reverse in place I had to look up then had the ah yeah I see moment, I did get some practice around visualising a problem.
public class MyLinkedList {
public Node head = null;
public Node tail = null;
public void append(int valueToAdd) {
if (head == null && tail == null) {
head = tail = new Node(valueToAdd);
} else {
tail.nextNode = new Node(valueToAdd);
tail = tail.nextNode;
}
}
public void printList() {
Node aNode = head;
while (aNode != null) {
System.out.println(aNode.value);
aNode = aNode.nextNode;
}
}
public void reverse() {
Node a = null, b = null, c = head;
tail = head;
while (c != null) {
a = c.nextNode;
c.nextNode = b;
b = c;
c = a;
}
head = b;
}
class Node {
public int value;
public Node nextNode = null;
public Node(int valueToAdd) {
this.value = valueToAdd;
}
}
}
Thursday, 21 January 2016
Monday, 11 January 2016
The new book is good
The oracle OCA Java book is good but it does leave some gaps, more make this work which is good in some ways frustrating in others. Anyway it is filling in lots of little gaps which is what I need. I had to postpone the exam as I just wasn't ready.
Articles and bits I liked this week,
Trying to make some tools for work although one API responds so much slower using the below instead of browser, taken URLs out. At first I thought it was because the API was first on the list, rejigged it so the problem URL not first same issue. At least it is a start. (done in my own time)
package com.company;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;
public class apiTester {
public Map<String, String> apiURLs = new HashMap<>();
public apiTester() {
apiURLs.put("google", "https://www.google.co.uk/");
apiURLs.put("bbc", "http://www.bbc.co.uk/");
}
public void runTests() {
long startTime, stopTime = 1;
for (String apiName : apiURLs.keySet()) {
startTime = System.currentTimeMillis();
HttpURLConnection connection = null;
try {
URL apiURL = new URL(apiURLs.get(apiName));
connection =
(HttpURLConnection)apiURL.openConnection();
connection.setRequestMethod("GET");
connection.connect();
} catch (MalformedURLException ex) {
System.out.println("Bad URL");
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (connection != null)
connection.disconnect();
}
stopTime = System.currentTimeMillis();
System.out.print(String.format("%1$-20s" ,apiName));
System.out.println((int) (stopTime - startTime) + "ms");
}
}
}
Articles and bits I liked this week,
Trying to make some tools for work although one API responds so much slower using the below instead of browser, taken URLs out. At first I thought it was because the API was first on the list, rejigged it so the problem URL not first same issue. At least it is a start. (done in my own time)
package com.company;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;
public class apiTester {
public Map<String, String> apiURLs = new HashMap<>();
public apiTester() {
apiURLs.put("google", "https://www.google.co.uk/");
apiURLs.put("bbc", "http://www.bbc.co.uk/");
}
public void runTests() {
long startTime, stopTime = 1;
for (String apiName : apiURLs.keySet()) {
startTime = System.currentTimeMillis();
HttpURLConnection connection = null;
try {
URL apiURL = new URL(apiURLs.get(apiName));
connection =
(HttpURLConnection)apiURL.openConnection();
connection.setRequestMethod("GET");
connection.connect();
} catch (MalformedURLException ex) {
System.out.println("Bad URL");
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (connection != null)
connection.disconnect();
}
stopTime = System.currentTimeMillis();
System.out.print(String.format("%1$-20s" ,apiName));
System.out.println((int) (stopTime - startTime) + "ms");
}
}
}
Sunday, 3 January 2016
Articles and lego picture maker getting there
Articles and news I liked,
Been working on a lego picture maker, which has a got a bit out of hand needs a to be refactored and a lot of stuff to add just pleased it is slowly getting there (link).
At the moment I cannot find a good up to date Java podcast however there is a podcast from early 2015, corejava: technical programming tests, the idea of a technical test done from home makes far more sense to me.
Finding the Java 8 OCA hard, worked through the Sybex Java 8 study guide and finding the tests hard going, ordered the Oracle versions at least the explanations of the topics will be different, the book is twice the size of the Sybex version.
Not seen much in the way of code camps here in the UK that do more than javascript and front end however these guys (the Iron yard) do everything and the Java Clojure course looks fun, 3 months and £8000 :O.
Been working on a lego picture maker, which has a got a bit out of hand needs a to be refactored and a lot of stuff to add just pleased it is slowly getting there (link).
At the moment I cannot find a good up to date Java podcast however there is a podcast from early 2015, corejava: technical programming tests, the idea of a technical test done from home makes far more sense to me.
Finding the Java 8 OCA hard, worked through the Sybex Java 8 study guide and finding the tests hard going, ordered the Oracle versions at least the explanations of the topics will be different, the book is twice the size of the Sybex version.
Not seen much in the way of code camps here in the UK that do more than javascript and front end however these guys (the Iron yard) do everything and the Java Clojure course looks fun, 3 months and £8000 :O.
Subscribe to:
Posts (Atom)