1 / 8

Laborator 3 Liste, stive si cozi - partea I -

Laborator 3 Liste, stive si cozi - partea I -. Stive si cozi implementate cu vectori. Stiva - Stuctura LIFO - varful stivei – top - is_empty, is_full - push, pop Coada - Stuctura FIFO - inceput, sfarsit coada – front si rear - is_empty, is_full - insert, remove.

kirk
Download Presentation

Laborator 3 Liste, stive si cozi - partea I -

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. Laborator 3Liste, stive si cozi- partea I -

  2. Stive si cozi implementate cu vectori Stiva- Stuctura LIFO- varful stivei – top- is_empty, is_full- push, popCoada- Stuctura FIFO- inceput, sfarsit coada – front si rear- is_empty, is_full- insert, remove

  3. Stive si cozi implementate cu vectori Stiva (principiu) + -> pop() -> pop() -> push(10) ->10 ->5 Stiva transpusa in vectori • isEmpty() • isFull() • - stackArrary[maxSize] • push[++top] • return pop[top--] • peek[top]

  4. Stive si cozi implementate cu vectori

  5. Stive si cozi implementate cu vectori Cozi (principiu) + -> remove() -> insert(10) ->1 remove() -> ->5 Coada transpusa in vectori • isEmpty() • isFull() • - queArray [maxSize] • insert[++rear] • return remove[front++] • peekFront[front]

  6. Stive si cozi implementate cu vectori

  7. Stive si cozi implementate cu vectori De facut:1. De implementat clasa Stack, cu constructorul Stack(n), unde n este dimensiunea maxima. De adaugat valorile 5, 10, 20, 15, 0, 50. De scos pas cu pas aceste valori. De afisat elementul din varful stivei2. De implementat clasa Coada, De adaugat valorile 5, 10, 20, 15, 0, 50. De scos pas cu pas aceste valori.3. De realizat un program care verifica consistenta unei expresii Exemplu: - c[d] // corect - a{b[c]d}e // corect - a{b(c]d}e // incorect; ] nu se potriveste cu ( - a[b{c}d]e} // incorect, nimic nu se potriveste cu } finalaIndicatii: Se testeaza caracter cu caracter, parantezele deschise se introduc intr-o stiva; cand intalnesc paranteze deschise efectuez un pop pe stiva si compar cele doua paranteze.

  8. Stive si cozi implementate cu vectori Exemple utile: - constructor Stiva: public StackX(int s) // constructor { maxSize = s; // set array size stackArray = new double[maxSize]; // create array top = ??????; // no items yet. Cat trebuie sa fie top initial?}- constructor Coada:public Queue(int s) // constructor { maxSize = s; queArray = new int[maxSize]; front = 0; rear = -1; nItems = 0;}- metoda pop:public int pop() // take item from top of stack{return stackArray[top--];}

More Related