Professional Documents
Culture Documents
Adobe Scan 07-Mar-2022
Adobe Scan 07-Mar-2022
Adobe Scan 07-Mar-2022
Insertinga Node
Into a Sorted of a doubly-linked
list and an
L. reference to the
head
insert it at the proper
location to maintain the sort
NULL
ixample list 1
<->2
<>4->
#include <8td6elh
#nclude s<Stdib-h> 3
Hinclede<stdl?b-hz 84ct Doubly Linkedlfs
#include csring h> Ooubly/nkefsfalode hend
Doublylfnked tis tNbde tal
cha neadlinet);
3
ypede sbutt Doublylhked Cheafe
0oullylinkestst alode
-
nede.- ide-doub
Bert
inI(0ouiylinked tR*
erdeuel
COublatnhelafnio
node
(Dulytinkeltfploke=
tfnked
Ltfalode
e -deublyRnte0S-node le(node
ly
Ooubly nedttlot
node nodener
neonerr=head
head-PhcU = ns
Cderbl niked.st)>tsknele, 3
e l r neu
node data y
dal5
2 . D e l e t ed u p l i c a l e - f
nkea Ist
ter to
to the head node of a
the
poiter
sorted linked list, where the data in the
1 are
given
return a sorted
sorted list with cach nodes is
given headascending
Delete
nodes
and
distinct value in the original list. The
order.
that he list is empty.
ay benull
indicating
pointer
Exampe list 1I ->2
first node in the list
rst node in the ->2 ->2->3->3>33-NULL.
. s
https://www.hackerrank.com/chailenges/dclete-duplicate-value-nodes-from-a-sorted-linked-
list/problem?h_r=internal-search
Program
Hncludkasth suenghlealsdaldo)
c ude <m?ts h> Rnt dofa
4ncude <math.h> stngyLRnleed Liat Albde*nexf
neude <stddh
inue<StAfat-h stauet strgLnke Lsf
melude <s4doh>
3ha LRokes Lisfalsko* he
inc ude <stt s Rnkelstalsir{al
4 cde sAatra,h
choeadine)
pedeshuct 8gyrked
tsA alole stal hkes Cs sloke
noeaiq no data,
eeeaut straynkes
Rs SnglaLRnketisk node ne xt -uL
etu no
5
2
U
1 - .t
C
iaha |
21SC1202- DATA STRUCTURES
be 3. nodes, we
need to print second middle elemene
nt. For
would be two middle
should
output there
nodes, then should be 4.
4->5->6 then output
1->2->3->4>
list is
linked
nodes in the linked
list
example, ifgiven should add
https://www.hackerearth.com/problemalgorithm/tind-the-middle-of-a-given-linked-list-using-recursion.
Note: Insert
function
on/
lash-pft snetdSred
Program
#ncluce zstdfo h> ak-phs
f0EL- h> slouops/ous-pt->ner
Ene lude (S
S/ruct n ode
PhintfThe middie elemen
N
Pnt dafa /d\ninl slow-P dala)
Smutt nlode"nexf,
head-
Mllskuct alode vod puahStauet alode**
.evo p nt
neus -daBa)
read) ne fnt
-nefJ =nesy-nade
C head
56
nodepér)
(s4utt
Ood pnLR
hile (pis A t l )
215C
pihtf 7 d pla-daka)
Task
Pla pla next co game,
Krishse, Vasu. Shiva.
to Anand
e rally tsg is given
linked ist of Single
circular
s a
shortest person in the
how is the
thei s t
the list
shoriest person
in the list.
e
choice: 17
nter your
of the Player-
nt ma?nt) .2
name and height
=alULt,
sAut alode*heas 4.9
.5
our choice: 2
a
Height
5.2
.i
PhfntI (had) 3.3
5.4
4.9
5.5
5.0
enu ***
-34-S-alvLL
the mdale cduenen l
- 3-4->5- NuLL
Theidde duncnt C3
21SC1202-DATASTRUCTURES
Skill Session
LinkedList
Elements
ofa linked list, print cach node's ata element, one per line. If the head pointer
Printthe node ofa l
1. pointer
to
the
hecad
function
printLinkedlList
the parameter(s):
Complete
following
has the of the list
P r i n t L i n k e d L i s t
https://www.hackerrank.com/challenges/print
SinglyLinkedL
istNode
challenges/print-the-elements-of-a-linked-list/problem?h_r-internal-search
kassenf h>
ErouEa4tint
hude
tinclude limiksh
<math .h>
inelu de
tnttude <sfleokh?
#nclude gstddefh
include (sfdnfh
nclude Astlo-h>
ncludegstdl6 h>
list of integers along with an integer 'N', Write a function to append the iant
list of
intea
1.Linkeds t linked
a
singly ked list and returna the new head to the list,
given
been
front
o fthe
https://www.codechef.comproblems/REC
You
have
the 05
towards
nodes
N'
t n c h e d e( s d r o . h >
Program:
f m e h u d e r s A r b h >
yPpeoe shruetnode
int dala;
Smuet node nex
dad
3 node"cneaft
ndelint
struet
rutt nede")
Newnode(S
matlocisiy Snuttnodr
netonode > NvLL stnuct ncde fe mp-head
while (lemp nexfl-a/vte
neturn Joll
temp femp nert
dala d la, 3
newnode
cturn nttwnode; emp-ne xt >ncuwnode
3 hctorn heqd i
ofmuetnede* n berfafendlstrud |3void print(sfnuetnosde *head
nodehead, tnt dala)
head= =Atvtl)
(hcad: ntull netern
Sfruet node emp-hea
*
s f r u c t node
emp:head
emp? :
head
3
head
endlhenà
inbetabendi
-inðerlaen d/. rtaNode at the Tailof aLinked List
egiven the pointer io the head node ofa linmked
3
o h i l e( l e m p - > n e r t l : n l y
KCUk>o) odeATail has the following parameters
LinkedListNode pointer head: a reference to th
am
lude aserth
else {
bneak append[-k, heclude l'mik.h>
emp: lemp-epl; head v/udekmath h
eleude 13tdkoc h
3hecad temp-)ncxt
n et m n 0 clude 1StddePh7
femp2 nezt: templ; clude<stdnt h
emp p e t ialvll clude s teio.h
ekadeks tlh
| Pint(lhead), c luede As tring.h7
npd
int Prainvoid) { readlihe C)
int t eolef stmuet Singlylin hL
n 5
Scamf('d, te); 34lhkedlistrlecle
"
3,4
ohile(t--) data vaus =t, 2,2, ede f shut f Singly inkedl
nglinkedLt,
S/ruet nede"head »alellopu lafale
uet Sngly Lnked
int C: Oj n data
oAle () Singly tinke3talede
https://www.hackerrank.com/challenges/insert-a-node-at.t
Program
Hinc lede{astert:h>
e-tail-of-a-linked-list/problem?h rinternal-search
1Singlylinkedlistnlode7
nclede <lvrîks h>
kma th h>
Chealesingly-linked lish_node(?nt
includc
#Tnc lude {stdkosl h Singlylinkedlistwod
malloc(sig of
et pode
nodo-ata)
einclude <Stddfh 7 singly
node data =node-dta nbods) linked[kh
nclede sfdint hz
node next lutl
tinchude (s tefo.h
c tuna node ;
fnelde <s tHl:b h>
Snc lude <s ting.hy void prinfusindy Inked.I3t
cha readliheC)i CSinglylike list nede nodeC hod
s/nuet Singlylin kL%/nkeieE fpbr) FlLe fp fr)
ypedef
whfle (node) {
SPnglytnked Listnlode
ypedef shuet singlyinkedl&t fpaint F(fpfs,*7d ,noe-da
node node -neyt
Singlylinke dL&t,
struet Singly binked tfnlede (nede)
n dafa
fprintk Pphs7S,Sp
Singy tinked/3tatodenexl void ree-s/ng -linked-1t
sbrutf singynked/& ff
Csingly Linkel Lisfntodet node)
SnglyLinkel[?sfAlede "head, shile (nede)
61
Srng lynk edli's t Nodet lenp-node it[¬zrl_FAn.
TFALLUR
node cde ->ney l> fn(int:o, iAllR/.
reeltmp) chod 11st-er
hat llikt-hmsstsesA
Sing inhed lis/Nodenbelninlatatla
ho)
int llis? lem sfa lolel (tSsti
iy inhed(Rt atohed,
Plen -cndpts,to).
(uistA hem.endph.
head: Note) {
e furn nislem-Sfs \1" th/
e
Chea le_siny 1nked.13/ nde(hlo), 'o"
Singytnhedlsttsly,
singlyinkedl3t Node nede hrud,
=
DATA
STRUCTURES
a Node
posilion in a linked list and return a
linked
4.Delete
Delete
the
node at
a grven
after you e delete the node In that
case, return
referencetto the head node.
list may
be empty a null value. The head is at
0. The position
Example
L h i s t 0 - > I - > 2 - > 3
Position= 2
, llist
2, llist =0
=0-
>3.
removing
the node
at position
After
Function Description
ction in the editor belov
deleteNode functi
the
Complete parameters:
following
has the
SinglyLinkedListNode pointer ilist: a referenc
deleteNode
the head node in
the 1st
of the node to remove
the position
-int positio:
https://www.hackerrank.com/chalenges/delete-a-node-from.a
Program
l enges/delete-a-node-from-Singylink
a-linked-list/probledlist
em?h_r=iNod
nternal-search
#inchudecaxM orlh
inçlude <lmits h>
node dota
include math
h>
Fnclu deestdboolh
snay tinke dlist alodened -
inclhe (sfdetf-h> wallos(s ct (singly hkeafsf nlbd
Enelude s fPnf.h> node-dakq -ndde -dalo
nclud e RsfJfoh> node > next
include <SJl6 h>
=lutl
3 euin node
#ndude <stzgh ofnset-node irdo -sirglynk.
chat neadlinet)i ts
1-CsPenkedLs7" sirdy.th ke
typele- s/rut sinalinlediode sfnt node -do
snglylivkest Ktede ; SnglyLinked L84 Atode nok
redelsbructSingyrkelt cHete-ing n ke4sf-nede(ned
ra linbeJlst
Stnueh SirgyLPrkedlst rlo
int dala CCsng hksd t)hess
Sfhgynkedl+st dalo* nex
3 s y nked aed Aode
sHuctstydlinkel tiSt
SinginkedLRstMsdethead Prt
Csinq y- 1hked-le)->4alode
3
CSingy-mked st)stail: node
62
epit S,led 8/yVO
malloc
tivkei&tModnde chab Sep
us-heod lull,
&lelnode 18 1o Null;
FLepho
bpengetenv (bupot.PATM'), |
21SC1202 - DATA STRUCTURES
Node from 1 to N. The tail of the list points to head of the list i.e.
Kth
n u m b e +
N
nodes
ked
5<-" An integer K is also given to you. You start
Remove
contains
N=5 |->2->3->4, A
5. list cont
list For when
A linklar in natd when you reach Kth node in the circular list you remove that node. For eg. if K-7
A
linked
we
istfrom he
counting from head.
ht now nd move K steps ahead till we reach node numbered 3 in circular list 1->2-3-
I rig
this node now the new linked list looks like this 1->2->4, .
i.e. node
head
from
We
remove
Node
start
S -
now we start counting from the next node. This process is repeated until
> 5 > 1 - > 2 - ]
has
been
removed
Aaserkh,
h> sfrglynkedlist nlcdY
ineleude
h>
tlm s
roem
sinady inkia!Stntede*head) ee
RyPrked8f)s1Snext
Mode
63
-oid pint sing-nkeds
SRrdyLnkal& slodenede dan
LefpbX
feots-_endphs,lo).
encp
aPlehede
11 eols-endpa/-1
pH b7d,ned» skaha),
noeode-next, SexftEnT-FAIWA
Cnoe eho lst-Coant
pin Fp7S, se)» ehot tr'sfl-tounlsh.
eadlneC
inl tsLcoum
sinayLRnkest aiade* pede stn (A-counksls,
tlenede hisf-tount-endph,1t)
Srynke Rstnbde" kmp:
node
istl_ee ale endp'
-lst-Counf-st1)
ee femp)
be Comgone \i|srg
cxerm-FAlLURE)
neN 'st lodot eci, ehont tisk_km.s}a
Rsaode7 head ) SEgt?aked ncadline O)
3
nt ma nc )
fepergefenv("corpur- PAT")
eha iss-endphs
215C1202- DATASTRUCTURES
lists
Compare twolinkedtothe head nodes of two linked lists. Compare
thehea the data in the
5. pointer
the nodes of the linbodL
You're
given all data attributes
cqual. .
are equal and the lists are the same length, return 1.
to
if they
are Otherwise return
check
Example
llist1:1->2->3NULL
llist2: 1->2--à3--à4-àNULL
aequal
l data
lists have
data attributes for the first 3 nodes. List2 is
longer, though, so the lists
The two are not eaual
Return 0.
Function Description
parameters:
has the following
Compare lists
SinglyLinkedListNodellist a reference to the head of a list
SinglyLinkedListNode llist2: a reference to the head ofa list
htgps:/www.hackerrank.com/chalilengeicompare-two-linked-lists/problem?h_r=internal-scarch
Erogram includc KaeThh
ue gnenkedtst
h fnclude klimi fs.h>
Stnayk ejLi nlo*head,
ncude {math:h>
Anclude (sfdboo].h> soLnkedLRgfac
#include <s fdle f.h > ndy tinkedf'st alode
ntude {s tdfnt hn Ceete -Sfnal-1fnke -1-node
n clude sfdo h> Cnt nede -duda)f
A include istninq.h>
aninked tistnlodense
cheor ncadlineC )
Malte(gABray*mlsedtAlalt
ypcdcf shuet sfnglylnked
nodedoia -hade_data ,
MoAe
Ipedel squds tauAMMeAn etuen neder
3
gfdhent - node -into -SRg
3
tquchSera utkLPÅ rMd
,I
trscount-end fi> rllsSh-count-san3 reunt
endfslo')
Sex(exIT FANVRf)
use only)
(For Evaluator's
Evaluator's Observation
Any out of
Comment of the Evaluator(if Marks Secured:
Evaluator:
Full Name of the
Evaluation:
Evaluator Date of
the
Signature of
65