View
239
Download
0
Category
Preview:
Citation preview
8/17/2019 Fs Lab Manual New
1/54
B.T.L INSTITUTE OF TECHNOLOGY &MANAGEMENTBANGALORE -560 099.
Department of Information Science & Engineering
Laboratory C rt!"#at
This is to certify that Mr./Ms...…………..……………………………………
bearing USN …………….……….has satisfactorily completed the course of
experiments in practical ………………………………………..….prescribed
by the Visvesvaraya Technology University !elgaum for ……………….…
Semester …………………..............................course in the laboratory of this
college in the year "##$%"#.
Signature of the Lab-In charge Signature of the HOD
Signature of the Examiners
&. ………………………
". ………………………
8/17/2019 Fs Lab Manual New
2/54
INDEXS.No Date Name of the Experiment Staff Signature
1IM LEMEN!"!ION O# I$O%EDI%E&!ION "ND I ES
'IM LEMEN!"!ION O# #IXED LEN(!H
%E&O%DS
)IM LEMEN!"!ION O# *"%I"+LE
LEN(!H %E&O%DS
,IM LEMEN!"!ION O# *"%I"+LE
LEN(!H %E&O%DS SIN( %%N
IM LEMEN!"!ION O# SIM LE INDEXON %IM"%/ 0E/
IM LEMEN!"!ION O# SIM LE INDEXON SE&OND"%/ 0E/
2IM LEMEN!"!ION O# &OSE3 EN!I"L
%O&ESSIN(
4IM LEMEN!"!ION O# 0-5"/ ME%(E
"L(O%I!HM
6 IM LEMEN!"!ION O# +-!%EE
17 IM LEMEN!"!ION O# +8 !%EE
11IM LEMEN!"!ION O# &OLLISION
%ESOL !ION !E&HNI3 E
1' IM LEMEN!"!ION O# %E&L"IMIN(#%EE S "&E SIN( LIN0ED LIS!
8/17/2019 Fs Lab Manual New
3/54
8/17/2019 Fs Lab Manual New
4/54
&b.cpp%%%%%%%%'include(iostream.h)'include(fstream.h)'include(conio.h)'include(string.h)int main01*
char temp,-fstream ifile ofileifile.open02src.txt2 ios++in1ofile.open02des.txt2 ios++out16hile0ifile))temp74NU881*strrev0temp1ofile((temp((endlcout((temp((endl
ifile.close01ofile.close01getch01
8/17/2019 Fs Lab Manual New
5/54
'. 5rite a &88 program to rea9 an9 an9search metho9s.
'include(stdio.h)'include(stdlib.h)'include(iostream.h)'include(fstream.h)'include(conio.h)'include(iomanip.h)'include(process.h)class student*
public+char name,&9- usn,&9- age,#9- sem,9- branch,&9- buffer,:9-
student s",#-void pac;01*
ofstream app&student sapp&.open02student&.txt2 ios++app1if07app&1*
cout((2cannot open file in o/p mode2getch01exit0#1
cout((2enter the student name+3t2cin))s.namecout((2enter usn+3t2cin))s.usncout((2enter age+3t2cin))s.agecout((2enter sem+3t2cin))s.semcout((2enter branch+3t2cin))s.branchstrcpy0s.buffer s.name1strcat0s.buffer 2
8/17/2019 Fs Lab Manual New
6/54
int count4strlen0s.buffer1for0int ;4# ;(:9%count ;551strcat0s.buffer 2721strcat0s.buffer 23n21app&((s.bufferapp&.close01
void search01*
fstream inchar usn,&9- extra,:9-in.open02student&.txt2 ios++in1if07in1*
cout((23n unable to open2getch01exit0#1
cout((23nenter the records usn you 6ant to search2cin))usnstudent s6hile07in.eof011*
in.getline0s.name &9 =
8/17/2019 Fs Lab Manual New
7/54
student sint ichar extra,:9-fstream inin.open02student&.txt2 ios++in1if07in1*cout((23n cannot open2getch01exit0#1
i4# printf02name3t3tusn3t3tage3t3tsem3t3tbranch3n216hile07in.eof011*
in.getline0s.name &9 =s3t3t>s2 s.name s.usn s.age s.sem s.branch1i55
in.close01getch01
void modify01*
fstream inchar usn,&9- buffer,:9- extra,:9-int i ?student s&,#-in.open02student&.txt2 ios++in1if07in1*
cout((2unable to open2getch01exit0#1
cout((2enter the usn2cin))usni4#6hile07in.eof011*
in.getline0s&,i-.name &9 =
8/17/2019 Fs Lab Manual New
8/54
in.getline0s&,i-.sem 9 =
8/17/2019 Fs Lab Manual New
9/54
strcat0buffer 2
8/17/2019 Fs Lab Manual New
10/54
). 5rite a &88 program to rea9 an9 an9 search metho9s.
'include(stdio.h)'include(stdlib.h)'include(iostream.h)'include(fstream.h)'include(conio.h)'include(iomanip.h)'include(process.h)class student*
public+char name,&9- usn,&9- age,#9- sem,9- branch,&9- buffer,:9-
student s",#-void pac;01*
ofstream app&student sapp&.open02student&.txt2 ios++app1if07app&1*
cout((2cannot open file in o/p mode2getch01exit0#1
cout((2enter the student name+3t2cin))s.namecout((2enter usn+3t2cin))s.usncout((2enter age+3t2cin))s.agecout((2enter sem+3t2cin))s.semcout((2enter branch+3t2cin))s.branchstrcpy0s.buffer s.name1strcat0s.buffer 2
8/17/2019 Fs Lab Manual New
11/54
strcat0s.buffer 23n21app&((s.bufferapp&.close01
void search01*
fstream inchar usn,&9-in.open02student&.txt2 ios++in1if07in1*
cout((23n unable to open2getch01exit0#1
cout((23n enter the records usn you 6ant to search2cin))usnstudent s6hile07in.eof011*
in.getline0s.name &9 =
8/17/2019 Fs Lab Manual New
12/54
cout((23n cannot open2getch01exit0#1
i4# printf02name3t3tusn3t3tage3t3tsem3t3tbranch3n216hile07in.eof011*
in.getline0s.name &9 =s3t3t>s2 s.name s.usn s.age s.sem s.branch1i55
in.close01getch01
void modify01*
fstream inchar usn,&9- buffer,:9-int i ?student s&,#-in.open02student&.txt2 ios++in1if07in1*
cout((2unable to open2getch01exit0#1
cout((2enter the usn2cin))usni4#6hile07in.eof011*
in.getline0s&,i-.name &9 =
8/17/2019 Fs Lab Manual New
13/54
*
cout((23n the old values 6ith usn+2((usn((2are2cout((23n name42((s&,?-.namecout((23n usn42((s&,?-.usncout((23n age42((s&,?-.agecout((23n sem2((s&,?-.semcout((23n branch42((s&,?-.branchcout((23n enter the ne6 values2cout((23name42 cin))s&,?-.namecout((23n usn42 cin))s&,?-.usncout((23n age42 cin))s&,?-.agecout((23n sem42 cin))s&,?-.semcout((23n branch2 cin))s&,?-.branch
else *
cout((2the record 6ith usn2((usn((2is not present2getch01return
in.close01fstream out&out&.open02student&.txt2 ios++out1if07out&1*
cout((23n unable to open2getch01return
for0?4# ?(i ?551*
strcpy0buffer s&,?-.name1strcat0buffer 2
8/17/2019 Fs Lab Manual New
14/54
*fstream infstream outint choiceout.open02student&.txt2 ios++out1if07in1*
cout((23n3ncant open2getch01exit0#1
out.close01for0 1*
cout((23n #+exit2cout((23n &+6rite2cout((23n "+display2cout((23n @+modify2cout((23n :+search2cout((23n enter choice2cin))choices6itch0choice1
*case &+ pac;01 brea;case "+unpac;01 brea;case @+modify01 brea;case :+search01 brea;case #+exit0#1default+ cout((2invalid ip2
brea;
8/17/2019 Fs Lab Manual New
15/54
,. 5rite a &88 program to
8/17/2019 Fs Lab Manual New
16/54
app&((s.bufferapp&.close01
void search01*
fstream inint rrnint i4#in.open02student&.txt2 ios++in1if07in1*
cout((23n unable to open2getch01exit0#1
cout((23n enter the rrn of the record2cin))rrnstudent s&,#- s"s".rrno4#6hile07in.eof011*
in.getline0s&,i-.name &9 =
8/17/2019 Fs Lab Manual New
17/54
int main01*
fstream outint choiceout.open02student&.txt2 ios++out1if07out1*
cout((23n3ncant open2getch01exit0#1
out.close01for0 1*
cout((23n #+exit2cout((23n &+6rite2cout((23n "+Search2cout((23n enter choice2cin))choices6itch0choice1
*case &+ 6riteArecord01 brea;case "+search01 brea;case #+exit0#1default+ cout((2invalid ip2
brea;
8/17/2019 Fs Lab Manual New
18/54
. 5rite a &88 program to imp;ement simp;e in9ex on primar> Ce> for a fi;e of stu9ent ob?ects. Imp;ement a99 : search : 9e;ete using the in9ex.
'include(iostream.h)'include(string.h)'include(fstream.h)'include(stdlib.h)class record*
public+char name,"#- age,9- usn,"#- branch,9-char sem,9-
rec,"#-char stAno,9-int novoid retrieveAdetails01*
fstream file"char name,"#- usn,"#- branch,9-char ind,9- age,9- sem,9-file".open02record.txt2 ios++in1for0int i4# i(no i551*
file".getline0ind 9 =
8/17/2019 Fs Lab Manual New
19/54
file".getline0ind 9 =
8/17/2019 Fs Lab Manual New
20/54
return
int main01*
fstream file& file"int choicechar rtAusn,"#- stAusn,"#-char ind,9- name,"#- age,9- sem,9- branch,9-int i flag flag&file&.open02index.txt2 ios++out1file".open02record.txt2 ios++out1if07file&
8/17/2019 Fs Lab Manual New
21/54
cout((2Cnter usn of student record to be searched3n2cin))stAusnfile&.open02index.txt2 ios++in1if07file&1*
cout((2error3n2exit0#1
flag&4#for0i4# i(no i551*
file&.getline0rtAusn "# =
8/17/2019 Fs Lab Manual New
22/54
cout((2Student details3n2for0i4# i(no i551*
cout((2Student 2((i5&
cout((2Usn+2((rec,i-.usn((23nName+2((rec,i-.name((23nBge+2((rec,i-.age((23nSem+2((rec,i-.sem((23n!ranch2((rec,i-.branch((23n2
brea;default+exit0#1
8/17/2019 Fs Lab Manual New
23/54
. 5rite a &88 program to imp;ement in9ex on secon9ar> Ce>: the name: for a fi;e of stu9ent ob?ects. Imp;ement a99 : search : 9e;ete using the secon9ar> in9ex.
'include(iostream.h)'include(string.h)'include(fstream.h)'include(stdlib.h)'include(conio.h)
class record*
public+char age,9- name,"#- usn,"#- branch,9- sem,9-
rec,"#- found,"#-int novoid sortArecords0int no&1*
int i ?record tempfor0i4# i(no& i551for0?4i ?(no& ?551if0strcmp0rec,?-.name rec,?5&-.name1)# FF ?5&(no1*
temp4rec,?-rec,?-4rec,?5&-rec,?5&-4temp
void createAindex0int no"1*
fstream index index"int iindex.open02secindex.txt2 ios++out1index".open02record.txt2 ios++out1for0i4# i(no" i551* index((rec,i-.name((2
8/17/2019 Fs Lab Manual New
24/54
*fstream fileint ichar ind,9- usn,"#- name,"#- age,9- sem,9- branch,9-file.open02record.txt2 ios++in1for0i4# i(no@ i551*
file.getline0ind 9 =
8/17/2019 Fs Lab Manual New
25/54
* cout((2Hhoose the candidates USN3n2
for0i4# i(; i551cout((2Name+2((found,i-.name((23nUSN+2((found,i-.usn((endl
cin))chusnfor0i4# i(; i551*
if0strcmp0chusn found,i-.usn144#1*
retrieveArecord0index,i- no:1return
cout((2invalid entry2return
void deleteArecord0char indx,- int no91*
int ifstream file& file"char name,"#- usn,"#- age,9- sem,9- branch,9- ind,9- index,"#-,"#-file".open02record.txt2 ios++in1for0i4# i(no9 i551*
file".getline0ind 9 =
8/17/2019 Fs Lab Manual New
26/54
if0flag440no9%&11*
no9%%cout((2Deleted3n2return
for0i4flag i(no9 i551*
rec,i-4rec,i5&-
no9%%cout((2Deleted3n2file".close01file&.open02secindex.txt2 ios++out1file".open02record.txt2 ios++out1for0i4# i(no9 i551*
file&((rec,i-.name((2
8/17/2019 Fs Lab Manual New
27/54
if0;44&1*
deleteArecord0index,#- noI1return
else*
cout((2Hhoose candidates usn3n2for0i4# i(; i551cout((2Name+2((found,i-.name((2USN+2((found,i-.usn((endl
cin))chusnfor0i4# i(; i551*
if0strcmp0chusn found,i-.usn144#1*
deleteArecord0index,i- noI1return
cout((2invalid entry2return
void main01*
fstream file& file"int choicechar rtAusn,"#- rtAname,"#- stAname,"#- stAusn,"#- stAno,9- ind,9-int i flag flag&file&.open02index.txt2 ios++out1file".open02record.txt2 ios++out1if07file&
8/17/2019 Fs Lab Manual New
28/54
*cout((2Name+2cin))rec,i-.namecout((2Usn+2cin))rec,i-.usncout((2Bge+2cin))rec,i-.age
cout((2Sem+2 cin))rec,i-.sem
cout((2!ranch+2 cin))rec,i-.branch
sortArecords0no1createAindex0no1file&.close01file".close01
brea;
case "+ cout((2enter name of student record to be searched2 cin))stAname file&.open02secindex.txt2 ios++in1 if07file&1 *
cout((2Crror2exit0#1
flag&4# for0i4# i(no i551 *
file&.getline0rtAname "# =
8/17/2019 Fs Lab Manual New
29/54
file&.open02secindex.txt2 ios++in1 if07file&1 *
cout((2Crror2exit0#1
flag4# for0i4# i(no i551 *
file&.getline0rtAname "# =
8/17/2019 Fs Lab Manual New
30/54
default+ exit0#1
2. 5rite a &88 program to rea9 t
8/17/2019 Fs Lab Manual New
31/54
void main01*
fstream out& out" out@int i ? m nchar list&,#-,"#- list",#-,"#-6ritelists01out&.open02file&.txt2 ios++in1out".open02file".txt2 ios++in1out@.open02file@.txt2 ios++out1if07out&
8/17/2019 Fs Lab Manual New
32/54
getch01
4. 5rite a &88 program to rea9 C Lists of names an9 merge them using C mergea;gorithm
8/17/2019 Fs Lab Manual New
33/54
temp4recrd,y-recrd,y-4recrd,y5&-recrd,y5&-4temp
fstream temp&temp&.open0filename ios++out1for0t4& t(;%& t551temp&((recrd,t-.name((2
8/17/2019 Fs Lab Manual New
34/54
for0i4# i(J i551file,i-.close01;6aymerge01fstream resultresult.open02&&&&.txt2 ios++in1cout((23n sorted records3n2char name,"#- usn,"#-for0i4# i(no i551*
result.getline0name "# =
8/17/2019 Fs Lab Manual New
35/54
6. 5rite a &88 program to imp;ement +-!ree for a gi=en set of integers an9 itsoperations insert an9 search . Disp;a> the tree.
'include(iostream.h)'include(fstream.h)'include(stdio.h)'include(stdlib.h)'include(conio.h)'include(math.h)'define order :'define min0int1ceil00float1order/"1struct node*
int level usageint numbers,order5&-struct nodeG children,order5&-struct nodeG parentstruct nodeG right
typedef struct nodeG NLDC NLDC head4NU88 cur temp up prev ne6up first temp& temp" NLDC getnode01*
NLDC tempint itemp40NLDC1malloc0si eof0struct node11if0temp44NU881*
cout((2insufficient memory3n2getch01exit0#1
temp%)level4#temp%)usage4#for0i4# i(4order i551*
temp%)children,i-4NU88temp%)numbers,i-4$$$
temp%)parent4NU88temp%)right4NU88return temp
8/17/2019 Fs Lab Manual New
36/54
void insertnode01*
int num i ? ; poi mincout((2enter number to insert into btree3n2cin))numif0head44NU881*
head4getnode01head%)usage4&head%)numbers,#-4numfirst4headreturn
else*
cur4head6hile0cur74NU881*
for0i4# ?4# i(40cur%)usage1%& i551if0num)cur%)numbers,i-1
?55 prev4curif0?44cur%)usage1cur4cur%)children,?%&-elsecur4cur%)children,?-
cur4prev poi4?if0cur%)numbers,poi-44num1*
cout((2element is already present3n2return
if0poi74cur%)usage1*
for0i4cur%)usage i)4poi5& i%%1*
cur%)numbers,i-4cur%)numbers,i%&-cur%)children,i-4cur%)children,i%&-
cur%)numbers,poi-4numcur%)children,poi-4NU88cur%)usage556hile0cur74NU881*
8/17/2019 Fs Lab Manual New
37/54
if0cur%)usage(4order1*
if0cur%)parent44NU881 brea;up4cur%)parenti4#6hile0up%)children,i-74cur1i55up%)numbers,i-4cur%)numbers,0cur%)usage1%&-cur4upcontinue
temp4getnode01for0;4min ?4# ;(order ;55 ?551*
temp%)numbers,?-4cur%)numbers,;-cur%)numbers,;-4$$$temp%)children,i-4cur%)children,;-cur%)children,;-4NU88
cur%)usage4mintemp%)usage4order%0cur%)usage15&temp%)level4cur%)levelif0cur%)children,#-74NU881*
for0i4# i(40cur%)usage1%& i551*
0cur%)children,i-1%)parent4cur
for0i4# i(40temp%)usage1%& i551*
0temp%)children,i-1%)parent4temp
if0cur%)parent44#1*up4getnode01up%)level40cur%)level15&up%)usage4"up%)numbers,#-4cur%)numbers,0cur%)usage1%&-up%)numbers,&-4temp%)numbers,0temp%)usage1%&-up%)children,#-4curup%)children,&-4tempcur%)parent4temp%)parent4uphead4upreturn
8/17/2019 Fs Lab Manual New
38/54
if0cur%)parent44NU881*up4getnode01up%)level40cur%)level15&up%)usage4"up%)numbers,#-4cur%)numbers,0cur%)usage1%&-up%)numbers,&-4temp%)numbers,0temp%)usage1%&-up%)children,#-4curup%)children,&-4tempcur%)parent4temp%)parent4uphead4upreturn
else*
up4cur%)parenttemp%)parent4upne6up4getnode01i4#6hile0up%)numbers,i-(cur%)numbers,#-1*
ne6up%)numbers,i-4up%)numbers,i-ne6up%)children,i-4up%)children,i-i55
ne6up%)numbers,i-4cur%)numbers,0cur%)usage1%&-ne6up%)children,i-4curi55ne6up%)numbers,i-4temp%)numbers,0temp%)usage1%&-ne6up%)children,i-4tempi55
?4#6hile0up%)numbers,?-(4temp%)numbers,0temp%)usage1%&-1*
?55
6hile0?(40up%)usage1%&1*
ne6up%)numbers,i-4up%)numbers,?-ne6up%)children,i-4up%)children,?-i55
?55
up%)usage4ine6up%)usage4ifor0i4# i(40ne6up%)usage1%& i551*
8/17/2019 Fs Lab Manual New
39/54
up%)numbers,i-4ne6up%)numbers,i-up%)children,i-4ne6up%)children,i-
free0ne6up1cur4upcontinue
void display0NLDC head1*
NLDC a,#- curint i4# ?4# ; levelcur4heada,i-4curi55
6hile0cur%)children,#-74NU881*
for0;4# ;(40cur%)usage1%& ;551*
a,i-4cur%)children,;-i55
?55cur4a,?-
i%%level4head%)levelfor0;4# ;(4i ;551*
cur4a,;-if0level74cur%)level1*
cout((23n2level4cur%)level
for0?4# ?(40cur%)usage1%& ?551*
cout((cur%)numbers,?-((22cout((23t2
8/17/2019 Fs Lab Manual New
40/54
void searchnode01*
int num i ? poicout((2enter number to search2cin))numcur4head6hile0cur74NU881*
for0i4# ?4# i(40cur%)usage1%& i551if0num)cur%)numbers,i-1
?55 prev4curif0?44cur%)usage1cur4cur%)children,?%&-elsecur4cur%)children,i-
cur4prev poi4?if0cur%)numbers,poi-44num1cout((2search success3n2elsecout((2search failure3n2
void main01*
int ch// clrscr01
for0 1*
cout((23n&.insert "+search @+display :+exit3n2cout((23nenter your choice3n2cin))chs6itch0ch1*
case &+insertnode01
brea;case "+searchnode01
brea;case @+display0head1
brea;default +exit0#1
8/17/2019 Fs Lab Manual New
41/54
17. 5rite a &88 program to imp;ement +8 tree for a gi=en set of integers an9 itsoperations insert : an9 search . Disp;a> the tree.
'include(iostream.h)'include(fstream.h)'include(stdio.h)'include(stdlib.h)'include(conio.h)'include(math.h)'define order :'define min0int1ceil00float1order/"1struct node*
int level usageint numbers,order5&-struct nodeG children,order5&-struct nodeG parentstruct nodeG right
typedef struct nodeG NLDC NLDC head4NU88 cur temp up prev ne6up first temp& temp" NLDC getnode01*
NLDC tempint itemp40NLDC1malloc0si eof0struct node11if0temp44NU881*
cout((2insufficient memory3n2getch01exit0#1
temp%)level4#temp%)usage4#for0i4# i(4order i551*
temp%)children,i-4NU88temp%)numbers,i-4$$$
temp%)parent4NU88temp%)right4NU88return temp
8/17/2019 Fs Lab Manual New
42/54
8/17/2019 Fs Lab Manual New
43/54
if0cur%)usage(4order1*
if0cur%)parent44NU881 brea;up4cur%)parenti4#6hile0up%)children,i-74cur1i55up%)numbers,i-4cur%)numbers,0cur%)usage1%&-cur4upcontinue
temp4getnode01for0;4min ?4# ;(order ;55 ?551*
temp%)numbers,?-4cur%)numbers,;-cur%)numbers,;-4$$$temp%)children,i-4cur%)children,;-cur%)children,;-4NU88
cur%)usage4mintemp%)usage4order%0cur%)usage15&temp%)level4cur%)levelif0cur%)children,#-74NU881*
for0i4# i(40cur%)usage1%& i551*
0cur%)children,i-1%)parent4cur
for0i4# i(40temp%)usage1%& i551*
0temp%)children,i-1%)parent4temp
if0cur%)parent44#1*up4getnode01up%)level40cur%)level15&up%)usage4"up%)numbers,#-4cur%)numbers,0cur%)usage1%&-up%)numbers,&-4temp%)numbers,0temp%)usage1%&-up%)children,#-4curup%)children,&-4tempcur%)parent4temp%)parent4uphead4upreturn
8/17/2019 Fs Lab Manual New
44/54
if0cur%)parent44NU881*up4getnode01up%)level40cur%)level15&up%)usage4"up%)numbers,#-4cur%)numbers,0cur%)usage1%&-up%)numbers,&-4temp%)numbers,0temp%)usage1%&-up%)children,#-4curup%)children,&-4tempcur%)parent4temp%)parent4uphead4upreturn
else*
up4cur%)parenttemp%)parent4upne6up4getnode01i4#6hile0up%)numbers,i-(cur%)numbers,#-1*
ne6up%)numbers,i-4up%)numbers,i-ne6up%)children,i-4up%)children,i-i55
ne6up%)numbers,i-4cur%)numbers,0cur%)usage1%&-ne6up%)children,i-4curi55ne6up%)numbers,i-4temp%)numbers,0temp%)usage1%&-ne6up%)children,i-4tempi55
?4#6hile0up%)numbers,?-(4temp%)numbers,0temp%)usage1%&-1*
?55
6hile0?(40up%)usage1%&1*
ne6up%)numbers,i-4up%)numbers,?-ne6up%)children,i-4up%)children,?-i55
?55
up%)usage4ine6up%)usage4ifor0i4# i(40ne6up%)usage1%& i551*
8/17/2019 Fs Lab Manual New
45/54
up%)numbers,i-4ne6up%)numbers,i-up%)children,i-4ne6up%)children,i-
free0ne6up1cur4upcontinue
void displaylist01*temp4first6hile0temp74NU881*for0int i4# i(0first%)usage15& i551*if00temp%)numbers,i-144$$$1cout((=3#=elsecout((temp%)numbers,i-((2 2
cout((23t2temp4temp%)right
void display0NLDC head1*
NLDC a,#- curint i4# ?4# ; levelcur4heada,i-4curi55
6hile0cur%)children,#-74NU881*
for0;4# ;(40cur%)usage1%& ;551*
a,i-4cur%)children,;-i55
?55cur4a,?-
i%%
8/17/2019 Fs Lab Manual New
46/54
level4head%)levelfor0;4# ;(4i ;551*
cur4a,;-if0level74cur%)level1*
cout((23n2level4cur%)level
for0?4# ?(40cur%)usage1%& ?551*
cout((cur%)numbers,?-((22cout((23t2
void searchnode01*
int num i ? poicout((2enter number to search2cin))numcur4head6hile0cur74NU881*
for0i4# ?4# i(40cur%)usage1%& i551if0num)cur%)numbers,i-1
?55 prev4curif0?44cur%)usage1cur4cur%)children,?%&-elsecur4cur%)children,i-
cur4prev poi4?if0cur%)numbers,poi-44num1cout((2search success3n2elsecout((2search failure3n2
void main01*
int ch// clrscr01
8/17/2019 Fs Lab Manual New
47/54
for0 1*
cout((23n&.insert "+search @+displaytree :.display tree 9+exit3n2cout((23nenter your choice3n2cin))chs6itch0ch1*
case &+
insertnode01 brea;case "+searchnode01
brea;case @+display0head1
brea;case :+displaylist01
brea;default +exit0#1
8/17/2019 Fs Lab Manual New
48/54
11. 5rite a &88 program to store an9 retrie=e stu9ent 9ata from fi;e using hashing.se an> co;;ision reso;ution techniGue.
'include(stdio.h)'include(stdlib.h)'include(string.h)'include(conio.h)'include(fstream.h)'include(iostream.h)class node*
public+char name,&9- usn,&9-node Glin;
node Gh,"$-void insert01*char name,&9- usn,&9- buffer,9#-fstream outout.open02student.txt2 ios++app1if07out1*cout((2n unable to open the file in append mode2getch01return
cout((2enter the name42cin))namecout((23nenter the usn42cin))usnstrcpy0buffer name1strcat0buffer 2
8/17/2019 Fs Lab Manual New
49/54
p4ne6 nodestrcpy0p%)name name&1strcpy0p%)usn usn&1
p%)lin;4NU88 prev4NU88curr4h,hashA;ey-if0curr44NU881*h,hashA;ey-4preturn
6hile0curr74NU881*
prev4currcurr4curr%)lin;
prev%)lin;4p
void retrieve01* fstream in char name,&9- usn,&9- int ? count node Gcurr in.open02student.txt2 ios++in1 if07in1 * cout((23n unable to open the file in input mode2 getch01 exit0#1 6hile07in.eof011 * in.getline0name &9 ="$ hashAinsert0name usn count1
cout((23n enter the usn42 cin))usn
8/17/2019 Fs Lab Manual New
50/54
count4# for0?4# ?(strlen0usn1 ?551 count4count5usn,?- count4count>"$ curr4h,count- /Gif0curr4NU881 * cout((2record not found2 getch01 return G/ if0strcmp0curr%)usn usn144#1 * cout((23nrecord found+2((curr%)usn((curr%)name getch01 return else * curr4curr%)lin; 6hile0curr74NU881
void main01 * int choice clrscr01 fstream out out.open02student.txt2 ios++out1 if07out1 * cout((23n unable to open the file in outmode2 getch01 exit0#1
for0 1 * cout((23n&.insert2 cout((23n ".retriece2 cout((23n&.exit2 cout((23n enter the choice2 cin))choice s6itch0choice1 * case &+insert01 brea; case "+retrieve01 brea;
8/17/2019 Fs Lab Manual New
51/54
case @+exit0#1 default+cout((23n invalid option2
1'. 5rite a &88 program to rec;aim the free space resu;ting from the 9e;etion of recor9s using ;inCe9 ;ists.
'include(stdio.h)'include(conio.h)'include(stdlib.h)'include(string.h)'include(iostream.h)'include(fstream.h)'include(ne6.h)class node*
public+ char name,"#-char usn,"#-node Glin;
node Gfirst4NU88void 6ritefile01*
node Gpchar buffer,#-fstream outout.open02student.txt2 ios++out1if07out1*cout((23n unadle to open the file student.txt in out mode2getch01exit0#1
p4first6hile0p74NU881*strcpy0buffer p%)name1strcat0buffer 2
8/17/2019 Fs Lab Manual New
52/54
*node Gpif0first44NU881*cout((23nlist is empty2return
p4first6hile0p74NU881*cout((2
8/17/2019 Fs Lab Manual New
53/54
return
cout((23n enter the usn to be deleted+2cin))usnif0strcmp0first%)usn usn144#1*cout((23n record deleted2del4firstdelete delfirst4first%)lin;6ritefile01return
prev4NU88curr4first6hile00strcmp0curr%)usn usn174#1 FF curr74NU881*
prev4NU88curr4curr%)lin;
if0curr44NU881*cout((23n The student 6ith usn2((usn((2is not present2return
prev%)lin;4curr%)lin;6ritefile01display01
void main01*int choiceclrscr01for0 1*
printf023n &+OnsertArear21 printf023n "+DeleteAid21 printf023n @+exit21 printf023nenter the choice421scanf02>d2 Fchoice1s6itch0choice1*case &+ insert01
brea;case "+ delet01
brea;case @+ exit0#1
brea;
8/17/2019 Fs Lab Manual New
54/54
Recommended