Aproj Ectrepor T On: Governmentpolytechni C, Ji Ntur

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

GOVERNMENTPOLYTECHNI

C,
JI
NTUR
APr
ojectRepor
tOn
"
progr
am t
odel
eteanodef
rom t
he
endoft
hesi
ngl
yli
nkedl
i
st"

Submi
tt
edby:
-
1)
Shi
ndeKunal
Bal
asaheb.(
CO222)
2)
Sol
ankeDur
geshSuni
l
.(CO223)
3)
Kut
eGopal
Pral
had.(
CO224)

Gui
deby:
-
ZahedAnsar
iSi
r.

SUBMI
TTEDTO:
-
Gov
ernmentpol
ytechni
c,j
i
ntur
Foracademi
cyear2021-
2022

1
MAHARASHTRASTATEBOARDOF
TECHNICALEDUCATI
ON
Cer
ti
fi
cat
e
Thisi stocert
ifyt
hatMr .KUTEGOPALPRALHADRAO.Rol lNo.
CO- 224ofThirdSemesterOfDiplomainComput erEngineeri
ngof
Insti
tute ,Gov er
nment Pol yt
echnic Ji
ntur.(code.0094) has
compl etedtheter
m wor ksati
sfact
ori
lyinCourseDataSt ructur
e
using 'C'(22317)fort he academic y ear2021 to 2022 as
prescribedi
nthecurr
icul
um.

Pl
ace:
Jint
ur Enr
oll
mentNo:
2000940065

Dat
e:………….
. Exam .
SeatNo.:
…………………

Subj
ectTeacher HeadOfTheDepar
tment
Pri
nci
pal

2
I
ndex

Sr
.No. Content PageNo.
1) ProjectAbst
ract 4
2) I
ntroducti
on 5
3) Al
gor it
hm 7
4) Program 8
5) Outputs 13

3
PROJECTABSTRACT:
-
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
……………………………………………………………………

4
I
NTRODUCTI
ON

Whati
sLi
nkl
ist:
-
Ali
nkedl i
stisasequenceofdat ast r
uct
ures,whichar
e
connect
edt ogethervi
alinks.Li
nkedLi sti
sasequenceoflinks
whichcontainsitems.Eachlinkcontainsaconnecti
ontoanother
l
ink.Li
nkedlististhesecondmost -useddatastruct
ureaft
erarr
ay.

Whati
sSi
ngl
yLi
nkl
ist:
-
Asi ngl
ylinkedlistisatypeoflinkedlistthati
sunidi
recti
onal,t
hat
i
s,itcanbet raversedinonlyonedi r
ect i
onfrom headtothelast
node( t
ail
).Eachel ementinali
nkedl istiscall
edanode.Asi ngle
nodecont ai
nsdat aandapoi ntertothenextnodewhi chhel
psi n
maintaini
ngt hestruct
ureofthel i
st.

I
nthisprogram,wewi l
lcr
eateasi nglyli
nkedlistanddeletea
nodefrom theendofthelist
.Toaccompl ishthistask,wef i
rstf
ind
outthesecondlastnodeoftheli
st.Then, makesecondl astnode
asthenewt ail
oftheli
st.Then,
deletethel astnodeoft heli
st.

5
How t
odel
eteel
ementf
rom endi
nSi
ngl
yLi
nkedLi
sti
n
C++?
Deletionf r
om endi nsinglylinkedlisti
nC++i soneoft he
variousdi fferentoper ationt hatwecanexecut eonSi ngl
yLinked
ListinCPPPr ogrammi ngLanguage.Si nglyLinkedListhasonl y
onepoi nterv ari
able,andhencewecanonl ymov einasi ngle
directi
on,t hat’swhyf ordel et
inganodef r
om theendoft heli
nked
l
istwef irstneedt otrav erset othel astnodewi ththehelpofa
pointerv ariableandt hendel eteit.Inthisart
icleletsseehow t o
codeaCPPPr ogram fordel etingthet ai
lnodeofasi ngl
yli
nkedlist
.

St
epst
odel
eteanel
ementf
rom endi
nsi
ngl
yli
nkedl
i
st:
-

1.Creat
eaclassNodewhichhastwoat
tri
but
es:dat
aandnext
.Nexti
sa
point
ert
othenextnodei
nthel
ist
.
2.Cr
eat
eanot
hercl
assDel
eteEndwhi
chhast
woat
tri
but
es:
headandt
ail
.
3.addNode(
)wi
l
laddanewnodet
othel
i
st:

a.Cr
eat
eanewnode.
b.I
tfi
rstchecks,whet
hert
heheadi
sequalt
onul
lwhi
chmeans
t
heli
stisempty.
c.I
ftheli
sti
sempt
y,bot
hheadandt
ailwi
l
lpoi
ntt
oanewl
yadded
node.
d.I
fthelisti
snotempty,t
henewnodewi l
lbeaddedtoendofthe
l
istsuchthattai
l'
snextwil
lpoi
nttoanewl yaddednode.Thi
s
newnodewi l
lbecomethenewtai
loft
helist
.
Del
eteFr
omEnd(
)wi
l
ldel
eteanodef
rom t
heendoft
hel
i
st:

a.I
tfi
rstcheckswhet
hertheheadisnul
l(empt
yli
st)t
hen,di
spl
ayt
he
message"Li
sti
sempty
"andretur
n.
b.I
ftheli
sti
snotempt
y,i
twi
l
lcheckwhet
hert
hel
i
sthasonl
yone
node.

6
c.I
fthel
i
sthasonl
yonenode,
itwi
l
lsetbot
hheadandt
ail
tonul
l
.
d.I
ftheli
sthasmorethanonenodethen,tr
aver
set
hrought
hel
i
st
t
il
lnodecurr
entpoi
ntst
osecondlastnodeint
hel
ist
.
e.Nodecur
rentwi
l
lbecomet
henewt
ail
oft
hel
i
st.
f
. Nodenextt
ocur
rentwi
l
lbemadenul
ltodel
etet
hel
astnode.
di
spl
ay(
)wi
l
ldi
spl
ayt
henodespr
esenti
nthel
i
st:

a.Def
ineanodecur
rentwhi
chwi
l
lini
ti
all
ypoi
ntt
otheheadoft
hel
i
st.
b.Tr
aver
set
hrought
hel
i
stt
il
lcur
rentpoi
ntst
onul
l
.
c.Di
spl
ayeachnodebymaki
ngcur
rentt
opoi
ntt
onodenextt
oit
i
neachi
ter
ati
on.

Al
gor
it
hm t
odel
eteanel
ementf
rom endi
nsi
ngl
yli
nkedl
ist:
-

I
FHEAD=NULL
 EXI
T
 SETPTR=HEAD
 Repeat5and6whi
l
ePTR-
>NEXT!
=NULL
 SETPREPTR=PTR
 SETPTR=PTR-
>NEXT
 NOW SETPREPTR-
>NEXT=NULL
 FREEPTR
 EXI
T

7
Pr
ogr
am f
ordel
eti
onf
rom endi
nsi
ngl
yli
nkedl
isti
nC++ :
-

#i
ncl
ude<i
ost
ream.
h>
#i
ncl
ude<coni
o.h>
#i
ncl
ude<ct
ype.
h>
#i
ncl
ude<al
loc.
h>
st
ructnode
{
i
ntnum;
node*
next
ptr
;
}
*st
node;
//nodeconst
ruct
ed
v
oidcr
eat
eLi
st(
intn)
;
v
oidl
ast
Del
ete(
);
v
oiddi
spl
ay(
);
i
ntmai
n()
{
i
ntn,
num,
pos;
cout
<<"
Ent
ert
henumberofnodes:"
;
ci
n>>n;
cr
eat
eLi
st(
n);
cout
<<"
\nLi
nkedl
istdat
a:\
n";
di
spl
ay(
);
l
ast
Del
ete(
);

8
cout
<<"
\nLi
nkedl
istaf
terdel
eti
on:\
n";
di
spl
ay(
);
r
etur
n0;
}
v
oidcr
eat
eLi
st(
intn)/
/funct
iont
ocr
eat
eli
nkedl
ist
{
st
ructnode*
frnt
Node,
*tmp;
i
ntnum,
i;
st
node=(
str
uctnode*
)mal
loc(
sizeof
(st
ructnode)
);
i
f(
stnode==NULL)
{
cout
<<"Memor
ycannotbeal
locat
ed"
;
}
el
se
{
cout
<<"
Ent
ert
hedat
afornode1:"
;
ci
n>>num;
st
node-
>num =num;
st
node-
>next
ptr=NULL;
//Li
nkst
headdr
essf
iel
dtoNULL
t
mp=st
node;

9
f
or(
i=2;
i<=n;
i++)
{
f
rnt
Node=(
str
uctnode*
)mal
loc(
sizeof
(st
ructnode)
);
i
f(
frnt
Node==NULL)/
/Iff
rnt
nodei
snul
lnomemor
ycannot
beall
ott
ed
{
cout
<<"
Memor
ycannotbeal
locat
ed"
;
br
eak;
}
el
se
{
cout<<"
Ent
ert
hedat
afornode"
<<i
<<"
:";
//Ent
eri
ngdat
ain
nodes.
ci
n>>num;
f
rnt
Node-
>num =num;
f
rnt
Node-
>next
ptr=NULL;
t
mp-
>next
ptr=f
rnt
Node;
t
mp=t
mp-
>next
ptr
;
}
}
}
}

10
v
oidl
ast
Del
ete(
)//
funct
iont
odel
etel
astnode
{
st
ructnode*
del
Last
,*pr
eNode;
i
f(
stnode==NULL)
{
cout
<<"
Listi
sempt
y";
}
el
se
{
del
Last=st
node;
pr
eNode=st
node;
whi
le(
del
Last
->next
ptr!
=NULL)
//Tr
aver
singt
il
lthel
ast
.
{
pr
eNode=del
Last
;
del
Last=del
Last
->next
ptr
;
}
i
f(
del
Last==st
node)
{
st
node=NULL;
}el
se
{
pr
eNode-
>next
ptr=NULL;
}

11
f
ree(
del
Last
);
//Del
eti
ngl
astnode
}
}
v
oiddi
spl
ay(
)//
funct
iont
opr
intl
inkedl
ist
{
st
ructnode*
tmp;
i
f(
stnode==NULL)
{
cout
<<"Nodat
afoundi
nthel
ist
";
}
el
se
{
t
mp=st
node;
cout
<<"
LinkedLi
st:
";
whi
le(
tmp!
=NULL)
{
cout
<<"
\t"
<<t
mp-
>num;
t
mp=t
mp-
>next
ptr
;
}
}
get
ch(
);
}

12
OUTPUT1OFPROGRAM:
-

Out
put2:
-

THANKYOU!

13

You might also like