This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PairwiseSwapNodesByChangingLinks { | |
public static Node swapNodeIterative(Node head){ | |
Node ptrOne_prev = null; | |
Node baseHead = null; | |
while(head!=null && head.next!=null ){ | |
//Take 2 pointers, one on head | |
Node ptrOne = head; | |
//another on head.next | |
Node ptrTwo = head.next; | |
//store the reference of next node of pointer 2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function computeSvgSizeFromData(config){ | |
var tree = d3.layout.tree(), | |
nodes = tree.nodes(config.data); | |
var maxTreeChildrenHeight = {}, | |
maxTreeHeight = 0, | |
maxTreeDepth = 0, | |
minSvgWidth, | |
minSvgHeight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); |