Skip to content

Instantly share code, notes, and snippets.

public class ReverseAlternateKNodes {
public static void main(String[] args) throws java.lang.Exception {
LinkedListT a = new LinkedListT();
for (int i = 1; i <= 12; i++) {
a.addAtEnd(i);
}
System.out.print("Original Link List 1 : ");
a.display(a.head);
int k = 2;
System.out.println("\n Recursion with 2k nodes where k = " +k);
public class SwapEveryKthNode {
public static void main (String[] args) throws java.lang.Exception
{
LinkedListT a = new LinkedListT();
a.addAtBegin(10);
a.addAtBegin(9);
a.addAtBegin(8);
a.addAtBegin(7);
a.addAtBegin(6);
a.addAtBegin(5);
public class MagicIndex {
// perform modified binary search
public int search(int[] A, int start, int end) {
if (start <= end) {
int mid = (start + end) / 2;
if (mid == A[mid]) // check for magic index.
return mid;
if (mid > A[mid]) { // If mid>A[mid] means fixed point might be on
// the right half of the array
return search(A, mid + 1, end);
public class ReverseInGrps {
public Node reveseGrps(Node head, int k){
int x = k;
Node head_next=null;
Node h = head;
Node head_prev = null;
while(h!=null && x>0){
head_next = h.next;
@thmain
thmain / computeSvgSizeFromData.js
Created January 6, 2016 16:03
d3_tree_min_distance
function computeSvgSizeFromData(config){
var tree = d3.layout.tree(),
nodes = tree.nodes(config.data);
var maxTreeChildrenHeight = {},
maxTreeHeight = 0,
maxTreeDepth = 0,
minSvgWidth,
minSvgHeight;
public class DoublyLinkedList {
int size =0;
Node head = null;
Node tail = null;
public Node addAtStart(int data){
System.out.println("Adding Node " + data + " at the start");
Node n = new Node(data);
if(size==0){
public class NthNodeFromEnd {
//Method 1
//Get the length of the Linked list, say it x
//nth node from the end will be x-n+1 from the start of the linked list
public static int getNodeUsingLength(Node head, int n){
int x =0;
Node curr = head;
while(curr!=null){
x++;
public class StackUsingLinkedList {
Node head= null;
int size =0;
public void push(int data){
Node x = new Node(data);
if(getSize()==0){
head = x;
}else{
//add the Node at the start of a Linked List
import java.util.Hashtable;
public class SimpleHashTable {
int [] a = new int[5];
String [] arrNames = new String[]{"Sumit","Jain","Raghav","Garg","Gaurav","Rishi"};
Hashtable<Integer, String> ht = new Hashtable<Integer, String>();