Professional Documents
Culture Documents
at begin
I n s e r t i o n
position
3) at a n y
Insertion
position
4) node any
a
Delete
5) node in SLL
Scarch a
6) c h o i c e . . .
2
12->78->29
Enteryour
->
34
TheNodes are: ->23-> using
SLL for all menu options.
program
Test the
above
h»
Program 4
aMent
fintlude
>
imih.h
<
sinlude
i n c h u d e k m u h r h h >
inude tshdbal.h
t i n c d d e L s k d i o . h s
4nchude esd t b h
i n t m dt eshringh
li
dhw yoad ine dlistnod Doublytnked lyt no de
sruck Dously nke
hypedef Lnbebs Doubly Lnksdit
ypece shrutt Doubly
inksLs rodef
shutl Oouby
M dada rvede neat;
Donsynkid kst
de prev;
Douby linkd kst ro
Jhutt Dowbly inkadust
Douby tinkud kst rNode head;
*
bi ). >
lalsnts/ rorde
(dobly Lnk1od Ust)-3to:
& (*douhly Lntsd.
ode prev
new urgn
Chan m
3
21SC1202 DATASTRUCTURES
n LabTask
verse the
the list without using the reverse function. The input and outot
Reverse a List elements.
Reverse
natically. You need to write a nction with the recommended method signature.
I. list of
handle
will
be
p o r t i o n s
r a n k . c o m / c h a l l e n g e s / f p - r e v e r s e - a - l i s t / p r o b l e m ? h _ r = i n t e r n a l - s e a r c h
https://www.hackerrank.com/ch
Program
ttincdude cstdio. h
i n t u d e c s t d kb-h>
shruttnde
int vd
shud no
de *new
S r u t t nsde
hea4 )
void pr-
pnt f(H->")
whle Chead
print F(lbnIn
void introt ( shunole** hea,int vJne )
Sut nede nt ade
NULL:
e-hod-(uct no de ) mallo c (te -
void m a )
P A d e n numn of eltmedA: )
SCanf( d; &ound
fovlio ietonk ; ir7)
ebmnt.c
Enar nume f
Aen oh h m u 1o
:
Saln qh elmas : 0o
uo
hen 3 cdemand
Ene y en :50
->/1(
->lo-8- >3o ->ho->s0
lenned L
21SC1202-DATASTRUCTURES
list
linked
doubly linke list, reverse the order of the nodes in place. That is, change
Reverse a node ofa doubly the direction ofthe list is reversed. Return a reference to the head
2. to
the.
head
so that
pointer o fthe
Given
the pointers
andp r e v
next list.
that the list is empty
the to indicate
r e v e r s e d
node
ofthe
node
might beNULL
head
The
Note: below.
F u n c t i o nD e s e r i p t i o n
editor w.
function
in the
reverse
the
Complete p a r a m e t e r ( s ) :
head of a DoublyLinkedList
following
to the hea
has the a
reference
reverse Node head:
D o u b l y Li n k e d L i s t N o d e
https://www.hackerank.com/challer
erank.com/challenges/one-month-preparation-kit-reverse-a-doubly-linked
list/problem?h = i n t e m a l - s e a r c h
Program
Hinchuk cstdio. h>
kb h>
ntlude es
Shrut node
ntdabr,
shut Node Aeat
shr NodePev
mp: Cunent->pV
CuYYen-> prev =uent
- Nn
wYn> ntt: hmp
(lhmg 1-0DLL)
heod-amp->prev,
70
Void pubh (shuct Nodehed -rt}, iw
new.ada)
Skutt Node new-node
pwC(4., node->dadh ).
node node >nent;
owp
Gn s
mant)
I23 S6
Stru Node head NULL Revnsed A
unh lhesd,u)
push (Lheud, 8)
push C hd, lo)
inkad tst
PrtCh brigin
prirtlyt Chnd
ewnse (kinc)
Reverte linkd kud tt
t
prrttl In
21SC1202-DATA STRUCTURES
Linked
list
Doubly
that contains integers as the data in each node. These data on cach
1linked list
Circular c i r c u
ardoubly
special algorithm that prints the three continuous clements of the list,
l a 1
3 a
have
g I v e n
developedas
You
n o d ei s
or
d i s t i n c t .
element
first w i l l be {1,9,12,9,12,7,12,.). The output contains the infinite number of
trom
the algorithmn
of
the You
Y o u are given only a part of the output that has been returned by the
starting
output
list, circular
the number of elements available in the original list and print the respective
the a
then it 1s
because
determine
elements
task is tto
Your
algorithm
elements.
hackerearth.com/problem/algorithm/hiddent-doubly-linked-liste8c l feadi
https:/ www.hackerearth.com/p
w
Program
tindeude 2stdio.hs
intmirt)
0, k
int num
Sanb (d, num)
)malloc (Jite ind ) °num)
' n t - L s nt
( t i e df lin)*num)
)mullo
t ullt (int
7tT)
for (i0, < num;
Stan : (W+1)):
1cenum / de Ls 3+2]): lb +*
kov (1
wlt (it : est [3 +7)
thn o
71
21SC1202 DATA STRUCTURES
S h I L
S s l o n
I .R e m o r eF r i e n d s
be
h cr
come celebrity
a
at her univerwity,. and her faccbook profile is full of friend
hus
h us
Christie
has accepted all the requests.
C h r i s t i c
D,
PhD,
is, Christie
getting
her
t h e nice
irlshe
girl.
Aner
Being
she is getting r o m olher guys, so he asks her to delete some of the
uests.
ll the attention
requcs of
jeulous
is
Kuldeep
Ilist.
fricnd
w
Now
lrom
her
some friends from her friend list,
since she knows the popularity
guys Acides
Christie d ecide to remove
scene' uses s
algorithm to delete a friend.
the following
avoind
a
she has, she
To triend
of the Friend.length-1 if (Friend[i).popularity
:DeletelFriend-false for i
I
1 to
rithm Delete(Fricnd):
delete i th fris
cteFriend-true break ifDeieteFriendfalsc) deletethe last friend
1)popularity)
Friendit
https://www.huck
data-structures/linked-list/singly-linked-lis
nckerearth.com/practice/da
-list/practice
problems/algorithm/remove-friends-5/
ProRram
Hntlude shdio n>
nlraut hp;
nt man(void)
ht nk, num
Stanf(rd, &E)
Lkle Ct>: 1)
14 num
SutChp Jia toP -1)_ 74
op
op+
SPLk roP): nwn
We k:1)
3 uSG
- DATA STRUCTURES
21SC1202
list. Given
is visited m o r e than
once
while traversing the a
cu cle if ar
cycle if any node 1. Otherwise, return 0.
2 .
C y c l eD e t e c
said
t i o n
to
contain
a
determine
contains
if it c ontain a cycle. If it does, return
is
l i n k e d
list
ked list,
linke.
o fa
A head
the
to
pointer 1->2->3->NULI
list so return 0.
data values. There is no cycle in this
ofnodes
Example
not their
tothelist numbers,
headrefers shown
are
the
2->3-> -> NULL
-> 2
The
numbers
nodes 1
to the
list of back to n o d e 1, so i urn
refers points
head node 3
where
cycle
There is a
F u n c t i o n D e s c r i p t i o n
editor below.
function in the
0 if there is
Returns not
or
there is a cycle
- Int: 1 if
https://www.hackerrank.com/challenges/detect-whether-a-linked-list-contains-a-cycle/problem?
h>
de <stdio
Program i n t u
Singuy nkud hst
int dat
Sinolunanteds node neat;
Dthunn 0,
75
21SC1202 DATA STRUCTURES
null meaning
head
R e v e r s e
a to
the
may
pointer given
3. ->NULL
the
head
pointer 1->2->3->
referencing the head ofthe list
thelist now
Given
The refurn head,
reversed. es
in place and
each.node
feach
E x a m p l eh e a dr e f e r e n c e s
pointers
of
the
ipulate
3-2->1>NULL.
beloow.
Function Description
the editor
ion in
f u n c t i o n .
reverse
Complete
the
parameter:
-SinglyLinkedLi
of the reversed list
r e f e r eence
ne to the head
a
pointer:
Returns
i n k e d L i s t N o d e
Singly hackerrank.com/challenges/reverse-a-linked-list/problem?h_reinternal-search
n NVL
Cuv = heas
uhile tuN
nexCurnerd
eV t r
CwYneu
76
21SC1202-DATASTRUCTURES
list
linked
sorted linked lists. The data in both lists will be sorted in
sorted head nodes
node
of two
mo the
Merge p o i n t e r
to
to obtain a single, merged linked list which also has data in ascending
4 the
next
nters
pointers
Tre
You
order. Changei
benull
meaning
a s v e n d i n go r d e
given
may
m ay
pointer hallenges/merge-two-sorted-linked
www.hackerrank.com/chal,
Either
head
ier.
hs
Programttinthe
.de
de m r Node
Stdro
lah (ringlo Lnkud ist rudehe,d
hs
Sngy
l
LIF n u s
h u d . malle
(singy Lnkud us)
nkud
fnqy ULL
ne Head-had: NULL
lail: nvIL
N Head nJuLiL hens 2enUIL)J
while ( hesd!
: l-^dJ}
hexd
daba >
i Ckead1
node-inb-Singy-inkd
-
hend 2 ht ad 2
nent,
while hend1!nuL
no minh Sina -liskedst (Lneshens, herk?~
L
headhead 1 hex
3
whe (head 2! wUL
C Lnes hoad, hendes
hent_node-inh-Singy-uotud-lst dada
head hea d 9hew
linkedlist
headofa node before the head. The next value in the
new node
at
deatthe
the list,
inked list.
insert a new
reference to the
linked
node new
a ofa with a given value. Return a
Insert the
head
should eplaced
5. to
data
value
is empty
Given
a
pointer
head
and
the
be null meaning
that the initiai
to given may
point pointer
should The h ead
list.
i n s e r t N o d e A
f u n c t i o n
parameter(s):
the following
mplete the
ofa list
Comp
has
insertNodeAtHead reference to the head
SinglyLinkedListNodellist
new node
field of the
fie
insert in the data
com/challenges/insert-a-node-at-the-head-
ad-of-a-linked-list/problem?h r=internal-search
value to
https:/www.hackerrank.com/cha
data:
the
Program t d i .h
d). hs
h e a dhtadhre
ly inked L
a t ha
Noe a had(sing
deine po
Linkedbpé
Node inno Node Lst, int dade)
Singly
Lnked ly
maloc(d*
of (inguy
Sinaly bnkeclst
node
new
pode)
ne data : duta,
afnev
nw nerl-\\o
vehwn r;
nt nent hst
78
21SC1202 DATA STRUCTURES
a the tail
G i v e n
from
C o u n tb a c k w a r d s
rds
Exanple refers to from the tail. The value is at the desired position.
n a tches
its distance
values
match
data
e
Function Description
following
has
the
refers to the head of the list
SinglyLinkedListN.
getNode pointerhead:
retrieve
to
the i t e m
p o s i t i o n F r o m T a i l :
int
Returns
position
desired
the
value at
https://www.hackerrank
int: the rank.com/challenges/get-the-value-of-t
f-the-node-at-a-specific-position-from-the
t a i l / p r o b l e m ? hr = i n t e r n a l - s e a r c h
dode(sin9y inked
isb Mode * u a , int p/t:on
Tarl)
int C:1, i:l
bnked tse node ~
phr =hend
Sinqly
ohile (per nnt !:0ULL
ph p h - > n e t
79