Created
October 4, 2015 09:26
-
-
Save Gnimuc/090649bd51dd9518eb55 to your computer and use it in GitHub Desktop.
[SO] Assign the object reference not the object
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
type Chain | |
value :: Int | |
right :: Chain | |
left :: Chain | |
#Make the last link in the chain point to itself | |
#so as to spare us from the julia workaround for nulls | |
Chain(value::Int) = (chain = new(); chain.value = value; chain.right = chain; chain.left = chain; chain) | |
end | |
function rotateright(x::Chain) | |
temp = x | |
x = x.left | |
temp.left = x.right | |
x.right = temp | |
x | |
end | |
c=Chain(0) | |
cr = Chain(10) | |
cl = Chain(20) | |
c.left = cl | |
c.right = cr | |
out = rotateright(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
more complicated case: