Skip to content

Instantly share code, notes, and snippets.

View rfaisal's full-sized avatar

Faisal Rahman rfaisal

  • Facebook
  • Vancouver, BC
View GitHub Profile
public class BTLeavesToDLL {
public static TNode<Integer> getLeaves(TNode<Integer> root){
if(root==null){
return null;
}
if(isLeaf(root)){
return root;
}
else{
TNode<Integer> left=getLeaves(root.left);
@rfaisal
rfaisal / IsSameBST.java
Created November 13, 2013 20:16
Given two arrays which represent a sequence of keys. Imagine we make a Binary Search Tree (BST) from each array. We need to tell whether two BSTs will be identical or not without actually constructing the tree.
public class IsSameBST {
public static boolean calculate(int []a, int []b){
return calculateRecursive(a, b, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
private static boolean calculateRecursive(int []a,int []b, int i_a, int j_b, int min, int max){
int i;
int j;
for(i=i_a;i<a.length;i++)
if(a[i]>min && a[i]<max) break;
for(j=j_b;j<b.length;j++)
@rfaisal
rfaisal / bst_lca.c
Created November 19, 2013 20:56
Given values of two nodes in a Binary Search Tree, write a c program to find the Lowest Common Ancestor (LCA). You may assume that both the values exist in the tree.
#include<stdlib.h>
#include<stdio.h>
struct node{
struct node *left;
struct node *right;
int v;
};
struct node *root;
void add_left(struct node *r,int v){
if(r){
@rfaisal
rfaisal / TreeTraversal.java
Created November 19, 2013 21:03
It is easy to traverse a binary tree in-order using recursion. Do it without using recursion.
public class TreeTraversal {
public static void inOrderWithoutRecursion(TNode<Integer> parent){
TNode<Integer> current= parent;
Stack<TNode<Integer>> stack =new Stack<TNode<Integer>>();
while(true){
if(current.left!=null){
stack.push(current);
current=current.left;
}
else{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace Skeleton.WebAPI.Controllers
{
// [Authorize]
public class ValuesController : ApiController
$.ajax({
type: "GET",
url: 'http://localhost:port/api/values',
success: function (_d) { alert(JSON.stringify(_d));}
}).fail(function (_d) { alert(JSON.stringify(_d)); });
public static void Register(HttpConfiguration config)
{
config.EnableCors();
// other stuff
}
[EnableCors(origins: "*", headers: "*", methods: "*")]
// [Authorize]
public class ValuesController : ApiController { /*Class Definition*/}
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
[EnableCors(origins: "*", headers: "*", methods: "*")]