Background
This post summarises various sorting techniques.
Sorting Techniques
I have written posts over time to show the implementation of some of the sorting techniques. Following are links to the same -
1 2 3 4 | //final field 1 public final transient String myName = "Aniket" ; //final field 2 public final transient Logger myLogger = LoggerFactory.getLogger(MyClass. class .getName()); |
1 2 3 4 | /** * The table, resized as necessary. Length MUST Always be a power of two. */ transient Entry[] table; |
1 2 3 4 5 | public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable { private static final long serialVersionUID = 362498820763181265L; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | public static void withSemaphores() throws InterruptedException, ExecutionException { Semaphore oddLock = new Semaphore( 1 ); Semaphore evenLock = new Semaphore( 0 ); Runnable printOdd = () -> { for ( int i = 1 ; i < 10 ; i = i + 2 ) { try { oddLock.acquire(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } ; System.out.println(i); evenLock.release(); } }; Runnable printEven = () -> { for ( int i = 2 ; i < 10 ; i = i + 2 ) { try { evenLock.acquire(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(i); oddLock.release(); } }; new Thread(printOdd).start(); new Thread(printEven).start(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public class Test { public static void main(String args[]) throws InterruptedException, ExecutionException { Callable<String> callable = () -> { Thread.sleep( 5000 ); return "Hello!" ; }; FutureTask<String> futureTask = new FutureTask<>(callable); Thread t = new Thread(futureTask); t.start(); while (!futureTask.isDone()) { System.out.println( "Task not done yet!" ); Thread.sleep( 1000 ); } System.out.println(futureTask.get()); } } |