How can I add line number to my algorithm? I want to write line number in the front of the algorithm line. How can I get that with the \usepackage[ruled]{algorithm2e}?
Code:
\documentclass{article}
\usepackage[ruled]{algorithm2e}
\renewcommand{\baselinestretch}{1.5}
\usepackage{listings}
\usepackage{blindtext}
\begin{document}
\blindtext
\vspace{1cm}
\begin{algorithm}[H]
\SetAlgoLined
\KwData{$next\_id, speed,stop\_distance, mac$}
\KwResult{Find the initializer. }
int $next\_id1$ = find a record with $speed > 30$ \\ for this $mac$ in the next table;\\
int $next\_id2$ = find record with $speed <7$ and \\ $stop\_distance < 60$ for this mac in the next table;\\
\If{$next\_id1 < next\_id2$}{
find the related $stop\_name$ for this mac;\\
return $stop\_name$;
}
\caption{Algorithm to find intializer.}
\end{algorithm}
\vspace{1cm}
\begin{lstlisting}[caption = {MYSQL query to find the initializer.}, label={lst: initializer}]
SELECT speed, stop_name
from next
where stop_distance < 60 and speed < 7
and mac = ? and next_id > ? LIMIT 1
\end{lstlisting}
\clearpage
\end{document}


\nlin front of a algorithm line will provide the line number, works out of the box – Oct 03 '15 at 16:55\nlin the front of the line after adding\SetNlSty{texttt}{(}{)}to my code but it does not work and I am getting this error! LaTeX Error: \begin{lrbox} on input line 4 ended by \end{document}.Please can you try it with my code? – Mr Asker Oct 03 '15 at 17:03