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
//http://www.geeksforgeeks.org/inorder-successor-in-binary-search-tree/ | |
//With Parent node given | |
struct node * inOrderSuccessor(struct node *root, struct node *n) | |
{ | |
// step 1 of the above algorithm | |
if( n->right != NULL ) | |
return minValue(n->right); | |
// step 2 of the above algorithm | |
struct node *p = n->parent; |
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
/* Helper function for getLevel(). It returns level of the data if data is | |
present in tree, otherwise returns 0.*/ | |
int getLevelUtil(struct node *node, int data, int level) | |
{ | |
if (node == NULL) | |
return 0; | |
if (node->data == data) | |
return level; | |
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
/* If target is present in tree, then prints the ancestors | |
and returns true, otherwise returns false. */ | |
bool printAncestors(struct node *root, int target) | |
{ | |
/* base cases */ | |
if (root == NULL) | |
return false; | |
if (root->data == target) | |
return true; |
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
services.factory('Api', ['$resource', | |
function($resource) { | |
return { | |
Recipe: $resource('/recipes/:id', {id: '@id'}), | |
Users: $resource('/users/:id', {id: '@id'}), | |
Group: $resource('/groups/:id', {id: '@id'}) | |
}; | |
}]); | |
function myCtrl($scope, Api){ |
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
for (i in 1..n-2) { | |
j = i+1 // Start right after i. | |
k = n // Start at the end of the array. | |
while (k >= j) { | |
// We got a match! All done. | |
if (A[i] + A[j] + A[k] == 0) return (A[i], A[j], A[k]) | |
// We didn't match. Let's try to get a little closer: | |
// If the sum was too big, decrement 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
package sample; | |
import java.util.HashMap; | |
import org.springframework.web.client.RestTemplate; | |
public class HelloWorld { | |
public static void main(String args[]) { | |
RestTemplate restTemplate = new RestTemplate(); |
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
var constants = require('../config/constants'); | |
var url = constants.APP_URL; | |
var soap = require('soap'); | |
var singleton = function singleton() { | |
var instance = null; | |
soap.createClient(url, function(err, client) { | |
if (err) { | |
console.log(err); | |
instance = null; |
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.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class RunLengthEncoding { | |
public static String encode(String source) { | |
StringBuffer dest = new StringBuffer(); | |
for (int i = 0; i < source.length(); i++) { | |
int runLength = 1; | |
while (i+1 < source.length() && source.charAt(i) == source.charAt(i+1)) { | |
runLength++; |
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
private static boolean detectCycle(ListNode head) { | |
ListNode p1 = head; | |
ListNode p2 = head; | |
while (p2 != null && p2.next != null) { | |
p1 = p1.next; | |
p2 = p2.next.next; | |
if (p1 == p2) | |
return true; | |
} |
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
// Use built in or binary modules | |
var crypto = require('crypto'); | |
var hash = crypto.createHmac("sha1",key).update(signatureBase).digest("base64"); |