Remove Endif from algorithmAlgorithm spanning two columns error with prevdepthDivide algorithm inside If...

Please, smoke with good manners

What's the metal clinking sound at the end of credits in Avengers: Endgame?

Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?

Smart diagram in Mathematica

How to determine the actual or "true" resolution of a digital photograph?

What does "rf" mean in "rfkill"?

Why does processed meat contain preservatives, while canned fish needs not?

Why does nature favour the Laplacian?

How to replace the "space symbol" (squat-u) in listings?

Is there a way to get a compiler for the original B programming language?

How can I place the product on a social media post better?

What's the polite way to say "I need to urinate"?

Is it possible to measure lightning discharges as Nikola Tesla?

Pressure to defend the relevance of one's area of mathematics

How to figure out whether the data is sample data or population data apart from the client's information?

Packing rectangles: Does rotation ever help?

How does a swashbuckler fight with two weapons and safely dart away?

TikZ how to make supply and demand arrows for nodes?

Where did the extra Pym particles come from in Endgame?

How to delegate to implementing class

Transfer over $10k

What is the difference between `a[bc]d` (brackets) and `a{b,c}d` (braces)?

Are Boeing 737-800’s grounded?

Normal subgroup of even order whose nontrivial elements form a single conjugacy class is abelian



Remove Endif from algorithm


Algorithm spanning two columns error with prevdepthDivide algorithm inside If EndIfRemove top rule from algorithm packageAlgorithmic: Put If and EndIf into same lineAlgorithm indent problem with sig-alternate document & algorithm(ic) packageAlgorithmic package in two different languages in same documentInserting multiple columns in algorithmHow to remove leading indentation from algorithm?how to remove spaces from algorithm and align nicely algorithmAlgorithm returning 0













1















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.










share|improve this question





























    1















    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.










    share|improve this question



























      1












      1








      1








      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.










      share|improve this question
















      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.







      algorithms algorithmic






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 15 mins ago









      Kurt

      42.3k950167




      42.3k950167










      asked 30 mins ago









      user473334user473334

      254




      254






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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 ...






          share|improve this answer
























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "85"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488129%2fremove-endif-from-algorithm%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            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 ...






            share|improve this answer




























              0














              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 ...






              share|improve this answer


























                0












                0








                0







                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 ...






                share|improve this 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 ...







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 19 mins ago









                KurtKurt

                42.3k950167




                42.3k950167






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488129%2fremove-endif-from-algorithm%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    miktex-makemf did not succeed for the following reasonHow to fix the “Sorry, but C:…miktex-pdftex.exe did...

                    How to insert first subfigures with caption in IEEE ACCESS LaTeX?Figure caption line breaking after first...

                    Ángela Graupera Índice Bibliografía Referencias Enlaces externos Menú de navegación«medi@Search »...