I'm looking for a clean way/best-practice of writing an algorithmic
block that uses pointers and references. I've had success with algorithmic
in the past, but this is the first time I've tried writing up something with pointers. The snippet code in C/C++ looks like:
Node *n = &root;
n->value = input;
The LaTeX approach I attempted doesn't look quite right:
\STATE $n \leftarrow \& \mathrm{root}$
\STATE $n \rightarrow \mathrm{value} \leftarrow \mathrm{input}$
Which renders as:
I think it looks a little odd with both with the &
, and the left and right arrows making it look like two things are pointing to mathrm. It seems a bit like the problem is a conflict with the \leftarrow
being used for assignment, but \leftarrow
appears to be common practice, so I'd like to follow it.
Of course I can also rewrite the algorithm to NOT use pointers, but it inflates the code block almost 2x and I'm working against a page limit. :) The end goal here of course is readability.
listings
package or theminted
package? I don't know but if you are using pointers, references and want a C++-like syntax this would be my first suggestion? listings documentation Perhaps it is too much for programming code and doesn't fit your needs precisely?! – patrickvogt Apr 17 '13 at 16:41listings
documentation, section 1.5 Alternatives. There is a short description of similar packages. Perhaps there is a package which fits for your use case – patrickvogt Apr 17 '13 at 16:44address(root)
or something similar, that way you do it totally generic. But think long and hard about the clarity of such a function, maybe address is not the correct name in your context. – zeroth Apr 17 '13 at 16:51listings
package. It was just my suggestion. So you can drop any implementation details such as data types and built in (language-specific) functions. You could also define your own language with both packages and define your own syntax highlighting (but I think this is quite an overhead) just for one algorithm – patrickvogt Apr 17 '13 at 16:57