Skip to content

Instantly share code, notes, and snippets.

@shiva27
shiva27 / SourceCodeLineCounter.java
Created December 5, 2011 04:24
Counting Source Code lines in a Java file
package examples;
import java.io.BufferedReader;
import java.io.IOException;
/**
* This class counts the number of source code lines by excluding comments, in a Java file
* The pseudocode is as below
*
* Initial: Set count = 0, commentBegan = false
@shiva27
shiva27 / gist:1516958
Created December 24, 2011 09:11
Circus Sorting Problem
A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For
practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or
her. Given the heights and weights of each person in the circus, write a method to compute the largest
possible number of people in such a tower.
EXAMPLE:
Input (ht, wt): (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)
Output: The longest tower is length 6 and includes from top to bottom: (56, 90) (60,95) (65,100) (68,110)
(70,150) (75,190)
@shiva27
shiva27 / BinarySearchTreeTest
Created November 15, 2013 01:37
Check if a given Binary Tree is a Binary Search Tree
public static void main(String ... args)
{
isBST(root, Integer.MAX_VALUE, Integer.MIN_VALUE);
}
private boolean isBST(TreeNode node, int max, int min)
{
boolean left = false;
boolean right = false;
if(node.left != null)