0% found this document useful (0 votes)
18 views25 pages

Dynamic Stack Implementation in C

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views25 pages

Dynamic Stack Implementation in C

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Khiat a

callye
Dlticn at and.
Ang.
#inelude< tda h
# include< tdlib h>
#include <stiy hs
sthuct callg {
ch¡i nam [50]i
chas lacatien [0];
int utadlhd -ya;
*

( chasram L], chas


ctuct aallyy * chat lode yas){
lacatan [], int allx )
Ned (ctut
sthuct aally xnAe (ettuct));
mallac (iz f
’ naMe,

lacatian, lacatian);
stey ( wehede-’
Nade
uNade ’ noet = NULL;
futatn

* insuthEáant(utut callg tl
stuet alliy
das rane [], ta aaten ll, int yah
dat Nade (rane, lacabin,

ree lade;
ele Nade ’

- n Nade ;
lact eet
hehón laut;

End (sthact calyg


3 * det
shuct calg - -NVLL){

("hut is
");

et -- laet )f
(lact we
callg : %sln lat*
hsnd ("Deltid

ttahn NULi

lact ) {
ret ;
Vaid su bat ( sbuct cally
sthuct
stact

et csbont necti
(cstert );
aullent nest;

int hain l0E


NVLL )
sthuct allg * lat -
in chaia s0);
[s0], leaten
daatan
das nane Shasra";
chas Nae [)=Hasehit
Enbellmert. Na - 00125512 724;
kyg larg

\n"):

itf ('3 Diytly al allgu\n );


laet

(hd);

NVL)

int aunt 1;

ln);

batey

-- \n);
haa: ");

San (".d"4", kcheia);


shuteh (chaia ) i

getchaa ();
rane, siud (ram), ddn);
gut l ')a)]-0;
(locatia,
name [ sthcghn
");

lact sucautai!.
inustd at Eant
jiny ("callyg

bieak i
Casl 34:
dhly liut(aut);

ulist (Jaet)

it (0);
Ehement- 6
"Am '
Imhlament tu ctacks
LIFO.
2.
end ans (loh )
3.
iam ae

Imjlamentation mithd hainto.


abhy and tt
abig
nkud bat basad : neds.

Kg chasactesste
LIFO Behawaus Singk Accss hont
Dynamic izA Na Randa acCUse.

hduanlags
Sintk and ivt óatians
Canctant tine as cait shosatianal
lag imhlaont and ndoetand.
bmitatians
mitad cas
fiud wia in alg imhenoiati
Nat switabk hd handan accs n.
Etas candtiane<
stuck aukfaa i- Rch afatian an fall tok
stad undajlas
Kantigusd mneg in aig implanontatcy
Nan-contigu nbd bet imhkmaniatan.
A~onatic canyh in magy gammig a g
Ajlatiau etad).
Ahlicatan all mangemnt (aall

Exhissicn alatian and canebsiaN


Imhlemant tee stacke in a
#indude <stdiah
# include < stdlib h >
# dina [Link] I00

int ass IMAX. SIZE);

Vaid in itstacka ( T Stacks *ts) !

h 2 = MAXSIZE ;
is ’ tah

tah 2 == HAX-SI2E ;
tutusn ts

int ispull ustacs * ts){


ts ’

nt ispull 2 (Ta Stacks * ts)


itbn ts ’

Vaid hush 1(Bea Stachs *t, nt valu)E

valu)
hetusn
stack 1\n', Valu);

Jaid Push2 ( hu Stacks * s, int valu)


(6)){
/ (ifpal 22
vabe)i
utusn i

eushud 'hd t stack in au);


pont/ ("

it yalu - ts ass [t’ teh --] ;

(Tee Stacks * t){


(übns 2(t)) {
ini ('stad 2
int vala
vala);

dshly 1 (tua stacks a t)i


Enty 1(t)){

hutur;

foh (int i=0; i<- ts ’ 2 ; itt)2

pint ("stad 2mnt: ");


(int i- MAX-S1ZE -1; i - I ’ th2; i
int main)
hat Nae [)- AHahshit Shah
ley as
lig Erslrwnt No - 001255I272;
hintl ("l Name i sn Erlelinnt No: 14 \a.
Nama, Enhellt No);
TAe Stacks stacl
iit Stak (Reteck)i
huch 1(k etads, 10);
huah 1 ( &stack, 20) ;
hush 1 (& stacks 30) ;
2 ( stack, l00 2;
huch
(b stuck, 200 )i
ush 2
);
hucch 2 (e tack, 3oD

dihly 2 (k stads );
h2 (katachu ),;
ditly (btack);

huska (stako, Y0);


ush4 (A stac, So
);

hush2(Aataks, S00);
dishly 1 (katace);
dily2(Latac);
tn Di
" Ajm '- Chat
a
and thavhse ahtian
lict tuck
duti
Taaty i- Asad is a fndanantal nas pirihl Th
-fAt-at
that fellels the at- in
Means the
ayhiatians
inlliy
Vabias Carhutg sciva
In ualatien , unde
call Panggemant, ahlaeian
Mechanis
inbed diet impaantatieni sizu, bnba
atacbs tat hauu fred
Unlibe assy basd
inhlshatian hheuidg deranic menesy alaatian.
lat
Each aunt in the stack cartairs

Data
Nut fintu
The etad rantan

Sie Kenmty

stad.
Ala: Chut aa re nede keth giasn dat
Set ne nods nut haintu o cslnt tt.

Ume camhlit : o(1)


2.
tack.
(stack wnday iu )
stahe assknt tf nade in tnfoiy vaidl

Decknt tok wze.


angplaty : o(4)
3.

chucd /atak i

te anhauj: ol1)
al
betan.

jtvati thagh lach nsde wwiy nt


Bint lach points
nadis data until NULL is ah.
Ang
# inede <tdia hs
# jndlud< adlih h)

sthuct Nad * net;


3:
stud Ned * - NULL ;

int val i
atiut Nad * neu Nadei

scanf ("%4 ",bval) ;


(etuct Nade*) mrallec ( v'zi (itutNel)
LNad
NULL ){

fton i
stuct Nad *tard i

sutiln

-> dat i
net i
ia(toh);

NVLL){

i/(4 = NULL )f
int min){
int chaiaj
int (" Hasset Shaima l»);
i n ("O0125S1272Y n);

inf ("s. Erit in');


"Enld yout cia : ")i
oin ("Entu
kay ("hdAdaia) ;
case ( duia) f
weth

tuthse(),;

eit (0);

3
Ejuimnt-8
"Am Imhlannt wlha, Irurhan, g,
buct and Hah sat g alg
sthutu
let ina hehe alde
(anandiy ai duandg)
4 Sedian kat : It divtu thu infut abig
hatt : attd and unottd am i-0i n-2.
Phacgi the aty

thu
suing th
canhaiy adoant slount and
ak in whang atds.
shmand.

On)
ang iem
at a tme.

in cesuct patia.
inceet ks
: o(1)
O(n)
diud and anges faalgn
tu tgnl fale.
dvids ablay in
Phaccss
beaieb
oln)

angel algoslhy
Lt divd and
5. Qick sAt.: haau hiat elkment
ahand Jriat
aitay
hatttixh ahig

onhgn), hace anhlab oCgn)


b'raj hiah dat athuc
Phease bwl mar - high hem aey

until hh sze ie 1.
hut

canplnt: o(1)
a9- Tmhlent slecian sait, Butble
Jat, Mehge satt, ick sast, Instan
sat, and Heah satt uey
ahey as a dat itsucuit.
Ang > # ineude <tdieh )
<ddib h>

# dine MAX. SIZE 100

int tuyt *aj

3
leid electian Sott(int ass [], int n) {
int ai,j, rinDrdr ;
as (ie 0j i<n-l;it) {

(all

3.
3
ass l0, int n)f
Vad bublhist(nt
int
0; i<n-1;ir)
ah (iarj0ijcn-j-1ijt+) 1

id instientast (int ass I J, rtn){

i;

;
ind i, ), K
ind ní ltl;
int n2 h-mj

L[i]- a (Ati];

i-0j
j:0;
K=hj
hik (i<n1 blj<n2){

hi (i<n )í
itt
K++;
3
whik (j <nz) {

jtt;
K+tj

atTl, int l, int s){


Vaid melgeSOót (int
i t m(a-4)/2;
ath, A,m);
mOig Sott( al, S);
MWig Satt(ail,
(a ,h, m, h);

loe, int higt) i


haittian (int astlJ,ind
int

intj i

itti

3
utun (it l);
Vaid

quckast (a%, lu, j-D;

ind lakat - i;
int
int igt = 2rit 2;

fa (is n/2 -l; i>-0; i--)


hatity (ah , n, i);
i--) 1
fes (io n-l; i)- 0;
husil (abi, i, 0),

dut, sayhce, n *

NAY SJZE);

ainy (" Inald na


jututn 0;

(i=0i j<n; i+){


("td", k al Lil !- 1)5
7(zanf

3
hetan

You might also like