DSNotes M2
DSNotes M2
Data hyPe.
whose
Abstact Data Type CADT) i a type of object
b y a set valueJ and
behavioY detined
Set of o perationJ. Tu definiion of ADT only
Lhat "perari0s aje to be per formed but not he
Inkrtau Stack {
Public vold push (srig str);
I| add neu eument qbiract
methods
public shriny pop O ;
eument
Stack
Repiesentation
of Srackj
4 Stack Operaions
Push 0peration
2
2
2
lnih al popx!
Slrutk underflo
· Peek operarion
Thil peYahon is used p ele ment
from Stack with our deleting it.
Dipla g operahon
Coh tnh of the stak ADT.
Displays
4. Ruhun
CStack, to iHn):
I. Yehn 1hm
Stack Ctop J.
2. Te yn
Impumentation of Stack using Lin ked List
can Ypy cJent stack lin ked lisE. In a
stack push and pop operationy an performed at
called Can perfurm Simi tar
operahioS at
Oe end of ligt using hp poinr.
400
dat
20
Start
200 lo 3o0
’ Applicationy of Stack
its tw
which
operand. Its qlso
c plau
calle
arithti
polöh notaon
tA- abe *4AB-c0
operator precedene:
consideiing fiu bi nary
operaons : - (subract) Cmulkpy
| cdtvid) A(erpoNnt). have fo lto wiy
o1der of pecedenu:
peraoy Valw
PTecedene
3
hghet
2
neAt highest
Lowey t
algovithm
:
po stfix expiession,
3. Jf 1he CharahY i an opeYa tor, check wether
Stack ib empty
a) lf Tne Stack
empty I push opr into stack
stack i not empy (hech prioity or opr.
i) lf the piiority ot scanned opera ty > operator
Present op of stack then Push
operarY in o stack.
i) f he priorty ot Scanned opera tor L=
operar Present at pop
operaor romn stack ard add hA post f
expression and 90 shp i)
4. lf charactey i)
righ t paran hesis Tn Pop
all opera br and operandy from Sack unkI it
Yeaches left paran heis and add
algebraic * preslon,
to
R AB ((-C
AB
AB C g n :
A BC t
AB + a j 2
sA B C+
ABC +- D
ABC +-D
7
ABC t -D*EF t
postfix notaDono g i v e h
Tu eguivalent (ett)
algcbraic expression ((A - (B+c)) 3 D)t
is A Bc+- D* EF t T
D
)
-(D
I-(0
) - (D
B-(D *)
B - CD )+
A AB-LD
+ A B -(0
(
. Evalu at
6,5
2 6,S,L
6,s,2i3
2 3 6, s,S
6, S,s, 1
40 6,S,40
6, 45
3 6,45,3
3 647
6 27 2?8
* fueue
Cqn detined
Aqucue an o rdered )t which
enables in sert opea1io ns be aF on
per form cd
end called Rear and delek opera tions be perfomad
at
ano heY end ca lled Front.
Princip u :
Queue is TetHr ed o be as First In
Enqucue operahon
add a ne w element he Year ed
2ucue. Reay poin kr i) inrCmend.
algoyith m
men,
piint " Qucu is full
exit
Tear = reaY +I
QCrear]= ihm
engeuc
front
Dequeu operation
Yemove an element
fom
of front pin kr i in Yemenred
algovith m
(front == o) hen noeyve
jt
print 2
else fron6
font]olh
iHm= queue t
it (hont ear) then
Honto 2
rear L
else
ont fyont +}
Lmp or not.
lsEmpy ) : (hecky if
data elemnt
peekC) or front): Aquiey
qvailabu at u on t node Lueue
This operati on
contain.
ral number
in 4 mem!
Theye 2ueue
aYra
fxed
linked uses do ub lined list
py ovides ueu whose siL can Va ry durig
4nd
procesing.
Representqtion of
queues uJing array
dimensional CI NI, can be used
A on ayay Say
Two poin kys , na mcly
te p1eyenr a 2ueue.
frON and REARI aYe used to indica two
endy of
2
queueil emp
ont = YeaY = 0
on O year = (
enucu 2L 33
21 33 1eaY =3
front =o
deyw
fron t= Year =3
300 3o X
460
100 200 300
tions oft
’ Applica queue
t jobs to be
H wsed to scheduL
Central Proceoing Unit (cPU ).
Shen mulipu wses Send print joby
printr, eacn printing
qucu. Then ha piinrr prins h
phning
to fst in frs out bas.
job) acco vdi ng
search data
Breadth
to fnd
first
qn element from 9 JYaph. stulun
* Types of queuL
’ Simp qucue Co) Linear Queue
IrAear ShrytuYc which fo ll0 wy
Paricular or der in hich operati on s
performed. order
queuc
max maximm siu 6 u ajiayt
1.
Singls tin kLd list
2 boubly linkud li3t
3. Arags
alorithm in a cirCulqr
toy engueue
(front=(ear 41) /marsiu )
2ueue over floLJ
taku value
if (front == -1)
front= Year o
btaL 4cue CyearJ = i m
else Koite
YeaY = (rear +1) /max-siu)
2ueue Ciear J = itcm
it (tront = = -1)
wrik ucue is nder flo
elsehid
ik m
A4ins
else
front = (hont t )/max-si
qbbrevakd
A deubu-ended queue Cdequeue, of hn
t gencrqlug 4
deue pIonouned deck) 4dded b
which - Can be
queue , for elemens
Chead) or
YemOved from erthar u front
back C4ai)
It is qlso Called a head - tail lin ke d
add add
Clement eleme
Frant
umove umoL
elemenf element
dlele
front
Outpur Restrictd Dege (ORD): |F i) a deque,
ohich alo) deletion end but allows
insertioN at both ends of
inert
front
Operatio nJ:
Deq ue
" Ingert- front () - ujed to push an elemnr ho ta
front deyue.
reaY
tronr
kront
34
YeAY
front
back
frum
elcmn qn po used C): back umoL-
23
S
from . qpe hae fyont
element an pop Uled front(0: move- u