
Заготовки по С / Динамические структуры / GDSL / Документация
.pdf
4.16 Sta k manipulation module
.16 Sta k manipulation module |
177 |
T
Funypedefsˆˆ gdslttionsGDSLstastagdslk kttypestagdsl.k stagdslk__staallok (tonst har
funvoidCrDestrFlushgdslateharoyALLOCstanew.stak. F,freek.ushgdsl(gdsl(gdslfreestastafunkk ( S)onstS)FREE_NAME,F) gdsl_allo _-
Getsthegdslgdslthe growingsizenamegdslstastaofofakkfaastastatorgetgetk.kof. growingsizeagetsta (kname.onstfagdsltor_(stagdslonstk_gdsltstaS) kstat S)k_t S) |
|||
ulongonst |
|
|
|
bool gdsl_ |
is |
empty ( onst gdsl_sta k_t S) |
|
Che k if asta k is empty. |
|||
|
|
gdsl |
sta k_get_top ( onst gdsl_sta k_ S) |
ˆ gdsl_element_t gdsl_sta k_get_bottom ( onst gdsl_sta k_t |
|||
Get the top of a sta k. |
. |
||
S) Get the b |
of a |
||
ˆ gdsl |
sta kottomgdsl_sta kk_set_name (gdsl_sta k_t S, onst har |
Generatedˆ voidG)NEWSetSetongdslthetheThuNAME)namegrowingJunsta22ofkfa11:15:30a settorta kof.growing2006a stafork. gdslfabytorDoxygen(gdsl_sta k_t S, ulong

178 |
gdsl Module Do umentation |
ˆ gdsl_elemen _ |
gdsl_sta k_insert (gdsl_sta k_t S, void |
ˆ VALUE)RemoveInsertelemenompareananelementelementfungdslingdslfroma staelementstaCOMPstak (PUSH)k remove(POP)searF,. void.h(gdsl( onststagdslk t S)sta k_t S,
ˆˆ S,gdslstagdslgdslSearSeark_eleelementthhmapS,forforstaenulongank artielementunPOS)gdslgdslularottombyMAPstai positionkkF,inmapsearvoidstainhakforward.stabyVALUE)k. position( onst gdsl( onststagdslk__t-
ˆ stagdslParsek elementS, gdslfromt apbgdslfunstaottomtopk._MAPmapUSERF,bavoidkwardDATA) ( onst gdsl_-
ˆvoidWRITEParsegdsl_aF,staFILEkkfromwritetop to( onstb gdsl. _sta k_t S, gdslUSER writeDATA)fun _t
ˆvoidfun ritegdslWRITEa l thestaelementskF,OUTPUTwriteFILEof a staxmlFILE,k to(gdsla voidle. staUSERk t_DATA)S, gdsl_write_-
ˆWRITEvoid gdsltheF,_FILEontentk_ofdumpa sta kOUTPUT(gdslto a lestaintoFILE,kXMLt .S,voidgdslUSERwriteDATA)fun _t
4..16.1.1.1DumpTypedeffunypedefthetionsinternalstruDoOUTPUTtstruumentationgdslture ofstaFILE,a stak kvoidto a USERle. _DATA)
butDeThisGDSLnitionbyypestatheisatkvoluntaryline.53ofGeneratedopaquethislegdslmodule.Variablesstaon .Thuk.h.Junof this22gdsl11:15:30kindstaould'nt2006k tforbegdsldireby Doxygently used,

. |
|
Sta k manipulation module |
|
179 |
||||||||
|
. |
|
.2 |
Fun tion Do umentation |
|
|||||||
|
defaultandfunAlloCreate |
|
gdslstastakallostainALLOC.kFthedata)k stafuntstrugdslFk.andtureTheset ALLOCstaFREEwhipointerskh allonameFFould,ouldis(gdslonstbesetbeusedtofreesetaharttopyrespefunNULLofNAMENAMEtively,tto use,.alloTthe |
|||||||||
|
4.16tionsfree.ate2.a1ones:elementsanewpointersnewFREE |
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
ALLOC |
F simply returns its argumen |
|
||
|
|
ˆ the default FREE |
|
F does nothing |
|
|
||||||
Note: |
|
|
|
|
|
|
|
|
|
|||
|
|
|
Complexity: O( 1 ) |
|
|
|
|
|||||
|
re ondition: |
|
|
|
|
|
|
|||||
|
|
|
nothing. |
|
|
|
|
|
|
|
||
Parameters: |
|
|
|
f the new sta k |
reate |
|
||||||
|
|
|
NAME The name |
|
|
|||||||
|
|
|
ALLOC |
|
F F |
on to allo |
to when insert ng it in a sta k |
|
||||
|
|
|
FREE |
F Fun tion to free elemement when deleting it from a sta k |
|
|||||||
Returns: |
|
|
llo ated |
|
k in ase f su ess. |
|
||||||
|
|
|
the newly |
|
|
|||||||
|
|
|
NULL in |
ase of insusta ient memory. |
|
|
||||||
See also: |
|
|
|
free()(p. 179) |
|
|
||||||
|
|
|
gdsl_sta k_ ush()(p. 180) |
|
|
|||||||
|
4.16.2.2 void gdsl_sta k_free (gdsl_sta k_t S) |
|
||||||||||
|
De |
stroy |
sta k. |
|
|
|
|
|
||||
|
|
|
|
all the elements of the sta k S by alling S's FREE F fun tion |
||||||||
|
pass |
|
to gdsl |
|
sta k |
allo ()(p. 179). The name of S is deallo ated and S is |
||||||
|
deallo ated itself too. |
|
|
|
|
|||||||
Note: |
|
|
|
|
|
|
|
|
|
PreGeneratedSComplexitondition:ust beThuy:a validJunO( |22Sgdsl| 11:15:30) sta 2006k t for gdsl by Doxygen

180 |
|
|
|
|
|
gdsl Module Do umentation |
|
|
Parameter : |
|
|
||||
|
|
gdsl_sta k_ ush()(p.179)80 |
|
||||
|
|
S The |
|
to destroy |
|
||
See also: |
|
allo |
|
||||
|
4.16.2.3 void gdsl_sta k_ ush (gdsl_sta k_t S) |
||||||
|
Flush |
sta k. |
|
|
|||
|
Deallo ate all the e ements of the sta k S by ing S's FREE F fun tion passed |
||||||
|
to gdsl |
|
sta k |
allo ()(p. 179). S is not deallo ated itself and S's name is not |
|||
|
m di ed. |
|
|
|
|
||
Note: |
|
|
stabe akvalidO(tofree()alloSushgdsl())(p(p. 179).sta k_t |
|
|||
|
|
SComplexity:also:ondition:Theust |
|
|
|||
|
|
gdsl |
|
|
|
|
|
Parameterre |
| | |
|
|||||
See |
|
|
|
|
|
PNote:Getsthe4.ostarameterre16QComplexity:.ondition:2ondi.4nameustonstbeof:a aO(validstha1 )kgdsl.gdslstastak_tk_get_name ( onst gdsl_sta k_t S)
TheThe ur ed string MUST NOT be freed.
S sta k to get the name from
Returns:the name of the sta k S.
See gdslalso:_sta k_set_name()(p. 183)
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

Sta k manipulation module |
|
181 |
||||||
4.16.2.5 ulong gdsl_sta k_get_size ( onst gdsl_sta k_t S) |
|
|||||||
Get the size of a sta k. |
|
|
|
|
||||
Note: |
|
y: O( 1 ) |
|
|
|
|
||
Complexitust be a valid gdsl_sta k_t |
|
|
||||||
Parameterre ondition: |
|
|
|
|
|
|
||
S The sta k to get the size from |
|
|
||||||
|
|
|
tsorkofofsta. StheForstaof)kthekstaexample,.getstakSgrowingk. SThisif(notedyouvaluesetfaSthis)tor. thevaluefa( onstamounttor()10,ofea hellstimeto |
|||||
berggumbernextgdslulongwinginsertionsoffastagdslelementstor |
|
|
|
|
||||
for |
|
|
|
|
|
|
|
|
Get4.16thethe.2.rtions6 |
|
|
|
|
| | |
|
|
|
Returns:reserv |
|
|
|
|
|
|
|
|
the um |
of elemen |
of S re |
|
10, then 10 new ells will be |
eserved for next |
|||
10 in |
|
. It is |
|
ay to avhestime for inserti ns. This value is by defaul |
||||
and an |
modi ed with gdsl |
sta k set growing |
(p. 183). |
|
||||
Note: |
|
y: O( 1 ) |
|
|
|
|
||
Complexitust be a valid gdsl_sta k_t |
|
|
||||||
Parameterre ondition: |
|
|
|
|
|
|
||
S The sta k get the growing fa tor from |
|
|
||||||
Returns: |
|
|
|
|
|
|
|
|
the growing fa tor of the sta k S. |
|
|
||||||
See also: |
|
|
insert()(p. 184) |
fa tor()(p. 183) |
|
|
||
gdsl_sta k_set |
growing |
|
|
|||||
4.16.2.7 |
bool gdsl |
sta k_is_empty ( onst gdsl_sta k_t S) |
|
|||||
Che k if a sta k is empty. |
|
|
|
|
||||
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |
|
|

182 |
|
|
|
|
|
|
|
|
gdsl Module Do umentation |
||
|
Note: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y: O( 1 ) |
|
|
|
|
|||
|
|
Complexitust be a valid gdsl_sta k_t |
|
|
|||||||
Parameterre ondition: |
|
|
he k |
|
|
|
|||||
|
|
S |
The sta k to |
|
|
|
|||||
Returns: |
|
|
|
k S is empty. |
|
|
|||||
|
|
TRUE if |
|
|
|
|
|||||
|
|
FALSE ifthesta k S is not empty. |
|
|
|||||||
4.16.2.8 |
gdsl_element_t gdsl_sta k_get_top ( onst gdsl_sta k_t |
||||||||||
|
|
|
|
S) |
|
|
|
|
|
|
|
|
Get the top of a sta k. |
|
|
|
|
||||||
Note: |
|
|
|
|
|
|
|
|
|
||
|
|
Complexity: O( 1 ) |
|
|
|
|
|||||
Parameterre ondition: |
|
|
|
|
|
|
|
||||
|
|
S |
ust be a valid gdsl_sta k_t |
|
|
||||||
|
|
The sta k to get the top from |
|
|
|||||||
Returns: |
|
on |
|
|
at the top positi n of the sta k S if S is not empty. |
||||||
|
|
the el |
|
|
|
||||||
|
|
The returmened elementained is not removed from S. |
|||||||||
|
|
NULL if the sta k S is empty. |
|
|
|||||||
See also: |
|
|
|
|
|
|
|
|
|||
|
|
gdsl_sta k_get_bottom()(p. 182) |
|
|
|||||||
4.16.2.9 |
gdsl_ |
elemen |
t gdsl_sta k_get_bottom ( onst |
||||||||
|
|
|
|
|
k |
t S) |
|
|
|||
|
Get the bottom ofstasta |
k. |
|
|
|
||||||
Note: |
|
|
|
|
|
|
s a k_t |
|
|
||
|
|
ComplexitS ust be a valid gdsl |
|
|
|||||||
Pre ondition:y: O( 1 ) |
|
|
|
|
|||||||
|
|
|
|
|
|
|
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |
|

|
4.16 Sta k manipulation module |
|
|
|
183 |
||||||||||
|
Parameter : |
|
|
|
|
|
|
|
|
|
|
||||
|
|
S The sta k to get the bottom from |
|
|
|
||||||||||
Returns: |
|
|
|
|
|
|
bottom p sition of the sta k S if S is not |
||||||||
|
|
the elemen ontained at |
|
|
|||||||||||
|
|
empty. The returned el |
entheis not removed from S. |
|
|||||||||||
|
|
NULL if the sta k S is empty. |
|
|
|
|
|
||||||||
See also: |
|
|
|
|
(p. 182) |
|
|
|
|
||||||
|
|
gdsl_sta k_get_ |
|
|
|
|
|
|
|||||||
4.16.2.10 |
gdsl_ |
ktop()gdsl sta k_set_name (gdsl_sta k_t S, |
|||||||||||||
|
|
SComplexitondition:nametheustbepreviousy:fnstaavalidO(stastahar1namekgdsl). |
_ofNEWstathek statNAMEk S to)a opy of NEW_NAME. |
||||||||||||
PNote:ChangeSetrethe |
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
arameter |
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
The sta k to hange the |
|
|
|
|
|
|
||||||
|
|
NEW NAME The new name of S |
|
|
|
||||||||||
Returns: |
|
|
|
|
of su ess. |
|
|
|
|||||||
|
|
the modi ed sta k |
|
|
|
|
|
|
|||||||
|
|
NULL in ase of insu asei |
|
t memory. |
|
|
|
||||||||
|
|
gdsl_sta k_get_name()(p. 180) |
|
|
|
||||||||||
See also: |
void gdsl_ |
|
k_set_growing_fa tor (gdsl_sta k_t S, |
||||||||||||
4.16.2.11 |
|
||||||||||||||
|
S |
|
|
|
ulong G)ofstasta |
k. |
|
|
|
the |
of ells to |
||||
|
|
|
growingfa tor |
|
|
the sta k S. This value |
|||||||||
|
|
thefor next insert |
|
. For |
|
|
|
if y u set |
this value |
10, ea h time |
|||||
|
next |
10 insertions. It ions way toexample,v ime for inserti ns. Tamounknow the a tual |
|||||||||||||
|
reservalue of the growing fa tor, use gdsl |
sta k_get growing |
fa tor()(p. 181) |
||||||||||||
|
the number of elements of |
S rea hes 10, then 10 w ells will be reserved for |
|||||||||||||
Note: |
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
Complexity: O( 1 ) |
|
|
|
|
|
|
|
|
|
||||
|
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |
|

184 |
|
|
|
|
|
|
|
gdsl Module Do umentation |
||
|
Pre ondition: |
|
|
|
|
|
|
|||
|
|
S ust be a valid gdsl_sta k_t |
|
|
||||||
Parameter |
: |
|
|
|
|
|
|
|||
|
|
S |
sta k to get the growing fa tor from |
|||||||
|
|
G The new growing fa tor of S. |
|
|
||||||
Returns: |
|
|
|
|
|
|
|
|
||
|
|
the growing fa tor of the sta k S. |
|
|
||||||
See also: |
|
|
insert()(p. 184) |
|
|
|||||
|
|
gdsl_sta k_get |
growing_fa tor()(p. 181) |
|||||||
4.16.2.12 |
|
gdsl_element_t gdsl_sta k_insert (gdsl_sta k_t S, |
||||||||
|
AInsertLLOClloelfutureelemenateantsaelementFinsertionsisnewvoidEtheSisreaelementhefuninVALUEintoahesinsertedtionstaSE'spointerkto(PUSH)growingbysavattheallingpassedtime.topfa.torS'sposition(G),gdslALLOCthenofstatheGFkstnewfunalloktionSells.()If(ponarethe.179)VALUEreservednumber.The. |
|||||||||
Note:forofnew |
|
|
|
|
|
|
|
|
||
|
|
Complexity: O( 1 ) |
|
|
|
|
||||
Pre ondition: |
|
|
|
|
|
|
||||
|
|
S ust be a valid gdsl_sta k_t |
|
|
||||||
Parameter |
: |
|
|
|
|
|
|
|||
|
|
S The sta k to ins rt in |
|
|
|
|
||||
|
|
VALUE The value used to make the new element to insert into S |
||||||||
Returns: |
|
|
lement E |
|
ase of su ess. |
|
|
|||
|
|
the |
|
|
|
|
|
|||
|
|
NULLinsertedase of insu ient memory. |
|
|
||||||
See also: |
|
|
s |
|
i |
f |
. 3) |
|
||
|
|
|
|
|
g t |
growing fa tor()(p.181) |
||||
|
|
gdsl_sta k_remove()(p. 185) |
|
|
||||||
|
|
|
|
|
|
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen |
|

|
Sta k manipulation module |
|
185 |
|||||
|
4.16.2.13 |
gdsl |
elemen |
gdsl |
sta k_remove (gdsl_sta k_t S) |
|
||
|
|
an |
|
t from a sta k (POP). |
|
|
||
|
Remove theelement at the top position of the sta k S. |
|
|
|||||
Note: |
|
y: O( 1 ) |
|
|
|
|
||
|
Complexitust be a valid gdsl_sta k_t |
|
|
|
||||
Parameterre ondition: |
|
|
|
|
|
|||
|
S |
The sta k to remove the top from |
|
|
||||
Returns: |
|
lement in ase of su ess. |
|
|
||||
|
the removed |
|
|
|||||
|
NULL in ase of S is empty. |
|
|
|
||||
See also: |
|
|
|
|
|
|
||
|
gdsl_sta k_insert()(p. 184) |
k_sear h ( onst gdsl_sta k_t |
||||||
4.16.2.14 |
gdsl_elemen _ |
gdsl_ |
Note:toSearompareComplexith for theaallpaS,y:S'srstgdsltiO(eularementomparelemenEwithequal.infunatostaVALUEstak. COMPin the_staF,kvoidS, by usingVALUECOMP) _F
ParameterreVALUECOMPSondition:TheustVALUEsbetaFTheakvalidThetovaluesear|Selemengdsl|omparison)tohthestaompareelemenk fun&S'stCOMPionelementsusedFtowith!=ompareNULL S's element with
Returns:the rst founded t E in ase of su ess.
NULL if no element is found.
See gdslalso:_sta k_sear h_by_position()(p. 186)
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen

186 |
|
elemen |
gdsl_ |
|
gdsl Module Do umentation |
||||||
|
4.16.2.15 |
|
k sear h_by_position ( onst |
|
|||||||
|
|
gdsl_ |
k |
t S, ul |
POS) |
|
|
|
|
|
|
|
Sear h for an elemenstaby |
its positionginstasta k. |
|
|
|
|
|||||
Note: |
y: O( 1 ) |
|
|
|
|
|
|
|
|
||
ParameterreNULLthePOSComplexitondition:TheustelementTheifsbetaPOSaposikatvalidtotheseariongdslPOSwherethe-stathiselementpositionkthet &elemenPOSininthetosta0sear&kPOSSh. |
|
= |
S |
||||||||
Returns: |
|
|
|
|
> |
< |
|
| | |
|
See4.16gdslalso:.2.16_stagdslk__sear>elemensta|L|kh()ortPOS(pS.t,185)gdsl<= 0.stmapk__funmap__tforwardMAP_F(,onstvoid
Note:returnsGDSLParsealled aonllitsMAPstaelemenealastkUSERhfromSexaminatedtsTOP,'ofelembottomtheDATAthenstatowithelementgdslk)topSUSERfrom.sta. bottomkDATAmapto_argumenttopforward(). The. MAPIf(pMAP.186)F_funstopsFreturntionandis
Parameterre Complexity:SMAPUSERondition:TheustforsbetaFwhiDATaTkvalidO(toeh MAPmappar|SUser'sgdsl| )funFreturnsstadatastionk topassedtGDSL&applyMAPtoonMAPeaF!=h_STOPS'sFNULLReturnselemen.Returnsthe NULLrstelementwhen
See also:the parsing is done. gdsl_sta k_map_ba kward()(p. 187)
Generated on Thu Jun 22 11:15:30 2006 for gdsl by Doxygen