1 / 9

STRUCTURA DE TIP STIVA

STRUCTURA DE TIP STIVA. DEFINITIE SI IMPLEMENTARE. CONTINUT. DEFINITIE DECLARAREA STIVEI PRELUCRAREA STIVEI - Testare - Initializare - Adaugarea unui nod - Eliminarea unui nod. DEFINITIE.

karif
Download Presentation

STRUCTURA DE TIP STIVA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STRUCTURA DE TIP STIVA DEFINITIE SI IMPLEMENTARE

  2. CONTINUT • DEFINITIE • DECLARAREA STIVEI • PRELUCRAREA STIVEI - Testare - Initializare -Adaugareaunui nod - Eliminareaunui nod

  3. DEFINITIE • Def:Stivaeste o listarestrictiva in care operatiile de introduceresiextragere se efectueazape la o singuraextremitate. • Proprietati: -celedouaextremitati ale stivei se numescbazasivarf. - accesul la nodurilestiveiestepermisnumaiprinextremitateavarf. - stiva se mainumestesistructura de tip LIFO (Last In First Out) vf baza

  4. IMPLEMENTARE Implementareastivei se poate face: • cu alocareinlantuita. – la fel ca a uneilisteliniaredar se vorfolosinumaiadaugarea in fataprimului nod sieliminareaprimului nod. • cu alocaresecventiala– este un mecanismmultmaisimplupentruadaugareasieliminareanodurilor. Concluzie: ceamaisimplaimplementare a stiveloresteceasecventiala cu ajutorulunui vector.

  5. DECLARAREA STIVEI Sintaxa: const unsigned NMAX=100; typedef<tip_data> nod; nod stiva[NMAX+1], val; unsigned vf,baza; unde: tip_data = orice tip al limbajului val - valoareaintrodusa in nod vf - varfulstivei Prelucrarea se face de la varfsprebaza. Accesul la informatia din varfulstivei se face cu stiva[vf]

  6. PRELUCRAREA STIVEI 1.Testarea stivei a.stivavida: este_vida = vf == NULL; undeeste_vida e o variabila cu valoarea 1 dacastiva e vidasi 0 in cazcontrar. b.stivaplina: este_plina = vf == NMAX; undeeste_plinae o variabila cu valoarea 1 dacastiva e plinasi 0 in cazcontrar. 2.Initializarea stivei In aceastasecventa se creeazastivavida: vf = baza = NULL;

  7. PRELUCRAREA STIVEI 3.Adaugarea unui nod in stiva: if (! este_plina) {if (este_vida) baza = 1; vf++; stiva [vf] = val;} Exemplu: Pentru o stiva in care se adauga 3 caracterea,b,coperatiile de adaugare se executaastfel:

  8. PRELUCRAREA STIVEI 4.Eliminarea unui nod din stiva: if (! este_vida) {val = stiva[vf]; vf --;} if(este_vida) vf = baza = NULL; Exemplu: Eliminarea a douacaractere din stiva se executaastfel:

  9. sfarsit

More Related