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 -
//final field 1 public final transient String myName = "Aniket"; //final field 2 public final transient Logger myLogger = LoggerFactory.getLogger(MyClass.class.getName());
/** * The table, resized as necessary. Length MUST Always be a power of two. */ transient Entry[] table;
public class HashMap<K,V> extends AbstractMap<K,V>
implements Map<K,V>, Cloneable, Serializable {
private static final long serialVersionUID = 362498820763181265L;
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();
}
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());
}
}
import { Directive, ElementRef, HostListener, Input, Renderer2 } from '@angular/core';
@Directive({
selector: '[appEnlarge]'
})
export class EnlargeDirective {
constructor(private el: ElementRef, private renderer: Renderer2) { }
@Input('appEnlarge') appEnlargeSize: string;
@HostListener('click') onclick() {
this.enlarge( this.appEnlargeSize || '100px');
}
@HostListener('dblclick') ondblclick() {
this.enlarge('50px');
}
private enlarge(enlargeSize: string) {
this.renderer.setStyle(this.el.nativeElement, 'font-size', enlargeSize);
}
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {EnlargeDirective} from './enlarge.directive'
@NgModule({
declarations: [
AppComponent,
EnlargeDirective
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule { }