-
-
Save andreis/69a242330617b2a62753ce604e276c0d to your computer and use it in GitHub Desktop.
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
def bubsort(arr): | |
if not arr: return None | |
for i in range(len(arr)): | |
for j in range(i+1, len(arr)): | |
if arr[i] > arr[j]: arr[i], arr[j] = arr[j], arr[i] | |
return arr | |
class Node(object): | |
def __init__(self, val, l=None, r=None): | |
self.val = val | |
self.left = l | |
self.right = r | |
def revtree(node): | |
if not node: return None | |
node.left, node.right = revtree(node.right), revtree(node.left) | |
return node | |
def test(): | |
print(bubsort([1,2,3])) | |
print(revtree(Node(1, Node(2), Node(3))).left.val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment