[Tex/LaTex] Remove \Endif from algorithm

algorithmicalgorithms

I want to write the following algorithm in LaTeX.

image of algorithmn

The code I used is as follows:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algorithmic}
%\usepackage{algpseudocode}
%\algtext*{EndIf}
\begin{document}
\begin{algorithm}
\caption{Left-rotate $(T,x)$}
\begin{algorithmic}
\STATE $y \gets \mathrm{right}[x]$
\STATE $ \mathrm{right}[x] \gets \mathrm{left}[y]$
\IF {$ \mathrm{left}[y] \neq \mathrm{NIL} $}
\STATE $ p[\mathrm{left}[y]] \gets x $
\ENDIF
\IF {$ p[x]=\mathrm{NIL} $}
\STATE $ \mathrm{root}[T] \gets y $
\ELSIF {$ x=\mathrm{left}[p[x]] $}
\STATE $ \mathrm{left}[p[x]] \gets y $
\ELSE 
\STATE $ \mathrm{right}[p[x]] \gets y $
\ENDIF
\STATE $ \mathrm{left}[y] \gets x $
\STATE $ p[x] \gets x $
\end{algorithmic}
\end{algorithm}
\end{document}

I have already tried all the solutions on this platform but unfortunately, none worked. The output generated is the following:

result

I do not want the \ENDIF, it would be nice if then can be on the line below the one with \IF, and the nesting should be according to the first image. Please help me out.

Best Answer

Simply add package option noend to algorithmic:

\usepackage[noend]{algorithmic}

With the following complete code

\documentclass{article}
\usepackage{algorithm}
\usepackage[noend]{algorithmic}
%\usepackage{algpseudocode}
%\algtext*{EndIf}
\begin{document}
\begin{algorithm}
\caption{Left-rotate $(T,x)$}
\begin{algorithmic}
\STATE $y \gets \mathrm{right}[x]$
\STATE $ \mathrm{right}[x] \gets \mathrm{left}[y]$
\IF {$ \mathrm{left}[y] \neq \mathrm{NIL} $}
  \STATE $ p[\mathrm{left}[y]] \gets x $
\ENDIF
\IF {$ p[x]=\mathrm{NIL} $}
  \STATE $ \mathrm{root}[T] \gets y $
\ELSIF {$ x=\mathrm{left}[p[x]] $}
    \STATE $ \mathrm{left}[p[x]] \gets y $
  \ELSE 
    \STATE $ \mathrm{right}[p[x]] \gets y $
\ENDIF
\STATE $ \mathrm{left}[y] \gets x $
\STATE $ p[x] \gets x $
\end{algorithmic}
\end{algorithm}
\end{document}

you get the result:

result

I personaly would prefer the version with end marks, the algorithm is better readable ...