Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
using namespace std;
#define T Tree<Key, Value>
#define KEY_VALUE template <class Key, class Value>
KEY_VALUE
class Tree {
public:
Tree *parent;
typedef unsigned int uint;
#define Item List<Key, Value>
#define KEY_VALUE template <class Key, class Value>
#define FLL(a) for (Item *tmp = (a); tmp != NULL; tmp = tmp->next)
KEY_VALUE
struct List {
Key k;
Value value;
Item *next;
/*
* @author: basicxman
* @description: http://dwite.ca/questions/cs4hs_root_of_a_string.html
*/
#include <iostream>
using namespace std;
bool TestRoot(string root, string s) {
int n = s.length();
#include "Graph.h"
#define MAXINT 1000
int printPath(int start, int end, vector<int> &parents, vector<int> &distance) {
cout << end << " (" << distance[end] << "): ";
int a = start;
int b = end;
@basicxman
basicxman / Prim.cpp
Created July 16, 2011 15:37
Prim's algorithm for minimum spanning tree.
#include "Graph.h"
#define MAXINT 1000
int findTotalWeight(int start, int end, vector<int> &parents, vector<int> &distance) {
int a = start;
int b = end;
int totalWeight = 0;
while (a != b) {
#include "Graph.h"
#include <queue>
#define unvisited 1
#define visited 2
#define processed 3
#define fill(a, b) fill_n((a).begin(), n, (b))
typedef vector<int> list;
@basicxman
basicxman / reverse_list.cpp
Created July 14, 2011 01:26
Reverse a single linked list in O(n) time and in-place.
void reverseList(list **l) {
if ((*l)->next == NULL) return;
// Hold the current list pointer for use in the actual swap, then assign the
// list pointer to the next element to place us at the correct head.
list *cur = *l;
*l = (*l)->next;
// Recurse with the new list pointer. This allows us to traverse to the
// farthest element while maintaining O(n) time.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Test</title>
1 ~$ irb
ruby-1.9.2-p136 :001 > require 'net/http'
=> true
ruby-1.9.2-p136 :002 > require 'uri'
=> false
ruby-1.9.2-p136 :003 > res = Net::HTTP.get_print URI.parse('http://www.wordreference.com/enfr/test')
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head>
# ApplicationController
def render_sidebar_widget(path, item = nil)
locals = {}
locals = self.send(item) unless item.nil?
render_to_string(:partial => path, :locals => locals).html_safe
end
helper_method :render_sidebar_widget
def reading_list
set(:reading_items, ReadingItem.updated_desc.all)