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
#coding:utf-8 | |
class treeNode: | |
""" | |
Tree node class | |
""" | |
def __init__(self, value, lnode=None, rnode=None): | |
self.value = value | |
self.lnode = lnode | |
self.rnode = rnode |
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 algorithm; | |
public class MergeSort { | |
public static void sort(int[] A,int p, int r){ | |
if(p < r){ | |
int q = (r+p)/2; | |
sort(A,p,q); | |
sort(A,q+1,r); | |
merge(A,p,q,r); | |
} |
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
public class InsertionSort { | |
public static void sort(int[] array) { | |
for (int i = 1; i < array.length; i++) { | |
int key = array[i]; | |
// insert a[j] into the sorted sequence A[0,j-1] | |
int j = i - 1; | |
while (j >= 0 && array[j] > key) { | |
array[j + 1] = array[j]; | |
j--; | |
} |