In order to include code, algorithm, pseudo-code listing is very useful package. To include listing package, include this in your document class.
\usepackage{listings}
The following tag shows how you can place your code or algorithm in latex .
\begin{lstlisting}[float = h, caption= Title, label=label, belowcaptionskip=0.4cm]
Place your code or algorithm here.
\end{lstlisting}
You can even include your source code directly to your documents. For example:
\lstinputlisting{main.java}
To add the “List of Listings” in your documents use the following in your main.tex file.
\lstlistoflistings
I have got a style for listing somewhere from the internet as shown in figure below:

To use the style add this in your document class:
\usepackage{listings}
\usepackage{courier}
\lstset{
basicstyle=\footnotesize\ttfamily, % Standardschrift
%numbers=left, % Ort der Zeilennummern
numberstyle=\tiny, % Stil der Zeilennummern
%stepnumber=2, % Abstand zwischen den Zeilennummern
numbersep=5pt, % Abstand der Nummern zum Text
tabsize=2, % Groesse von Tabs
extendedchars=true, %
breaklines=true, % Zeilen werden Umgebrochen
keywordstyle=\color{red},
frame=b,
% keywordstyle=[1]\textbf, % Stil der Keywords
% keywordstyle=[2]\textbf, %
% keywordstyle=[3]\textbf, %
% keywordstyle=[4]\textbf, \sqrt{\sqrt{}} %
stringstyle=\color{white}\ttfamily, % Farbe der String
showspaces=false, % Leerzeichen anzeigen ?
showtabs=false, % Tabs anzeigen ?
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
%backgroundcolor=\color{lightgray},
showstringspaces=false % Leerzeichen in Strings anzeigen ?
}