Skip to content

Instantly share code, notes, and snippets.

View KJTsanaktsidis's full-sized avatar

KJ Tsanaktsidis KJTsanaktsidis

View GitHub Profile
--Implements Mergesort
mergeLists :: (Ord a) => [a] -> [a] -> [a] -> [a]
mergeLists acc xa xb
| null xa && null xb = reverse acc --We are complete
| null xa = mergeLists ((head xb):acc) [] (tail xb) --Only b left
| null xb = mergeLists ((head xa):acc) (tail xa) [] --Only a left
| (head xa) <= (head xb) = mergeLists ((head xa):acc) (tail xa) xb --a first
| otherwise = mergeLists ((head xb):acc) xa (tail xb) --b first
--Implements Mergesort
mergeLists :: (Ord a) => [a] -> [a] -> [a] -> [a]
mergeLists acc xa xb
| null xa && null xb = acc --We are complete
| null xa = mergeLists (acc:(head xb)) [] (tail xb) --Only b left
| null xb = mergeLists (acc:(head xa)) (tail xa) [] --Only a left
| (head xa) <= (head xb) = mergeLists (acc:(head xa)) (tail xa) xb --a first
| otherwise = mergeLists (acc:(head xb)) xa (tail xb) --b first
@KJTsanaktsidis
KJTsanaktsidis / graph.py
Created May 11, 2013 04:40
A graph that can do dijkstra's algorithm and a little extra
import csv
import functools
import sys
import heapq
class AdjacencyGraph():
@functools.total_ordering
class SearchNode():
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Node-Link Tree</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.27.2"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?1.27.2"></script>
<style>