0% found this document useful (0 votes)
40 views

DS&A unit 2 (half)

The document discusses linked lists, a dynamic data structure consisting of nodes that contain data and pointers to the next node. It outlines various types of linked lists, including singly linked lists and doubly linked lists, and describes operations such as insertion, deletion, and searching. Additionally, it includes code snippets for implementing linked lists in C programming.

Uploaded by

vinaygdev6
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)
40 views

DS&A unit 2 (half)

The document discusses linked lists, a dynamic data structure consisting of nodes that contain data and pointers to the next node. It outlines various types of linked lists, including singly linked lists and doubly linked lists, and describes operations such as insertion, deletion, and searching. Additionally, it includes code snippets for implementing linked lists in C programming.

Uploaded by

vinaygdev6
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
You are on page 1/ 11

UNIT - D2

PAGE:
LINKED LIST DATE :

I;okd Ist sa
is dynamic data stuctune which
Can and stiok au Yequired duin g yen type
allocatio n the atlocath'on
wuing dynamie mamory
fictio'

Each yecorcd of a linkecd list is called a nae.


Knkud 's a celle ton of nocu wbore each node
Conats 2 feld
ioform otion (oata)
2. Addeu of the net node n the ist thu liokd
|'st is a collection of stuctre ordinec not by
by
the physical placament în memoTy but by the logical
linka that oe stored a pait of the dat in
the stctune itself
aldthe acta
START s
is a ylobal vaniable which poiats to he load
of linked I384.

NULL
pointen indicata the end of laked list.
of lioked Iist
sinqle Iinked list
double oked list
3 iTculan Ined list
dolble circulan lnked list

operation on lneed lst


fnwton
Deletion
Traveual
Con catenate
Seaneh
PAGE:
DATE

Bnked tist wnd to implument dota


data stuctne
Such au stcka Queu q'pha, tee
neation of lined list
s tuct node
stuet nede * pP
2fildi
int infor (item, dota )
stvct node net ; (0) * liok

Irnting New ode at the of linked


lst font.

Geate a stutne called onicket tthe fetd


Dame
lay id, rus. wickets, 6alls
write
pogam fo dylay playou hutng highat
Yur. wickat.
PAGE:
DATE :

# incluce < stdio.h>


main l)
struck nod

chas name eoJ;


int id [io];

iot wickets ;
int 00 Ball

void main ()

Struck cricket

print f (" Enten no playo ]a");


Scant ( .d

printf ( Enten plauyer detalls)


for (iz 0, <N; )
Scanf ( s d", " 4. d","d" is,
4ci: name
c[i idJ, &o[i:vun],4 [i wickt),+[: noball
int main
mar c[o].
for (i-|; icn; itt)
imar <c(i] TUu)
PAGE:
DATE

ineed list
# incluce
# inclde < malloc h
vofd CYeate - sLL ();
void diplay - sLL 03
void seanch - SLL) ;
void int- first
first-- SLL ();
void inent- lat. sLL ();
void i e t
-pos
void cdelete - fst-sue 0;
void dlelete lat- SLL);
void dlete - pos- SLL ();
stuct node

int data3
stuet node * net;

stuct node t stant ULL;


int maln )

int choice ;
while (1)

print rlate singly liokd list ")


priotf (" In 2.e display hel antat of stog'y
stngly tintad;
printf (ulo3 seanch y in a Singly linked Iist");
priot f ("1n int at fist posifon)
H.
print f ("n s. inwrt at lat posttion)
print f (ln 6. y t at positon";
priat t ( lng delet the key elem ent at iist posihon'
printlns delte the key element at lart positio):
ete the
printf (")ln g. delete the key elkment at pos ticn"):
PAGE:
DATE

print ("ln enter yowr choiee :"):


Scanf (" d", choiee);
Switch ( choice)

Cau 1 !. Greate- sLL 33 6yeak


Cau 2 - SLL(); 6veak;
Cau 3: Secnh Stl); beak :
Cau 4 insert Arst- SlL (); 6reak;
Ca s : iunt - layt- SLL (); break:
Cau 6 : inet pos- SLL ()break;
Cau 7: delete - first- sLL() ; break ;;
Cas delete - lat- sLLU)3 6yeak
Caw q? delete - pos- SLLl) ; 6reak
dfaut:eit lo);

vofd uat SLLL)

struct ncde * nkmp;


priotf ( enter the no o notei o);
Scanf (* d", n)
foy (i=0: len; it+)

ntmp (stuct node ) malloc (sia ofstuct nod


priot ("lo erten the data to be inuorted :);
Scanf (" .d",
. d" ntemp ~> data );
temp net
jf (stant
stot * ntemp:
V DATE

else
H4
temp
stt =

SCanf ( c" ¢ choice ) |6 1400

3
piot t ("lo singly nkd list Guatedl In'):
stayt
Vofd
dplay- see()
Stuct node * temp;
iot Count = 0;
NULL)
printf ("
lse
lihkd Iist is empty "J;
iprint f (" ln contents of singly Iinkd tist are lo2
for (temp Sant tmp ! e noel; temp =temp ->next

Count tt
mp -’ data);
print f ("ln total nodu fn Itnked list
is %d", count};,

Rn temp Stat 3001


stot temp
300 2001

666
PAGE
DATE

void seanch - s LL )

shuct node * temp


fnt Rey flaq=o;
printf n ehten key to be sianchd in su;:
if start
printf ( sihgy Itokd list is em pty I!] sard
Caknbt te done la");
else

tp stant;
while (temp

break;

temp tmP

paotf (la key not found in se |a):


ese
found in sLLln");
pintf (" Bay
PAGE :
DATE

void iwt - first- sLl)

shuct noce ntemp


otemp =(shuct noden ) malloc (stz of (stuct nod)):
brintf ( ln eoten the data to be inunted at
of sLL:); bugining
SConf ("d", 4otemp -dota);
ntkmp
if (stnt NuL)
Stat =ntemp '
z

clse

ntemp
stant =ntemp i
printf ("ln new node inted at frst
positienln");

void r t layt sLL )

s tuet nede nemp, * CUY;


ntermp = (stuct node ) molloc (sie of (stvctno)
priat 4(° enten the data to be iruted at lat positon
of sLL);
Scanf (" %d", fn temp - dta);
ntemp -- pet ULL;
if (stont NULL);
print f ("In eopty SLL inentioo connot be perfemel
at lat posttion)o)'
else
PAGE:
DATE

Cun = stant
while ( cun - neat != NULL)

- ntemp
printF (ln nw node inyted at lat posihon
3

void inwnt Dos ~ SL


-pos
struct node t ntemp , * pre tprev;
fot count pes;
tenp (stuet node) malloclsize of (stctnode)
ntemp - net ULL,

priotB ("enten data for new node to be ihotet ):


Scanf ( 1d", 4ntemp -> data);
printf ( nentor he position for frtion::
Scanf (" /d" 4po s);
f(stant pos >1)

printf ( invalid postten "):


retunn
(pos - ))

) neat sant:'
stant nkmp:
Yetunn

Count 1,
PAGE:
DATE

CUY = stant
wbile ( cwn ! = NULL B Count !=
pos)
tprev
Count +t}

if (ount = pos)

tprev > nvat = ntemp


3
ntmp
else

priatf ( invalid data position !! tion


Cannot be done in seLln");

proqram to find the factoricad of aa numben using


finchion.
# incude < stlio " h >
jnt foct (int );
void ma'n )

int n, factoyial;
printf (" Entn a nunben:|o);
Scant ( d"
factorial = fact (n)
printf ( he foctorial of td s td Io'.n,
foctorial);
PAGE:
DATE

fot fact (ioto)

for iz; icn; itt)

You might also like