You are on page 1of 3

Laborator 7

Creare TDA stiva prin extinderea TDA lista

Se considera o reprezentare a stivelor bazata pe liste inlantuite. Accesele se vor face prin
capatul din fata al listei.
Operatiile push si pop sunt atunci realizate cu operatiile ins_in_fata() respectiv
sterge_prim() de la liste inlantuite, iar operatia top() prin primul().

SURSE PUSE LA DISPOZITIE



 Fisierele stiva.h si stiva.c date din acest document.
 Fisierele data.h si lista.h de la curs
 Fisierul lista.c creat in lucrarea de laborator precedenta.

TEMA DE REALIZAT

Un program demonstrativ pentru operatiile cu stive, elementele continand caractere.


Programul va afisa meniul urmator

p – push (se va citi un caracter de la tastatura si se va introduce in stiva)


q – pop
t – top
u - toppop
s – stare stiva (plina, vida, contine elemente)
a – afisare stiva (cu functia conv_stiva_sir introdusa de dh in stiva.h si stiva.c)
v – verificare inchidere corecta a parantezelor (se citeste un sir continand paranteze)
i – info autor
g – gata program

FISIERELE stiva.h SI stiva.c

//--------------------------------------------------------
// F i s i e r u l s t i v a . h
//--------------------------------------------------------
#ifndef __STIVA_H_
#define __STIVA_H_
#include "lista.h"

typedef LISTA STIVA;

extern STIVA news();


extern STIVA push(STIVA,DATA);
extern STIVA pop(STIVA);
extern DATA top(STIVA);
extern STIVA toppop(STIVA ,DATA *);
extern LOGIC emptys(STIVA);
extern LOGIC fulls(STIVA);
extern void destroys(STIVA);
#endif;

//--------------------------------------------------------
// F i s i e r u l s t i v a . c
//--------------------------------------------------------
#include "stiva.h"
#include "lista.h"

STIVA news()
{
return (STIVA)newl();
}
//--------------------------------------------------------
STIVA push(STIVA s,DATA x)
{
return ins_in_fata((LISTA)s,x);
}
//---------------------------------------------------------
STIVA pop(STIVA s)
{
return (STIVA) sterge_prim((LISTA)s);
}
//---------------------------------------------------------
DATA top(STIVA s)
{
return emptys(s)?ABSENT : primul(LISTA)s);

}
//---------------------------------------------------------
STIVA toppop(STIVA s, DATA *val)
{
*val=top(s);
return pop(s);
}
//---------------------------------------------------------
LOGIC emptys( STIVA s)
{
return este_vida((LISTA)s);
}
//---------------------------------------------------------
LOGIC fulls(STIVA s)
{
return este_plina((LISTA)s);
}
//---------------------------------------------------------
void destroys(STIVA s)
{
destroy((LISTA)s);
}

You might also like