diff --git a/Sorting Algorithm/MergeSort_Recursively/RecMergeSort.py b/Sorting Algorithm/MergeSort_Recursively/RecMergeSort.py new file mode 100644 index 0000000..3782080 --- /dev/null +++ b/Sorting Algorithm/MergeSort_Recursively/RecMergeSort.py @@ -0,0 +1,41 @@ +#itai192 +#a method that merges two ordered list +def Merge(l1, l2): + l3=[] + #until one list is empty + while(len(l1)>0 and len(l2)>0): + #add the lowest value between the two lists into the third list and remove it from the list it came from + if (l1[0]0): + l3.append(l1.pop(0)) + while(len(l2)>0): + l3.append(l2.pop(0)) + return l3 +#the recursive merge sort method +def MergeSortRec(lis,start,end): + length=end-start+1 + #if the length is one return a list with one item in it + if(length==1): + return [lis[start]] + #if the list has two items, return a list containing the two items in order + if(length==2): + #if the list is in order return it the same way + if(lis[start]