Jump to content

Algoritmi: Structura Alternativa


CorinA

Recommended Posts

Se defineste prin selectia intre doua sau mai multe actiuni in functie de datele problemei.Poate fi de doua tipuri:

1.STRUCTURA ALTERNATIVA SIMPLA: Intre doua posibilitati alternative(adevarat;fals) si care are ca instructiuni de baza instructiunile urmatoare:

daca conditie

         atunci

            actiune1;

         altfel

            actiune2;

sfarsit_daca.
if conditie

       then

         actiune1;

       else

         actiune2;

endif.
2.STRUCTURA ALTERNATIVA GENERALIZATA: Este atunci cand vom alege intre mai multe posibilitati (diferite de principiul adevarat si fals) in functie de o variabila de memorie numita selector,variabila care contine elemente de acelasi tip;executarea actiunilor se va face in functie de valoarea selectorului in ordinea in care ne sunt date elementele lui.
in cazul ca selector

         cazul v1:actiune1;

         cazul v2:actiune2;

...........................

         cazul vi:actiune i;

...........................

         cazul vn:actiune n;

         altfel  actiune n+1

sfarsit_in_caz_ca.
in case selector

         case v1:actiune1;

         case v2:actiune2;

..........................

         case vi:actiune i;

..........................

         case vn:actiune n;

         else    actiune n+1;

endcase.

4Qn7oKL.gif cjZhNAh.gifsykL3n4.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.