Programs

Published on May 2016 | Categories: Documents | Downloads: 41 | Comments: 0 | Views: 423
of 234
Download PDF   Embed   Report

Comments

Content

calendar program - ACG

prototype.h

#include <stdio.h>

#include <stdlib.h>

#define TRU !

#define "A#$ %

int get&day&code 'int year()

int get&leap&year 'int year()

*oid print&calendar '"+# ,fout- int year- int day&code- int leap&year()

int get&year '*oid()

main.c

#include .prototype.h.

int main'(

/

int year- day&code- leap&year)

"+# ,fout)

fout 0 fopen '.calendar.t1t.- .2.()

year 0 get&year'()

day&code 0 get&day&code 'year()

leap&year 0 get&leap&year 'year()

print&calendar'fout- year- day&code- leap&year()

printf'.3pen up 45calendar.t1t45 to see your calendar...4n.()

return %)

6

func.c

#include .prototype.h.

int get&year '*oid(

/

int year)

printf '. nter a year7 .()

scanf '.8d.- 9year()

return year)

6

int get&day&code 'int year(

/

int day&code)

int 1!- 1:- 1;)

1! 0 'year - !.(< =.%)

1: 0 'year - !.(< !%%.)

1; 0 'year - !.(< =%%.)

day&code 0 'year > 1! - 1: > 1;( 8?)

return day&code)

6

int get&leap&year 'int year(

/

<<if''year8 =( 00 % ()

if'year8 =00% 99 year8!%% @0 % AA year8=%%00%(

return TRU )

else return "A#$ )

6

*oid print&calendar '"+# ,fout- int year- int day&code- int leap&year( <<function header

/

int days&in&month- <, number of days in month currently

being printed ,<

day- <, counter for day of month ,<

month) <, month 0 ! is Ban- month 0 : is "eb- etc. ,<

fprintf 'fout-. 8d.- year()

for ' month 0 !) month <0 !:) month>> ( /

s2itch ' month ( / <, print name and set days&in&month ,<

case !7

fprintf'fout-.4n4nBanuary. ()

days&in&month 0 ;!)

breaC)

case :7

fprintf'fout-.4n4n"ebruary. ()

days&in&month 0 leap&year D :E 7 :F)

breaC)

case ;7

fprintf'fout- .4n4nGarch. ()

days&in&month 0 ;!)

breaC)

case =7

fprintf'fout-.4n4nApril. ()

days&in&month 0 ;%)

breaC)

case H7

fprintf'fout-.4n4nGay. ()

days&in&month 0 ;!)

breaC)

case I7

fprintf'fout-.4n4nBune. ()

days&in&month 0 ;%)

breaC)

case ?7

fprintf'fout-.4n4nBuly. ()

days&in&month 0 ;!)

breaC)

case F7

fprintf'fout-.4n4nAugust. ()

days&in&month 0 ;!)

breaC)

case E7

fprintf'fout-.4n4n$eptember. ()

days&in&month 0 ;%)

breaC)

case !%7

fprintf'fout-.4n4n3ctober. ()

days&in&month 0 ;!)

breaC)

case !!7

fprintf'fout-.4n4nJo*ember. ()

days&in&month 0 ;%)

breaC)

case !:7

fprintf'fout-.4n4nKecember. ()

days&in&month 0 ;!)

breaC)

6

fprintf'fout-.4n4n$un Gon Tue Led Thu "ri $at4n. ()

<, ad*ance printer to correct position for first date ,<

for ' day 0 !) day <0 ! > day&code , H) day>> (

fprintf'fout-. . ()

<, print the dates for one month ,<

for ' day 0 !) day <0 days&in&month) day>> ( /

fprintf'fout-.8:d.- day ()

if ' ' day > day&code ( 8 ? > % ( <, before $atD ,<

<, mo*e to ne1t day in same 2eeC ,<

fprintf'fout-. . ()

else <, sCip to ne1t line to start 2ith $un ,<

fprintf'fout- .4n . ()

6

<, set day&code for ne1t month to begin ,<

day&code 0 ' day&code > days&in&month ( 8 ?)

6

6

 

DMA

prototype.h

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

*oid concat'char ,,-int()

main.c

#include .prototype.h.

int main'int ma1-char, arg*MN(

/

ma10atoi'arg*M!N()

printf'.4nma1 8d.-ma1()

printf'.4npattern 8s.-arg*M:N()

char inputMH%N)

char ,,str-,,temp)

str0JU##)

temp0JU##)

int i-count-len)

count0%)

for'i0%)i<ma1)i>>(

/

memset'input-%-H%()

printf'.4n nter a string 7 .()

fgets'input-=E-stdin()

len0strlen'input()

printf'.4nlen 8d.-len()

inputMlen-!N054%5)

if'% 00 strcmp'input-.end.((

breaC)

if'JU## @0 strstr'input-arg*M:N((

/

count>>)

temp0'char ,,(realloc'temp-count,siOeof'char ,(()

<<printf'.4nT $T.()

<,if'JU## @0 temp(

str0temp),<

tempMcount-!N0'char,(malloc''strlen'input(>!(,siOeof'char(()

strcpy'tempMcount-!N-input()

6

6

printf'.4ntest.()

concat'temp-count-!()

for'i0%)i<count)i>>(

free'tempMiN()

free'temp()

temp0JU##)

return %)

6

func.c

#include .prototype.h.

*oid concat'char ,,name-int c(

/

int i)

char outputMH%N)

memset'output-%-H%()

for'i0c)i>0%)i--(

/

strcat'output-nameMiN()

6

printf'.4nThe Resultant $tring is 7 8s.-output()

6

FILES

header.h

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

*oid merge'"+# ,,-"+# ,,-"+# ,,()

main.c

#include.header.h.

int main'int argc-char ,arg*MN(

/

if'argc@0=(

/

printf'.4nLrong number of arguments..()

e1it'%()

6

"+# ,input&int 0 JU##)

"+# ,input&str 0 JU##)

"+# ,output 0 JU##)

input&int0fopen'arg*M!N-.r.()

input&str0fopen'arg*M:N-.r.()

output0fopen'arg*M;N-.2.()

merge'9input&int-9input&str-9output()

fclose'input&int()

fclose'input&str()

fclose'output()

return %)

6

func.c

#include<header.h>

*oid merge'"+# ,,input!-"+# ,,input:-"+# ,,output(

/

int n)

char ,s:)

<<s!0'char ,(malloc'siOeof'char( , H()

s:0'char ,(malloc'siOeof'char( , H()

2hile'!(

/

fscanf',input!-.8d.-9n()

fprintf',output-.8d.-n()

fgets's:-H-,input:()

fprintf',output-.8s.-s:()

fprintf',output-.4n.()

if''% @0 feof',input!(( AA '% @0 feof',input:(((

/

breaC)

6

6

6 FILE_BIN

header.h

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

typedef struct

/

int rec&no)

int emp&id)

char ,name)

char ,department)

char ,phonenumber)

6 mployee)

*oid insert' mployee ,()

*oid display' mployee ,()

main.c

#include .header.h.

#define GAP H

int main'(

/

"+# ,input 0 JU##)

mployee emp&arrayMGAPN)

mployee emp)

int num-i-ch-id&search-rec&search)

int ret&*al 0 %)

int err&*al 0 %)

char name&searchM:%N)

memset'name&search-%-:%()

printf'.4n nter the number of records you 2ant to input- it should be lesser than 8d 7 .-GAP()

scanf'.8d.-9num()

for 'i0%)i<num)i>>(

/

emp&arrayMiN.rec&no0'i>!()

insert'9emp&arrayMiN()

6

input0fopen'. mp&data.-.2b.()

if 'JU## 00 input(

/

printf'.4n rror opening file..()

return %)

6

ret&*al0f2rite'emp&array-siOeof' mployee(-num-input()

<<printf'.4nf2rite returns 7 8d.-ret&*al()

if'num @0 ret&*al(

/

printf'.4n rror in f2rite.()

6

ret&*al0fclose'input()

if '% @0 ret&*al(

/

printf'.4n rror in closing file..()

return %)

6

input0fopen'. mp&data.-.rb.()

if 'JU## 00 input(

/

printf'.4n rror in opening file..()

return %)

6

do

/

printf'.4n nter your choice 74n nter ! to search record by name.4n nter : to search record by +K.4n nter ; to search record by number.4n nter = to e1it 7 .()

scanf'.8d.-9ch()

fseeC'input-%-%()

if '! 00 ch(

/

printf'.4n nter the name to search 7 .()

scanf'.8s.-name&search()

2hile'!(

/

ret&*al 0 fread'9emp-siOeof' mployee(-!-input()

<<printf'.4nfread returns 7 8d.-ret&*al()

if '% 00 ret&*al(

/

err&*al 0 ferror'input()

if '% @0 err&*al(

/

printf'.4n rror in reading file..()

6

else

/

printf'.4n 3" reached..()

6

breaC)

6

if '% 00 strcmp'emp.name-name&search((

/

display'9emp()

breaC)

6

6

6

else if ': 00 ch(

/

printf'.4n nter the +K to search 7 .()

scanf'.8d.-9id&search()

2hile'!(

/

ret&*al 0 fread'9emp-siOeof' mployee(-!-input()

<<printf'.4nfread returns 7 8d.-ret&*al()

if '% 00 ret&*al(

/

err&*al 0 ferror'input()

if '% @0 err&*al(

/

printf'.4n rror in reading file..()

6

else

/

printf'.4n 3" reached..()

6

breaC)

6

if 'emp.emp&id 00 id&search(

/

display'9emp()

breaC)

6

6

6

else if '; 00 ch(

/

printf'.4n nter the record number to search 7 .()

scanf'.8d.-9rec&search()

2hile'!(

/

ret&*al 0 fread'9emp-siOeof' mployee(-!-input()

<<printf'.4nfread returns 7 8d.-ret&*al()

if '% 00 ret&*al(

/

err&*al 0 ferror'input()

if '% @0 err&*al(

/

printf'.4n rror in reading file..()

6

else

/

printf'.4n 3" reached..()

6

breaC)

6

if 'emp.rec&no 00 rec&search(

/

display'9emp()

breaC)

6

6

6

else

/

printf'.4n 1iting..()

breaC)

6

62hile'ch@0=()

ret&*al0fclose'input()

if '% @0 ret&*al(

/

printf'.4n rror in closing file..()

return %)

6

for 'i0%)i<num)i>>(

/

free'emp&arrayMiN.name()

emp&arrayMiN.name 0 JU##)

free'emp&arrayMiN.department()

emp&arrayMiN.department 0 JU##)

free'emp&arrayMiN.phonenumber()

emp&arrayMiN.phonenumber 0 JU##)

6

return %)

6

 

func.c

#include .header.h.

*oid insert' mployee ,e(

/

char emp&nameM:%N-emp&deptM:%N-emp&noM:%N)

int len&name-len&dept-len&no)

memset'emp&name-%-:%()

memset'emp&no-%-:%()

memset'emp&dept-%-:%()

char ,fgets&ret 0 JU##)

<< e->phonenumber 0 %)

printf'.4n nter the +K number of mployee 7 .()

scanf'.8d.-9'e->emp&id(()

printf'.4n nter the phone number of the mployee 7 .()

scanf'.8s.-emp&no()

<<printf'.pn 7 8ld.-e->phonenumber()

printf'.4n nter the name of the mployee 7 .()

scanf'.8s.-emp&name()

len&no0strlen'emp&no()

<,fgets&ret 0 fgets'emp&name-!E-stdin()

if'JU## 00 fgets&ret(

/

printf'.fgets failed4n.()

6,<

len&name0strlen'emp&name()

printf'.4n nter the name of the Kepartment 7 .()

scanf'.8s.-emp&dept()

<,fgets&ret 0 fgets'emp&dept-!E-stdin()

if'JU## 00 fgets&ret(

/

printf'.fgets failed4n.()

6,<

len&dept0strlen'emp&dept()

e->name 0 'char ,(malloc'len&name , siOeof'char(()

if'JU## 00 e->name(

/

printf'.4nGalloc "ailure..()

6

e->department 0 'char ,(malloc'len&dept , siOeof'char(()

if'JU## 00 e->department(

/

printf'.4nGalloc "ailure..()

6

e->phonenumber 0 'char ,(malloc'len&no , siOeof'char(()

if'JU## 00 e->phonenumber(

/

printf'.4nGalloc "ailure..()

6

memset'e->name-%-len&name()

strncpy'e->name-emp&name-len&name()

memset'e->department-%-len&dept()

strncpy'e->department-emp&dept-len&dept()

memset'e->phonenumber-%-len&no()

strncpy'e->phonenumber-emp&no-len&no()

6

*oid display' mployee ,e(

/

printf'.4nRecord number 7 8d.-e->rec&no()

printf'.4n mployee +K 7 8d.-e->emp&id()

printf'.4n mployee name 7 8s.-e->name()

printf'.4n mployee department 7 8s.-e->department()

printf'.4n mpoyee phonenumber 7 8s4n.-e->phonenumber()

6

FUNC_POINTERS

prototype.h

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

char 2ordsM:HNM:HN)

int compare'char ,-char ,()

*oid sort'int-int ',('char ,-char ,(()

main.c

#include.prototype.h.

int main'(

/

int n-i)

int ',ptr&comp('char ,-char ,(0JU##)

printf'.4n nter the number of strings you 2ant to sort 7 .()

scanf'.8d.-9n()

printf'.4n nter 8d number of strings 7 4n.-n()

for'i0%)i<n)i>>(

/

scanf'.8s.-2ordsMiN()

6

ptr&comp0compare)

sort'n-compare()

return %)

6

func.c

#include.prototype.h.

int compare'char ,first-char ,second(

/

return'strcmp'first-second(()

6

*oid sort'int num-int ',fptr('char ,-char ,((

/

char tempM:HN)

memset'temp-%-:H()

int i-Q-r-inde1)

for'i0%)i<num)i>>(

/

inde10i)

for'Q0i>!)Q<num)Q>>(

/

r0strcmp'2ordsMinde1N-2ordsMQN()

if'r>%(

/

inde10Q)

6

6

strcpy'temp-2ordsMinde1N()

strcpy'2ordsMinde1N-2ordsMiN()

strcpy'2ordsMiN-temp()

6

printf'.4nThe names in ascending order 7 .()

for'i0%)i<num)i>>(

/

printf'.4n8s.-2ordsMiN()

6

printf'.4n.()

6

LOAN

prototype.h

#include<stdio.h>

#include<math.h>

float monthlypayment'float-float-float()

*oid displaybalance'float-float-int()

main.c

#include .prototype.h.

int main'(

/

float p-r)

int y)

printf'.4n nter the principal amount 7 .()

scanf'.8f.-9p()

printf'.4n nter the rate of interest per annum 7 .()

scanf'.8f.-9r()

printf'.4n nter the number of years 7 .()

scanf'.8d.-9y()

displaybalance'p-r-y()

return %)

6

monthlypayment.c

#include .prototype.h.

float monthlypayment'float a-float i-float R(

/

return'a,i,R()

6

display.c

#include .prototype.h.

*oid displaybalance'float p-float r-int t(

/

int m-i)

float rm-R-mp-ip-pp-pr)

m0t,!:)

rm0''r<!:(<!%%()

pr0po2''!>rm(-m()

R0'pr<'pr-!(()

mp0monthlypayment'p-rm-R()

printf'.4nAmount of the loan 7 8f.-p()

printf'.4n+nterest per year 7 8f8.-r()

printf'.4n+nterest per month 7 8f8.-rm()

printf'.4nJumber of years 7 8d.-t()

printf'.4nJumber of months 7 8d4n.-m()

printf'.4nG3JTS4t3#K TA#AJC 4tG3JTS#U VAUG JT4t+JT R $T VA+K4tVR+JC+VA# VA+K4tJ L TA#AJC .()

for 'i0!)i<0m)i>>(

/

printf'.4n8d4t.-i()

printf'.8f4t.-p()

printf'.8f4t.-mp()

ip0'p,rm()

printf'.8f4t.-ip()

pp0mp-ip)

printf'.8f4t.-pp()

p0p-pp)

printf'.8f4t.-p()

6

6

MAGIC

prototype.h

#include<stdio.h>

#define GAP !%

*oid get&input'int-int()

int checC&sRuare&matri1'int-int()

*oid display&matri1'int-int()

*oid is&magic&sRuare'int-int()

int aMGAPNMGAPN)

 

main.c

#include .prototype.h.

int main'(

/

int c-r-flag)

flag0%)

do

/

printf'.4n nter ro2 siOe of the matri1 lesser than 8d 7 .-GAP()

scanf'.8d.-9r()

printf'.4n nter the column siOe of the matri1 lesser than 8d 7 .-GAP()

scanf'.8d.-9c()

if'!00checC&sRuare&matri1'c-r((

flag0!)

else

printf'.4nJot a sRuare matri1. nter again..()

62hile'flag00%()

get&input'c-r()

display&matri1'c-r()

is&magic&sRuare'c-r()

return %)

6

func.c

#include .prototype.h.

int checC&sRuare&matri1'int m-int n(

/

if'm00n(

return !)

else

return %)

6

*oid get&input'int m-int n(

/

int i-Q)

printf'.4n nter the elements into the matri1 7 4n.()

for'i0%)i<m)i>>(

/

for'Q0%)Q<n)Q>>(

scanf'.8d.-9aMiNMQN()

6

6

*oid display&matri1'int m-int n(

/

int i-Q)

for'i0%)i<m)i>>(

/

printf'.4n.()

for'Q0%)Q<n)Q>>(

printf'.8d4t.-aMiNMQN()

6

6

*oid is&magic&sRuare'int m-int n(

/

int i-Q-sum&diag&l-sum&diag&r-sum&ro2-sum&col-flag)

sum&diag&l0%)

for'i0%)i<m)i>>(

/

for'Q0%)Q<n)Q>>(

/

if'i00Q(

sum&diag&l>0aMiNMQN)

6

6

sum&diag&r0%)

for'i0%)i<m)i>>(

/

for'Q0%)Q<n)Q>>(

/

if''i>Q(00'n-!((

sum&diag&r>0aMiNMQN)

6

6

if 'sum&diag&l00sum&diag&l(

flag0!)

else

flag0%)

for'i0%)i<m)i>>(

/

sum&ro20%)

for'Q0%)Q<n)Q>>(

sum&ro2>0aMiNMQN)

if'sum&ro200sum&diag&l(

flag0!)

else

/

flag0%)

breaC)

6

6

for'i0%)i<m)i>>(

/

sum&col0%)

for'Q0%)Q<n)Q>>(

sum&col>0aMQNMiN)

if'sum&col00sum&diag&l(

flag0!)

else

/

flag0%)

breaC)

6

6

if'flag00!(

printf'.4nThe gi*en matri1 is a GAG+C $WUAR ..()

else

printf'.4nThe gi*en matri1 is not a GAG+C $WUAR ..()

6

MORSE CODE

prototype.h

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define GAP :I

*oid encode'char ,()

*oid decode'char ,()

list.h

char ,morseMGAPNM:N0//.a.-..-.6-

/.b.-.-....6-

/.c.-.-.-..6-

/.d.-.-...6-

/.e.-...6-

/.f.-...-..6-

/.g.-.--..6-

/.h.-......6-

/.i.-....6-

/.Q.-..---.6-

/.C.-.-.-.6-

/.l.-..-...6-

/.m.-.--.6-

/.n.-.-..6-

/.o.-.---.6-

/.p.-..--..6-

/.R.-.--.-.6-

/.r.-..-..6-

/.s.-.....6-

/.t.-.-.6-

/.u.-...-.6-

/.*.-....-.6-

/.2.-..--.6-

/.1.-.-..-.6-

/.y.-.-.--.6-

/.O.-.--...66)

 

main.c

#include .prototype.h.

int main'(

/

char inputM:%N-codeM=%N)

memset'input-%-:%()

memset'code-%-=%()

int ch-l)

do

/

printf'.4n nter your choice 74n nter ! for ncoding.4n nter : for Kecoding.4n nter ; for 1it.4n.()

scanf'.8d.-9ch()

if'ch00!(

/

printf'.4n nter a string for encoding7 .()

scanf'.8s.-input()

l0strlen'input()

if'54n500inputMl-!N(

/

inputMl-!N054%5)

6

encode'input()

6

else if'ch00:(

/

printf'.4n nter a string for decoding 7 .()

scanf'.8s.-code()

l0strlen'code()

if'54n500codeMl-!N(

/

codeMl-!N054%5)

6

decode'code()

6

else if'ch00;(

/

printf'.4n 1iting..()

6

62hile'ch@0;()

return %)

6

func.c

#include .prototype.h.

#include .list.h.

*oid encode'char ,string(

/

int i-l-Q)

l0strlen'string()

char codeMH%N)

memset'code-%-H%()

for'i0%)i<l)i>>(

/

for'Q0%)Q<:I)Q>>(

/

if'stringMiN 00 ,morseMQNM%N(

/

strcat'code-morseMQNM!N()

strcat'code-.X.()

6

6

6

printf'.4nThe encoded string for 8s is 7 8s.-string-code()

6

*oid decode'char ,c(

/

int i-l-Q)

Q0%)

l0strlen'c()

char stringM:%N)

memset'string-%-:%()

char ,2ordM!%N)

memset'2ord-%-!%()

char delimMN0.X.)

2ordMQN0strtoC'c-delim()

printf'.4ns 7 8s.-2ordMQN()

2hile'JU## @0 2ordMQN(

/

for'i0%)i<GAP)i>>(

/

if'%00strcmp'2ordMQN-morseMiNM!N((

/

strcat'string-morseMiNM%N()

6

6

Q>>)

2ordMQN0strtoC'JU##-delim()

6

printf'.4nThe decoded string is 7 8s.-string()

6

POINTERS

prototype.h

#include<stdio.h>

*oid day&modified'int-int-int()

int inde1'char ,()

main.c

#include .prototype.h.

int main'(

/

int d-m-y)

printf'.4n nter the year 7 .()

scanf'.8d.-9y()

printf'.4n nter the month 7 .()

scanf'.8d.-9m()

printf'.4n nter the day 7 .()

scanf'.8d.-9d()

day&modified'y-m-d()

return %)

6

day&modified.c

#include .prototype.h.

*oid day&modified'int y-int m-int day(

/

int G3JTSM!:N0/;!-:F-;!-;%-;!-;%-;!-;!-;%-;!-;%-;!6)

char, KAUMFN0/.Gonday.-.Tuesday.-.Lednesday.-.Thursday.-."riday.-.$aturday.-.$unday.6)

int countM?N0/%-%-%-%-%-%-%6)

int i-d-n-c-num-cnum-R-inde1!-inde1:-diff)

d0%)

if''y8=00% 99 y8!%%@0%( AA 'y8=%%00%((

/

G3JTSM!N0:E)

<<printf'.4n8d.-G3JTSM!N()

6

for 'i0:%%!)i<y)i>>(

/

if''i8=00% 99 i8!%%@0%( AA 'i8=%%00%((

d>0;II)

else

d>0;IH)

6

num0d)

printf'.4nThe day of the begining of the year is 7 8s.-KAUMd8?N()

inde1!0inde1'KAUMd8?N()

for 'i0%)i<m-!)i>>(

d>0G3JTSMiN)

d>0'day-!()

cnum0d)

inde1:0inde1'KAUMd8?N()

printf'.4nThe gi*en date is a 7 8s4n.-KAUMd8?N()

diff0cnum-num)

c0diff-'?-inde1!()

for'i0inde1!)i<?)i>>(

countMiN>0!)

R0'int(c<?)

for'i0%)i<?)i>>(

countMiN>0R)

for'i0%)i<0inde1:)i>>(

countMiN>0!)

for'i0%)i<?)i>>(

/

printf'.4nThe number of 8ss is 7 8d.-KAUMiN-countMiN()

6

6

int inde1'char ,s(

/

if's00.Gonday.(

return %)

else if's00.Tuesday.(

return !)

else if's00.Lednesday.(

return :)

else if's00.Thursday.(

return ;)

else if's00."riday.(

return =)

else if's00.$aturday.(

return H)

else if's00.$unday.(

return I)

6

  PIGLATIN

prototype.h

#inc !"e#$t"io.h%

#inc !"e#$trin&.h%

ch'r inp!t()*+,

ch'r pi&(-*+,

ch'r o!tp!t(-*+,

int i$_.o/e 0ch'r 12,

.oi" &et_/or"02,

int pi& 'tin0ch'r 1 3int2,

4'in.c

#inc !"e5prototype.h5

int 4'in02

6

int en73 en8,

4e4$et0inp!t3*3)*2,

4e4$et0pi&3*3-*2,

4e4$et0o!tp!t3*3-*2,

print905:nEnter 'n inp!t $trin& ; 52,

9&et$0inp!t38<3$t"in2,

en7=$tr en0inp!t2,

i90>:n>==inp!t( en7?7+2

inp!t( en7?7+=>:*>,

print905:nEnter 'nother inp!t $trin& ; 52,

9&et$0pi&3)<3$t"in2,

en8=$tr en0pi&2,

i90>:n>==pi&( en8?7+2

pi&( en8?7+=>:*>,

&et_/or"02,

ret!rn *,

@

9!nc.c

#inc !"e5prototype.h5

ch'r .o/e (+=6>'>3>e>3>i>3>o>3>!>3>A>3>E>3>I>3>O>3>U>@,

int i$_.o/e 0ch'r 1n'4e2

6

int i,

9or0i=*,i#7*,iAA2

6

i90n'4e(*+==.o/e (i+2

ret!rn 7,

@

ret!rn *,

@

int pi& 'tin0ch'r 1n'4e3int B2

6

int i3C,

int =$tr en0n'4e2,

i90*==i$_.o/e 0n'4e22

6

9or0i=7,i# ,iAA2

6

o!tp!t(B+=n'4e(i+,

BAA,

@

o!tp!t(B+=n'4e(*+,

$trc't0o!tp!t35'y 52,

BA=-,

ret!rn B,

@

i907==i$_.o/e 0n'4e22

6

9or0i=*,i# ,iAA2

6

o!tp!t(B+=n'4e(i+,

BAA,

@

$trc't0o!tp!t35'y 52,

BA=),

ret!rn B,,

@

@

.oi" &et_/or"02

6

int i3B3 3 en,

B=*,

=*,

ch'r 1/or"(D*+,

ch'r "e i4(+=5 5,

/or"(B+=$trtoC0inp!t3"e i42,

/hi e0NULL E= /or"(B+2

6

=pi& 'tin0/or"(B+3 2,

BAA,

/or"(B+=$trtoC0NULL3"e i42,

@

en=$tr en0o!tp!t2,

o!tp!t( en?7+=>:*>,

print905:nF$53o!tp!t2,

i90$trc4p0o!tp!t3pi&2==*2

print905:nThe $econ" $trin& i$ the pi& 'tin o9 the 9ir$t $trin&.52,

e $e

print905:nThe $econ" $trin& i$ not the pi& 'tin o9 the 9ir$t $trin&.52,

@

  STRUCTURES

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "+# JAG 7 name&det&header.h

,

, K $CR+VT+3J 7 Contains header files- function prototypes and user

, defined *ariables for name details program

,

, KAT JAG R " R JC R A$3J

,

, !-BUJ-!% $ibu VR+$G-; C "G +nitial Creation.

,

, Copyright :%!%- Aricent Technologies 'Soldings( #td

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

<, A*oiding multiple inclusions of header file ,<

#ifndef JAG &K T&&S AK R&S

#define JAG &K T&S AK R&S

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, S AK R "+# $

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, GACR3$

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

#define GAP ;:

#define name&ret int

#define "A+#UR %

#define $UCC $$ !

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, U$ R K "+J K TUV $

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

typedef struct

/

char ,first&name)

char ,second&name)

6person&name&et)

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, "UCJT+3J VR3T3TUV $

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

e1tern name&ret update&person'person&name&et ,,- char ,- char ,()

e1tern name&ret display&person'person&name&et ,,- int()

e1tern name&ret free&person'person&name&et ,,()

#endif

 

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "+# JAG 7 name&det&main.c

,

, K $CR+VT+3J 7 Vrogram for storing first name and second name for

, a set of persons.

,

, KAT JAG R " R JC R A$3J

,

, !-BUJ-!% $ibu VR+$G-; C "G +nitial Creation.

,

, Copyright :%!%- Aricent Technologies 'Soldings( #td

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, S AK R "+# $

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

#include .name&det&header.h.

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, #3CA# GACR3$

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

#define $+Y !%

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "unction Jame 7 main

, Kescription 7 Accepts a first name and second name of a ma1 of !%

, persons and stores it in an array of structure.

, Returns 7 $uccess or "ailure

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

int main'(

/

char f&nameMGAPN- s&nameMGAPN-inputMGAPN)

person&name&et ,ptr&person)

name&ret ret&*al 0 $UCC $$)

char ,fgets&ret 0 JU##)

int person&inde1 0 %)

memset'f&name-%-GAP()

memset's&name-%-GAP()

2hile'person&inde1 < $+Y (

/

printf'.Ko you 2ant to continue. 5Ruit5 to terminate4n.()

fgets&ret 0 fgets'input-GAP-stdin()

if'JU## 00 fgets&ret(

/

printf'.fgets failed4n.()

ret&*al 0 "A+#UR )

breaC)

6

if'strncmp'input-.Ruit.-=( 00 %(

/

ret&*al 0 $UCC $$)

breaC)

6

else

/

printf'. nter the first name - ma1imum ;! characters4n.()

fgets&ret 0 fgets'f&name- GAP- stdin()

if'JU## 00 fgets&ret(

/

printf'.fgets failed4n.()

ret&*al 0 "A+#UR )

breaC)

6

printf'. nter the second name - ma1imum ;! characters4n.()

fgets&ret 0 fgets's&name- GAP- stdin()

if'JU## 00 fgets&ret(

/

printf'.fgets failed4n.()

ret&*al 0 "A+#UR )

breaC)

6

ret&*al 0 update&person'9ptr&person-f&name-s&name()

if'"A+#UR 00 ret&*al(

/

printf'.update&person -failed4n.()

breaC)

6

6

if'"A+#UR 00 ret&*al(

/

printf'.Updating Ketails - "ailure4n.()

printf'.Kisplaying current output4n.()

6

else

/

printf'.Updating Ketails - $uccess4n.()

printf'.Kisplaying current output4n.()

6

ret&*al 0 display&person'9ptr&person-person&inde1()

if'"A+#UR 00 ret&*al(

/

printf'.Kisplay failed4n.()

free&person'9ptr&person()

6

else

/

printf'.4nKisplaing Ketails - $uccess.()

free&person'9ptr&person()

6

person&inde1 >0 !)

6<,end of 2hile,<

return %)

6

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "+# JAG 7 string&functions.c

,

, K $CR+VT+3J 7 "unctions for storing name details of persons

,

, KAT JAG R " R JC R A$3J

,

, !-BUJ-!% $ibu VR+$G-; C "G +nitial Creation.

,

, Copyright :%!%- Aricent Technologies 'Soldings( #td

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, S AK R "+# $

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

#include .name&det&header.h.

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, #3CA# "UJCT+3J$

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

static name&ret remo*e&ne2line'char ,()

static name&ret allocate&person'person&name&et ,,- int- int()

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "unction Jame 7 remo*e&ne2line

, Kescription 7 Remo*es 4n- if any- from the array

, Returns 7 $uccess or "ailure

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

static name&ret remo*e&ne2line'

char ,arg&input <, input string ,<

(

/

if'JU## 00 arg&input( <, rror handling for argument ,<

/

return "A+#UR )

6

<, "inds out the length of the string ,<

int str&len 0 strlen'arg&input()

<, ChecCs 2hether a 54n5 is appended at the end ,<

if'54n5 00 arg&inputMstr&len - !N(

/

arg&inputMstr&len - !N 0 54%5) <, Replaces 54n5 2ith 54%5 ,<

6

return $UCC $$)

6

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "unction Jame 7 allocate&person

, Kescription 7 Allocates memory for structure and elements

, Returns 7 $uccess or "ailure

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

static name&ret allocate&person'

person&name&et ,,person- <, ptr to person ,<

int len&first- <, #ength of first name ,<

int len&second <, #ength of second name ,<

(

/

,person 0 'person&name&et ,(malloc'siOeof'person&name&et(()

if'JU## 00 person(

/

printf'.Galloc failure4n.()

return "A+#UR )

6

',person(->first&name 0 'char ,(malloc'len&first , siOeof'char(()

if'JU## 00 ',person(->first&name(

/

printf'.Galloc failure4n.()

return "A+#UR )

6

',person(->second&name 0 'char ,(malloc'len&second , siOeof'char(()

if'JU## 00 ',person(->second&name(

/

printf'.Galloc failure4n.()

return "A+#UR )

6

return $UCC $$)

6

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "unction Jame 7 update&person

, Kescription 7 Copies the !st 9 :nd name to each array element

, Returns 7 $uccess or "ailure

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

name&ret update&person'

person&name&et ,,person- <, Vtr to structure ,<

char ,first&arg- <, "irst name ,<

char ,second&arg <, $econd name ,<

(

/

name&ret ret&*al0$UCC $$)

int first&len-second&len)

ret&*al0remo*e&ne2line'first&arg()

if '"A+#UR 00 ret&*al(

/

printf'.4nJe2 line Remo*al "ailure for first name..()

return "A+#UR )

6

first&len0strlen'first&arg()

ret&*al0remo*e&ne2line'second&arg()

if '"A+#UR 00 ret&*al(

/

printf'.4nJe2 line Remo*al "ailure for second name..()

return "A+#UR )

6

second&len0strlen'second&arg()

ret&*al0allocate&person'person-first&len-second&len()

if '"A+#UR 00 ret&*al(

/

printf'.4nGemory Allocation "ailure..()

return "A+#UR )

6

else

/

memset'',person(->first&name-%-first&len()

strncpy'',person(->first&name-first&arg-first&len()

memset'',person(->second&name-%-second&len()

strncpy'',person(->second&name-second&arg-second&len()

6

return $UCC $$)

6

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "unction Jame 7 display&person

, Kescription 7 Kispay the contents of the person array

, Returns 7 $uccess or "ailure

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

name&ret display&person'

person&name&et ,,person- <, Array of persons ,<

int inde1 <, Total number of persons ,<

(

/

printf'.person - 8d4t.- inde1 > !()

printf'."irst Jame - 8s4t.- ',person(->first&name()

printf'.$econd Jame - 8s4n.- ',person(->second&name()

return $UCC $$)

6

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "unction Jame 7 free&person

, Kescription 7 Keallocates memory allocated for person array

, Returns 7 $uccess or "ailure

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

name&ret free&person'

person&name&et ,,person <, Array of persons ,<

(

/

',person(->first&name0JU##)

free'',person(->first&name()

',person(->second&name0JU##)

free'',person(->second&name()

',person(0JU##)

free'',person(()

return $UCC $$)

6

  USER_DEFINED

header.h

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

typedef struct

/

int area)

int population)

char ,name)

char ,country)

char ,airport)

char ,type)

6place)

typedef enum

/

"A+#UR -

$UCC $$

6type&ret)

e1tern type&ret update&information'place ,,- int()

e1tern type&ret display&information'place ,,- int()

e1tern *oid free&place'place ,,-int()

main.c

#include .header.h.

#define GAP H

int main'(

/

place ,place&ptr)

type&ret ret&*al 0 $UCC $$)

char ch)

int i-inde1-place&category)

inde10%)

printf'.4n nter the details of 8d places 7 .-GAP()

2hile'inde1<GAP(

/

printf'.4n nter R to Ruit . .()

scanf'. 8c.-9ch()

if 'ch 00 5R5(

/

printf'.4n 1iting..()

breaC)

6

else

/

printf'.4nVlace 7 8d.-'inde1>!(()

printf'.4n+s it a metropolitan city or a tourist destination D 4n nter ! for Getropolitan City and : for Tourist Kestination 7 .()

scanf'.8d.-9place&category()

ret&*al0update&information'9place&ptr-place&category()

if 'ret&*al 00 "A+#UR (

/

printf'.4nUpdate +nformation "ailed.4nTry Again..()

breaC)

6

else

/

printf'.4nUpdate $uccessful..()

6

ret&*al0display&information'9place&ptr-place&category()

if 'ret&*al 00 "A+#UR (

/

printf'.4nKisplaying +nformation "ailed.4nTry Again..()

free&place'9place&ptr-place&category()

breaC)

6

else

/

printf'.4nKisplaying +nformation $uccessful4n.()

free&place'9place&ptr-place&category()

6

inde1 >0 !)

6

6

return %)

6

func.c

#include.header.h.

#define GAP$+Y :%

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

, #3CA# "UJCT+3J$

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

static *oid remo*e&ne2line'char ,()

static *oid allocate 'place ,,-int-int-int-int-int()

<,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

,

, "unction Jame 7 remo*e&ne2line

, Kescription 7 Remo*es 4n- if any- from the array

, Returns 7 $uccess or "ailure

,

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,<

static *oid remo*e&ne2line'

char ,arg&input <, input string ,<

(

/

if'JU## 00 arg&input(

/

printf'.4n rror.()

6

else

/

<, "inds out the length of the string ,<

int str&len 0 strlen'arg&input()

<, ChecCs 2hether a 54n5 is appended at the end ,<

if'54n5 00 arg&inputMstr&len - !N(

/

arg&inputMstr&len - !N 0 54%5) <, Replaces 54n5 2ith 54%5 ,<

6

6

6

static *oid allocate'place ,,placeobQ-int len&name-int len&country-int len&type-int len&airport-int category(

/

,placeobQ 0 'place ,(malloc'siOeof'place(()

if'JU## 00 placeobQ(

/

printf'.Galloc failure4n.()

6

',placeobQ(->name 0 'char ,(malloc'len&name , siOeof'char(()

if'JU## 00 ',placeobQ(->name(

/

printf'.Galloc failure4n.()

6

',placeobQ(->country 0 'char ,(malloc'len&country , siOeof'char(()

if'JU## 00 ',placeobQ(->country(

/

printf'.Galloc failure4n.()

6

if 'category 00 :(

/

',placeobQ(->type 0 'char ,(malloc'len&type , siOeof'char(()

if'JU## 00 ',placeobQ(->type(

/

printf'.Galloc failure4n.()

6

',placeobQ(->airport 0 'char ,(malloc'len&airport , siOeof'char(()

if'JU## 00 ',placeobQ(->airport(

/

printf'.Galloc failure4n.()

6

6

6

type&ret update&information'place ,,placeobQ-int category(

/

char city&nameM:%N-city&countryM:%N-city&airportM:%N-city&typeM:%N)

memset'city&name-%-:%()

memset'city&country-%-:%()

memset'city&airport-%-:%()

memset'city&type-%-:%()

int len&name-len&country-len&airport-len&type-city&area-city&population)

char ,fgets&ret 0 JU##)

printf'.4n nter the name of the city 7 .()

scanf'.8s.-city&name()

remo*e&ne2line'city&name()

len&name0strlen'city&name()

<,',placeobQ(->name 0 'char ,(malloc'len , siOeof'char(()

if'JU## 00 ',placeobQ(->name(

/

printf'.Galloc failure4n.()

return "A+#UR )

6,<

printf'.4n nter the name of the country 7 .()

scanf'.8s.-city&country()

remo*e&ne2line'city&country()

len&country0strlen'city&country()

<<'placeobQ(->country 0 'char ,(malloc'len , siOeof'char(()

if 'category 00 !(

/

printf'.4nGetropolitan City 7 .()

printf'.4n nter the area 7 .()

scanf'.8d.-9city&area()

<<',place&obQ(->population 0 'int ,(malloc'siOeof'int(()

printf'.4n nter the population 7 .()

scanf'.8d.-9city&population()

allocate'placeobQ-len&name-len&country-%-%-category()

',placeobQ(->area0city&area)

',placeobQ(->population0city&population)

6

else

/

printf'.4nTourist Kestination 7 .()

printf'.4n nter the type of city 7 .()

scanf'.8s.-city&type()

<,if'JU## 00 fgets&ret(

/

printf'.fgets failed4n.()

6,<

remo*e&ne2line'city&type()

len&type0strlen'city&type()

<<',placeobQ(->type 0 'char ,(malloc'len , siOeof'char(()

printf'.4n nter the name of nearest airport 7 .()

scanf'.8s.-city&airport()

<<fgets&ret 0 fgets'city&airport- :%- stdin()

<,if'JU## 00 fgets&ret(

/

printf'.fgets failed4n.()

6,<

remo*e&ne2line'city&airport()

len&airport0strlen'city&airport()

allocate'placeobQ-len&name-len&country-len&type-len&airport-category()

<<',placeobQ(->airport 0 'char ,(malloc'len , siOeof'char(()

6

memset'',placeobQ(->name-%-len&name()

strncpy'',placeobQ(->name-city&name-len&name()

memset'',placeobQ(->country-%-len&country()

strncpy'',placeobQ(->country-city&country-len&country()

if 'category 00 :(

/

memset'',placeobQ(->type-%-len&type()

strncpy'',placeobQ(->type-city&type-len&type()

memset'',placeobQ(->airport-%-len&airport()

strncpy'',placeobQ(->airport-city&airport-len&airport()

6

return $UCC $$)

6

type&ret display&information'place ,,place&obQ-int category(

/

if 'JU## 00 place&obQ(

/

printf'.4n rror.()

return "A+#UR )

6

printf'.4nJame 7 8s.-',place&obQ(->name()

printf'.4nCountry 7 8s.-',place&obQ(->country()

if 'category 00 !(

/

printf'.4nGetrolopolitan City..()

printf'.4nArea 7 8d.-',place&obQ(->area()

printf'.4nVopulation 7 8d.-',place&obQ(->population()

6

else

/

printf'.4nTourist Kestination..()

printf'.4nType 7 8s.-',place&obQ(->type()

printf'.4nJearest Airport 7 8s.-',place&obQ(->airport()

6

return $UCC $$)

6

*oid free&place'place ,,place&obQ-int category(

/

',place&obQ(->name 0 JU##)

free'',place&obQ(->name()

',place&obQ(->country 0 JU##)

free'',place&obQ(->country()

if 'category 00 :(

/

',place&obQ(->type 0 JU##)

free'',place&obQ(->type()

',place&obQ(->airport 0 JU##)

free'',place&obQ(->airport()

6

free',place&obQ()

6

GARIABLE ARGUMENT

header.h

#include<stdio.h>

#include<string.h>

#include<stdarg.h>

*oid concat&str'char ,-...()

 

main.c

#include.header.h.

int main'(

/

concat&str'.git.-.anQali.-.Ruit.()

concat&str'.git.-.anQali.-. singh.-.Ruit.()

concat&str'.git.-.anQali.-. singh.-. Aricent.-.Ruit.()

return %)

6

func.c

#include.header.h.

*oid concat&str'char ,str-...(

/

char ,output-,temp)

int len-len!)

*a&list *)

*a&start'*-str()

len0strlen'str()

output0'char ,(malloc''len>!( , siOeof'char(()

if 'JU## 00 output(

/

printf'.4nGemory allocation failure..()

6

memset'output-%-len()

strncpy'output-str-len()

2hile'% @0 strncmp'str-.Ruit.-=((

/

str 0 *a&arg'*-char ,()

if'% 00 strncmp'str-.Ruit.-=((

/

breaC)

6

len! 0 strlen'str()

len >0 len!)

temp0'char ,(realloc'output-''len>!( , siOeof'char((()

if 'JU## @0 temp(

/

output0temp)

6

strncat'output-str-len!()

6

printf'.4nThe concatenated string is 7 8s4n.-output()

free'temp()

temp 0 JU##)

<<free'output()

output 0 JU##)

6

SINGLE LINHED LIST

header.h

#include<stdio.h>

#include<stdlib.h>

struct node

/

int data)

struct node ,ne1t)

6)

typedef struct node node)

e1tern node, createnode'()

e1tern *oid insertion'node ,,-int()

e1tern *oid deletion'node ,,-int()

e1tern *oid display'node ,()

e1tern *oid free&node'node ,()

main.c

#include .header.h.

int main'(

/

int ch-ch&ins-ch&del-flag)

flag0%)

node ,head 0 JU##)

do

/

printf'.4n nter your choice.4n nter ! for insertion.4n nter : for deletion.4n nter ; for display.4n nter = to e1it 7 .()

scanf'.8d.-9ch()

s2itch'ch(

/

case ! 7 printf'.4n nter ! to insert at the end -: to insert at the begining and ; to insert after a node 7 .()

scanf'.8d.-9ch&ins()

insertion'9head-ch&ins()

breaC)

case : 7 printf'.4n nter ! to delete at the begining-: to delete at the end and ; to delete a particular node 7 .()

scanf'.8d.-9ch&del()

deletion'9head-ch&del()

breaC)

case ; 7 display'head()

breaC)

case = 7 free&node'head()

printf'.4n 1iting.()

flag0!)

breaC)

6

62hile'flag00%()

return %)

6

func.c

#include .header.h.

node, createnode'(

/

int *al)

node ,ne2node)

ne2node0'node ,(malloc'siOeof'node(()

if'JU## 00 ne2node(

/

printf'.4nGalloc "ailure..()

e1it'%()

6

printf'.4n nter a *alue in the node 7 .()

scanf'.8d.-9*al()

ne2node->data 0 *al)

ne2node->ne1t 0 JU##)

return ne2node)

6

*oid insertion'node ,,head-int ch(

/

node ,ne2node-,temp-,ins)

temp 0 ,head)

int *al)

ne2node 0 createnode'()

if 'JU## 00 ne2node(

/

printf'.4nJode not created..()

6

if 'JU## 00 ,head(

/

,head0ne2node)

6

else if'JU## 00 ',head(->ne1t(

/

',head(->ne1t0ne2node)

6

else

/

if'! 00 ch(

/

2hile'JU## @0 temp->ne1t(

/

temp0temp->ne1t)

6

temp->ne1t0ne2node)

6

else if ': 00 ch(

/

ne2node->ne1t 0 ,head)

,head 0 ne2node)

6

else

/

printf'.4n nter the *alue of the node after 2hich you 2ould liCe to insert a ne2 node 7 .()

scanf'.8d.-9*al()

2hile'temp->data @0 *al 99 JU## @0 temp->ne1t(

/

temp0temp->ne1t)

6

ins0temp->ne1t)

temp->ne1t0ne2node)

ne2node->ne1t0ins)

6

6

6

*oid deletion'node ,,head-int ch(

/

node ,ne2node-,temp-,del)

temp 0 ,head)

int *al)

if 'JU## 00 ,head(

/

printf'.4nThe list is empty..()

6

else if 'JU## 00 ',head(->ne1t(

/

printf'.4nThe head node containing the *alue 8d is deleted..-',head(->data()

free',head()

',head( 0 JU##)

6

else

/

if '! 00 ch(

/

printf'.4nThe head node containing the *alue 8d is deleted..-',head(->data()

temp 0 ',head(->ne1t)

free',head()

,head 0 temp)

6

else if ': 00 ch(

/

2hile 'JU## @0 temp->ne1t->ne1t(

/

temp0temp->ne1t)

6

printf'.4nThe node containing the *alue 8d is deleted..-temp->ne1t->data()

free'temp->ne1t()

temp->ne1t0JU##)

6

else

/

printf'.4n nter the *alue of the node 2hich you 2ould liCe to delete 7 .()

scanf'.8d.-9*al()

2hile 'temp->ne1t->data @0 *al 99 JU## @0 temp->ne1t->ne1t(

/

temp0temp->ne1t)

6

del0temp->ne1t)

printf'.4nThe node containing the *alue 8d is deleted..-del->data()

temp->ne1t 0 temp->ne1t->ne1t)

free'del()

del 0 JU##)

6

6

6

*oid display'node ,head(

/

printf'.4nKisplaying nodes 7 4n.()

2hile'JU## @0 head->ne1t(

/

printf'.8d -> .-head->data()

head0head->ne1t)

6

printf'.8d.-head->data()

printf'.4n.()

6

*oid free&node'node ,head(

/

node ,temp)

temp 0 head)

2hile'JU## @0 head->ne1t(

/

temp 0 head->ne1t)

head->ne1t 0 head->ne1t->ne1t)

free'temp()

temp 0 JU##)

6

free'head()

head 0 JU##)

6

DOUBLE LINHED LIST

header.h

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

struct node

/

int emp&id)

char ,emp&name)

struct node ,ne1t)

struct node ,pre*)

6)

typedef struct node node)

node, createnode'()

*oid insert&at&begin'node ,,-node ,,()

*oid insert&at&end'node ,,-node ,,()

*oid insert&at&*alue'node ,,-node ,,-int()

*oid delete&at&begin'node ,,-node ,,()

*oid delete&at&end'node ,,-node ,,()

*oid delete&at&*alue'node ,,-node ,,-int()

*oid display'node ,()

*oid free&node'node ,()

main.c

#include .header.h.

int main'(

/

int ch-ch&ins-ch&del-flag-*al-*al!)

flag0%)

node ,head 0 JU##)

node ,tail 0 JU##)

do

/

printf'.4n nter your choice.4n nter ! for insertion.4n nter : for deletion.4n nter ; for display.4n nter = to e1it 7 .()

scanf'.8d.-9ch()

s2itch'ch(

/

case ! 7 printf'.4n nter ! to insert at the end -: to insert at begining and ; to insert after a node 7 .()

scanf'.8d.-9ch&ins()

if '! 00 ch&ins(

/

insert&at&end'9head-9tail()

6

else if ': 00 ch&ins(

/

insert&at&begin'9head-9tail()

6

else

/

printf'.4n nter the employee id after 2hich you 2ant to insert the ne2 node 7 .()

scanf'.8d.-9*al()

insert&at&*alue'9head-9tail-*al()

6

breaC)

case : 7 printf'.4n nter ! to delete at the end-: to delete at the begining and ; to delete a particular node 7 .()

scanf'.8d.-9ch&del()

if '! 00 ch&del(

/

delete&at&end'9head-9tail()

6

else if ': 00 ch&del(

/

delete&at&begin'9head-9tail()

6

else

/

printf'.4n nter the employee id after 2hich you 2ant to delete 7 .()

scanf'.8d.-9*al!()

delete&at&*alue'9head-9tail-*al!()

6

breaC)

case ; 7 display'head()

breaC)

case = 7 free&node'head()

printf'.4n 1iting4n.()

flag0!)

breaC)

6

62hile'flag00%()

return %)

6

func.c

#include .header.h.

#define GAP :%

node, createnode'(

/

node, ne2node)

char nameMGAPN)

int len 0 %)

<< char ,fgets&ret)

memset'name-%-GAP()

ne2node 0 'node ,(malloc'siOeof'node(()

if 'JU## 00 ne2node(

/

printf'.4nGalloc "ailure..()

6

ne2node->emp&id 0 %)

printf'.4n nter the employee id 7 .()

scanf'.8d.-9ne2node->emp&id()

printf'.4n nter the employee name 7 .()

scanf'.8s.-name()

<,fgets&ret 0 fgets'name-!E-stdin()

if 'JU## 00 fgets&ret(

/

printf'.4n"gets failure..()

6,<

len 0 strlen'name()

<,if '54n5 00 nameMlen-!N(

/

nameMlen-!N 0 54%5)

6,<

ne2node->emp&name 0 JU##)

ne2node->emp&name 0 'char ,(malloc''len>!( , siOeof'char(()

if 'JU## 00 ne2node->emp&name(

/

printf'.4nGalloc "ailure..()

6

memset'ne2node->emp&name-%-len()

strncpy'ne2node->emp&name-name-len()

ne2node->pre* 0 JU##)

ne2node->ne1t 0 JU##)

return ne2node)

6

*oid insert&at&end'node ,,head-node ,,tail(

/

node ,ne2node)

ne2node 0 createnode'()

if 'JU## 00 ,head(

/

,head0ne2node)

,tail0ne2node)

6

else

/

',tail(->ne1t 0 ne2node)

ne2node->pre* 0 ,tail)

,tail 0 ne2node)

6

6

*oid insert&at&begin'node ,,head-node ,,tail(

/

node ,ne2node)

ne2node 0 createnode'()

if 'JU## 00 ,head(

/

,head 0 ne2node)

,tail 0 ne2node)

6

else

/

',head(->pre* 0 ne2node)

ne2node->ne1t 0 ,head)

,head 0 ne2node)

6

6

*oid insert&at&*alue'node ,,head-node ,,tail-int *al(

/

node ,ne2node-,temp)

ne2node 0 createnode'()

if 'JU## 00 ,head(

/

,head 0 ne2node)

,tail 0 ne2node)

6

else

/

temp 0 ,head)

2hile '*al @0 temp->emp&id(

/

temp0temp->ne1t)

if 'JU## 00 temp(

/

printf'.4nThe *alue entered does not e1ist in the node..()

breaC)

6

6

ne2node->ne1t 0 temp->ne1t)

ne2node->pre* 0 temp)

temp->ne1t 0 ne2node)

ne2node->ne1t->pre* 0 ne2node)

6

6

*oid delete&at&end'node ,,head-node ,,tail(

/

node ,del)

if 'JU## 00 ,head(

/

printf'.4nThe list is empty..()

6

else

/

del 0 ,tail)

,tail 0 ',tail(->pre*)

',tail(->ne1t 0 JU##)

free'del->emp&name()

del->emp&name 0 JU##)

free'del()

del 0 JU##)

6

6

*oid delete&at&begin'node ,,head-node ,,tail(

/

node ,del)

if 'JU## 00 ,head(

/

printf'.4nThe list is empty..()

6

else

/

del 0 ,head)

,head 0 ',head(->ne1t)

',head(->pre* 0 JU##)

free'del->emp&name()

del->emp&name 0 JU##)

free'del()

del 0 JU##)

6

6

*oid delete&at&*alue'node ,,head-node ,,tail-int *al(

/

node ,del)

if 'JU## 00 ,head(

/

printf'.4nThe list is empty..()

6

else

/

del 0 ,head)

2hile'*al @0 del->emp&id(

/

del 0 del->ne1t)

if 'JU## 00 del(

/

printf'.4nThe *alue entered does not e1ist in the list..()

breaC)

6

6

del->pre*->ne1t 0 del->ne1t)

del->ne1t->pre* 0 del->pre*)

free'del->emp&name()

del->emp&name 0 JU##)

free'del()

del 0 JU##)

6

6

*oid display'node ,head(

/

if 'JU## 00 head(

/

printf'.4nThe list is empty..()

6

else

/

2hile 'JU## @0 head->ne1t(

/

printf'.8d.-head->emp&id()

printf'. 8s -> .-head->emp&name()

head 0 head->ne1t)

6

printf'.8d.-head->emp&id()

printf'. 8s4n.-head->emp&name()

6

6

*oid free&node'node ,head(

/

node, temp)

if 'JU## 00 head(

/

printf'.4nThe list is empty..()

6

2hile 'JU## @0 head->ne1t(

/

temp 0 head->ne1t)

if 'JU## 00 temp->ne1t(

/

free'temp->emp&name()

temp->emp&name 0 JU##)

free'temp()

temp 0 JU##)

head->ne1t 00 JU##)

breaC)

6

head->ne1t 0 head->ne1t->ne1t)

head->ne1t->pre* 0 head)

free'temp->emp&name()

temp->emp&name 0 JU##)

free'temp()

temp 0 JU##)

6

free'head->emp&name()

head->emp&name 0 JU##)

free'head()

head 0 JU##)

6

STACHS

he'"er.h

#inc !"e#$t" iI.h%

#inc !"e#$t"io.h%

#inc !"e#$t"Ioo .h%

$tr!ct no"e

6

ch'r "'t',

$tr!ct no"e 1neJt,

@,

type"e9 $tr!ct no"e no"e,

no"e1 cre'teno"e0ch'r2,

.oi" p!$h0no"e 113ch'r2,

ch'r pop0no"e 112,

4'in.c

#inc !"e 5he'"er.h5

#"e9ine MAK 7D

int 4'in0int 'r&c3ch'r 1'r&.(+2

6

FILE 1inp = NULL,

FILE 1o!t = NULL,

ch'r $tr(MAK+,

ch'r re.(MAK+,

int i3 en,

Ioo I = tr!e,

no"e 1he'" = NULL,

LL$tr = 0ch'r 124' oc0MAK 1 $iMeo90ch'r22,

i90'r&cE=)2

6

print905:nNron& n!4Ier o9 'r&!4ent$.52,

eJit0*2,

@

inp = 9open0'r&.(7+35r52,

i9 0NULL == inp2

6

print905:nError openin& 9i e.52,

eJit0*2,

@

o!t = 9open0'r&.(8+35/52,

i9 0NULL == o!t2

6

print905:nError openin& 9i e.52,

eJit0*2,

@

/hi e0I2

6

4e4$et0$tr3*37D2,

4e4$et0re.3*37D2,

en = *,

0.oi"29&et$0$tr37D3inp2,

en = 0int2$tr en0$tr2,

$tr( en?7+ = >:*>,

9or 0i=*,i# en?7,iAA2

6

p!$h0Ohe'"3$tr(i+2,

@

9or 0i=*,i# en?7,iAA2

6

re.(i+ = pop0Ohe'"2,

@

re.( en?7+ = >:*>,

i9 0* == $trnc4p0$tr3re.30$iMe_t2 en22

6

9print90o!t35F$53$tr2,

9print90o!t35:n52,

@

9ree0he'"2,

he'" = NULL,

i9 0* E= 9eo90inp22

6

Ire'C,

@

@

0.oi"29c o$e0inp2,

0.oi"29c o$e0o!t2,

ret!rn *,

@

 

9!nc.c

#inc !"e 5he'"er.h5

no"e1 cre'teno"e0ch'r c2

6

no"e 1ne/no"e,

ne/no"e=0no"e 124' oc0$iMeo90no"e22,

i90NULL == ne/no"e2

6

print905:nM' oc F'i !re.52,

eJit0*2,

@

ne/no"e?%"'t' = c,

ne/no"e?%neJt = NULL,

ret!rn ne/no"e,

@

.oi" p!$h0no"e 11he'"3ch'r c2

6

no"e 1ne/no"e = cre'teno"e0c2,

i9 0NULL == ne/no"e2

6

print905:nNo"e not cre'te".52,

eJit0*2,

@

i9 001he'"2 == NULL2

6

01he'"2 = ne/no"e,

@

e $e

6

ne/no"e?%neJt = 01he'"2,

01he'"2 = ne/no"e,

@

@

ch'r pop0no"e 11he'"2

6

no"e 1te4p,

ch'r c,

i9 0NULL == 01he'"22

6

print905:nLi$t e4pty.52,

ret!rn >*>,

@

e $e

6

te4p = 01he'"2?%neJt,

c = 01he'"2?%"'t',

9ree01he'"2,

1he'" = te4p,

ret!rn c,

@

@

L1.oi" 9ree_no"e0no"e 11he'"2

6

no"e 1te4p,

te4p = 01he'"2,

/hi e0NULL E= 01he'"2?%neJt2

6

te4p = 01he'"2?%neJt,

01he'"2?%neJt = 01he'"2?%neJt?%neJt,

9ree0te4p2,

te4p = NULL,

@

9ree01he'"2,

01he'"2 = NULL,

@1L

  DOUBLE CIRCULAR LINHED LIST

header.h

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

struct node

/

int emp&id)

char ,emp&name)

struct node ,ne1t)

struct node ,pre*)

6)

typedef struct node node)

node, createnode'()

*oid insert&at&begin'node ,,-node ,,()

*oid insert&at&end'node ,,-node ,,()

*oid insert&at&*alue'node ,,-node ,,-int()

*oid delete&at&begin'node ,,-node ,,()

*oid delete&at&end'node ,,-node ,,()

*oid delete&at&*alue'node ,,-node ,,-int()

*oid display'node ,()

*oid free&node'node ,()

main.c

#include .header.h.

int main'(

/

int ch-ch&ins-ch&del-flag-*al-*al!)

flag0%)

node ,head 0 JU##)

node ,tail 0 JU##)

do

/

printf'.4n nter your choice.4n nter ! for insertion.4n nter : for deletion.4n nter ; for display.4n nter = to e1it 7 .()

scanf'.8d.-9ch()

s2itch'ch(

/

case ! 7 printf'.4n nter ! to insert at the end -: to insert at begining and ; to insert after a node 7 .()

scanf'.8d.-9ch&ins()

if '! 00 ch&ins(

/

insert&at&end'9head-9tail()

6

else if ': 00 ch&ins(

/

insert&at&begin'9head-9tail()

6

else

/

printf'.4n nter the employee id after 2hich you 2ant to insert the ne2 node 7 .()

scanf'.8d.-9*al()

insert&at&*alue'9head-9tail-*al()

6

breaC)

case : 7 printf'.4n nter ! to delete at the end-: to delete at the begining and ; to delete a particular node 7 .()

scanf'.8d.-9ch&del()

if '! 00 ch&del(

/

delete&at&end'9head-9tail()

6

else if ': 00 ch&del(

/

delete&at&begin'9head-9tail()

6

else

/

printf'.4n nter the employee id after 2hich you 2ant to delete 7 .()

scanf'.8d.-9*al!()

delete&at&*alue'9head-9tail-*al!()

6

breaC)

case ; 7 display'head()

breaC)

case = 7 free&node'head()

printf'.4n 1iting4n.()

flag0!)

breaC)

6

62hile'flag00%()

return %)

6

func.c

#include .header.h.

#define GAP :%

node, createnode'(

/

node, ne2node)

char nameMGAPN)

int len 0 %)

<< char ,fgets&ret)

memset'name-%-GAP()

ne2node 0 'node ,(malloc'siOeof'node(()

if 'JU## 00 ne2node(

/

printf'.4nGalloc "ailure..()

6

ne2node->emp&id 0 %)

printf'.4n nter the employee id 7 .()

scanf'.8d.-9ne2node->emp&id()

printf'.4n nter the employee name 7 .()

scanf'.8s.-name()

<,fgets&ret 0 fgets'name-!E-stdin()

if 'JU## 00 fgets&ret(

/

printf'.4n"gets failure..()

6,<

len 0 strlen'name()

<,if '54n5 00 nameMlen-!N(

/

nameMlen-!N 0 54%5)

6,<

ne2node->emp&name 0 JU##)

ne2node->emp&name 0 'char ,(malloc''len>!( , siOeof'char(()

if 'JU## 00 ne2node->emp&name(

/

printf'.4nGalloc "ailure..()

6

memset'ne2node->emp&name-%-len()

strncpy'ne2node->emp&name-name-len()

ne2node->pre* 0 JU##)

ne2node->ne1t 0 JU##)

return ne2node)

6

*oid insert&at&end'node ,,head-node ,,tail(

/

node ,ne2node)

ne2node 0 createnode'()

if 'JU## 00 ,head(

/

,head0ne2node)

,tail0ne2node)

6

else

/

',tail(->ne1t 0 ne2node)

ne2node->pre* 0 ,tail)

,tail 0 ne2node)

',tail(->ne1t 0 ',head()

',head(->pre* 0 ',tail()

6

6

*oid insert&at&begin'node ,,head-node ,,tail(

/

node ,ne2node)

ne2node 0 createnode'()

if 'JU## 00 ,head(

/

,head 0 ne2node)

,tail 0 ne2node)

6

else

/

',head(->pre* 0 ne2node)

ne2node->ne1t 0 ,head)

,head 0 ne2node)

',head(->pre* 0 ',tail()

',tail(->ne1t 0 ',head()

6

6

*oid insert&at&*alue'node ,,head-node ,,tail-int *al(

/

node ,ne2node-,temp)

ne2node 0 createnode'()

if 'JU## 00 ,head(

/

,head 0 ne2node)

,tail 0 ne2node)

6

else

/

temp 0 ,head)

2hile '*al @0 temp->emp&id(

/

temp0temp->ne1t)

if 'JU## 00 temp(

/

printf'.4nThe *alue entered does not e1ist in the node..()

breaC)

6

6

ne2node->ne1t 0 temp->ne1t)

ne2node->pre* 0 temp)

temp->ne1t 0 ne2node)

ne2node->ne1t->pre* 0 ne2node)

6

6

*oid delete&at&end'node ,,head-node ,,tail(

/

node ,del)

if 'JU## 00 ,head(

/

printf'.4nThe list is empty..()

6

else

/

del 0 ,tail)

,tail 0 ',tail(->pre*)

',tail(->ne1t 0 ',head()

',head(->pre* 0 ',tail()

free'del->emp&name()

del->emp&name 0 JU##)

free'del()

del 0 JU##)

6

6

*oid delete&at&begin'node ,,head-node ,,tail(

/

node ,del)

if 'JU## 00 ,head(

/

printf'.4nThe list is empty..()

6

else

/

del 0 ,head)

,head 0 ',head(->ne1t)

',head(->pre* 0 ',tail()

',tail(->ne1t 0 ',head()

free'del->emp&name()

del->emp&name 0 JU##)

free'del()

del 0 JU##)

6

6

*oid delete&at&*alue'node ,,head-node ,,tail-int *al(

/

node ,del)

if 'JU## 00 ,head(

/

printf'.4nThe list is empty..()

6

else

/

del 0 ,head)

2hile'*al @0 del->emp&id(

/

del 0 del->ne1t)

if 'JU## 00 del(

/

printf'.4nThe *alue entered does not e1ist in the list..()

breaC)

6

6

del->pre*->ne1t 0 del->ne1t)

del->ne1t->pre* 0 del->pre*)

free'del->emp&name()

del->emp&name 0 JU##)

free'del()

del 0 JU##)

6

6

*oid display'node ,head(

/

node ,temp)

temp 0 head)

if 'JU## 00 head(

/

printf'.4nThe list is empty..()

6

else

/

2hile 'head @0 temp->ne1t(

/

printf'.8d.-temp->emp&id()

printf'. 8s -> .-temp->emp&name()

temp 0 temp->ne1t)

6

printf'.8d.-temp->emp&id()

printf'. 8s -> .-temp->emp&name()

printf'.8d.-temp->ne1t->emp&id()

printf'. 8s4n.-temp->ne1t->emp&name()

6

6

*oid free&node'node ,head(

/

node ,temp-,temp!-,del)

temp! 0 head)

temp 0 head)

if 'JU## 00 head(

/

printf'.4nThe list is empty..()

6

2hile 'head @0 temp!->ne1t(

/

del 0 temp->ne1t)

<,if 'JU## 00 del->ne1t(

/

free'temp->emp&name()

temp->emp&name 0 JU##)

free'temp()

temp 0 JU##)

head->ne1t 00 JU##)

breaC)

6,<

temp->ne1t 0 temp->ne1t->ne1t)

temp->ne1t->pre* 0 temp)

temp! 0 temp->ne1t)

free'del->emp&name()

del->emp&name 0 JU##)

free'del()

del 0 JU##)

6

free'temp!->emp&name()

temp!->emp&name 0 JU##)

free'temp!()

temp! 0 JU##)

free'head->emp&name()

head->emp&name 0 JU##)

<<free'head()

<<head 0 JU##)

6

SINGLE CIRCULAR LINHED LIST

header.h

#include<stdio.h>

#include<stdlib.h>

struct node

/

int data)

struct node ,ne1t)

6)

typedef struct node node)

e1tern node, createnode'()

e1tern *oid insertion'node ,,-int()

e1tern *oid deletion'node ,,-int()

e1tern *oid display'node ,()

e1tern *oid free&node'node ,()

main.c

#include .header.h.

int main'(

/

int ch-ch&ins-ch&del-flag)

flag0%)

node ,head 0 JU##)

do

/

printf'.4n nter your choice.4n nter ! for insertion.4n nter : for deletion.4n nter ; for display.4n nter = to e1it 7 .()

scanf'.8d.-9ch()

s2itch'ch(

/

case ! 7 printf'.4n nter ! to insert at the end -: to insert at the begining and ; to insert after a node 7 .()

scanf'.8d.-9ch&ins()

insertion'9head-ch&ins()

breaC)

case : 7 printf'.4n nter ! to delete at the begining-: to delete at the end and ; to delete a particular node 7 .()

scanf'.8d.-9ch&del()

deletion'9head-ch&del()

breaC)

case ; 7 display'head()

breaC)

case = 7 free&node'head()

printf'.4n 1iting.()

flag0!)

breaC)

6

62hile'flag00%()

return %)

6

func.c

#include .header.h.

node, createnode'(

/

int *al)

node ,ne2node)

ne2node0'node ,(malloc'siOeof'node(()

if'JU## 00 ne2node(

/

printf'.4nGalloc "ailure..()

e1it'%()

6

printf'.4n nter a *alue in the node 7 .()

scanf'.8d.-9*al()

ne2node->data 0 *al)

ne2node->ne1t 0 JU##)

return ne2node)

6

*oid insertion'node ,,head-int ch(

/

node ,ne2node-,temp-,ins)

temp 0 ,head)

int *al)

ne2node 0 createnode'()

if 'JU## 00 ne2node(

/

printf'.4nJode not created..()

6

if 'JU## 00 ,head(

/

,head0ne2node)

6

else if'JU## 00 ',head(->ne1t(

/

',head(->ne1t 0 ne2node)

ne2node->ne1t 0 ',head()

6

else

/

if'! 00 ch(

/

2hile'',head( @0 temp->ne1t(

/

temp0temp->ne1t)

6

temp->ne1t0ne2node)

ne2node->ne1t 0 ',head()

6

else if ': 00 ch(

/

ne2node->ne1t 0 ,head)

2hile'',head( @0 temp->ne1t(

/

temp0temp->ne1t)

6

,head 0 ne2node)

temp->ne1t 0 ',head()

6

else

/

printf'.4n nter the *alue of the node after 2hich you 2ould liCe to insert a ne2 node 7 .()

scanf'.8d.-9*al()

2hile'temp->data @0 *al 99 JU## @0 temp->ne1t(

/

temp0temp->ne1t)

6

ins0temp->ne1t)

temp->ne1t0ne2node)

ne2node->ne1t0ins)

6

6

6

*oid deletion'node ,,head-int ch(

/

node ,ne2node-,temp-,del)

temp 0 ,head)

int *al)

if 'JU## 00 ,head(

/

printf'.4nThe list is empty..()

6

else if 'JU## 00 ',head(->ne1t(

/

printf'.4nThe head node containing the *alue 8d is deleted..-',head(->data()

free',head()

',head( 0 JU##)

6

else

/

if '! 00 ch(

/

del 0 ',head()

2hile'',head( @0 temp->ne1t(

/

temp0temp->ne1t)

6

',head( 0 ',head(->ne1t)

temp->ne1t 0 ',head()

printf'.4nThe head node containing the *alue 8d is deleted..-del->data()

free'del()

del 0 JU##)

6

else if ': 00 ch(

/

2hile '',head( @0 temp->ne1t->ne1t(

/

temp0temp->ne1t)

6

del 0 temp->ne1t)

temp->ne1t 0 ',head()

printf'.4nThe node containing the *alue 8d is deleted..-del->data()

free'del()

del0JU##)

6

else

/

printf'.4n nter the *alue of the node 2hich you 2ould liCe to delete 7 .()

scanf'.8d.-9*al()

2hile 'temp->ne1t->data @0 *al(

/

temp 0 temp->ne1t)

6

del 0 temp->ne1t)

printf'.4nThe node containing the *alue 8d is deleted..-del->data()

temp->ne1t 0 temp->ne1t->ne1t)

free'del()

del 0 JU##)

6

6

6

*oid display'node ,head(

/

printf'.4nKisplaying nodes 7 4n.()

node ,temp)

temp 0 head)

2hile'head @0 temp->ne1t(

/

printf'.8d -> .-temp->data()

temp0temp->ne1t)

6

printf'.8d -> .-temp->data()

printf'.8d.-temp->ne1t->data()

printf'.4n.()

6

*oid free&node'node ,head(

/

node ,temp-,temp!)

temp! 0 head)

2hile'head @0 temp!->ne1t(

/

temp 0 head->ne1t)

temp!->ne1t 0 temp!->ne1t->ne1t)

free'temp()

temp 0 JU##)

6

free'temp!()

temp! 0 JU##)

<<free'head()

<<head 0 JU##)

6

PUEUE CIRCULAR

header.h

#include<stdio.h>

#include<stdlib.h>

*oid insert'int MN-int-int,-int,()

*oid del'int MN-int-int,-int,()

*oid display'int MN-int-int,-int,()

 

main.c

#include .header.h.

#define $+Y H

int main'(

/

int RueueM$+Y N)

int front-rear-ch)

char c)

front 0 %)

rear 0 -!)

do

/

printf'.4n nter ! to insert- : to delete- ; to display and = to e1it 7 .()

scanf'.8d.-9ch()

if '! 00 ch(

/

do

/

insert'Rueue-$+Y -9front-9rear()

printf'.4nKo you 2ish to insert more 7 .()

scanf'. 8c.-9c()

62hile 'c 00 5y5()

6

else if ': 00 ch(

/

do

/

del'Rueue-$+Y -9front-9rear()

printf'.4nKo you 2ish to delete more 7 .()

scanf'. 8c.-9c()

62hile 'c 00 5y5()

6

else if '; 00 ch(

/

display'Rueue-$+Y -9front-9rear()

6

else

/

printf'.4n 1iting.4n.()

e1it'%()

6

62hile '= @0 ch()

return %)

6

func.c

#include .header.h.

*oid insert'int RueueMN-int siOe-int ,front-int ,rear(

/

int n)

if '''',front( 00 %( 99 '',rear( >0 siOe-!(( AA '',front( 00 '',rear(>!( 99 -! @0 ',rear(((

/

printf'.4nWueue 3*erflo2..()

6

else

/

printf'.4n nter an element 7 .()

scanf'.8d.-9n()

if '% @0 ',front( 99 ',rear( >0 'siOe-!((

/

',rear( 0 '',rear( > !(8siOe)

RueueM',rear(N 0 n)

6

else if '% 00 ',front( AA ',rear( < siOe(

/

',rear( >>)

RueueM',rear(N 0 n)

6

6

6

*oid del'int RueueMN-int siOe-int ,front-int ,rear(

/

if '-! 00 ',rear((

/

printf'.4nWueue Underflo2..()

6

else

/

printf'.4nThe number deleted is 7 8d.-RueueM',front(N()

RueueM',front(N 0 %)

',front( >>)

6

6

*oid display'int RueueMN-int siOe-int ,front-int ,rear(

/

int i)

printf'.4nThe Wueue is 7 .()

for 'i0',front()i @0 ',rear()i0'i>!(8siOe(

/

printf'.4n8d.-RueueMiN()

6

printf'.4n8d.-RueueMiN()

6

PUEUE PRIORITQ

header.h

#include<stdio.h>

struct node

/

int pri)

char data)

struct node ,ne1t)

6)

typedef struct node node)

node, createnode'()

*oid insert'node ,,-node ,,()

*oid del'node ,,-node ,,()

*oid display'node ,,()

*oid free&node'node ,,-node ,,()

main.c

#include .header.h.

int main'(

/

node ,front-,rear)

front 0 JU##)

rear 0 JU##)

int ch)

do

/

printf'.4n nter ! to insert- : to delete- ; to display and = to e1it 7 .()

scanf'.8d.-9ch()

s2itch'ch(

/

case ! 7 insert'9front-9rear()

breaC)

case : 7 del'9front-9rear()

breaC)

case ; 7 display'9front()

breaC)

case = 7 free&node'9front-9rear()

<<free'rear()

<<rear 0 JU##)

e1it'%()

breaC)

6

62hile'ch@0=()

return %)

6

func.c

#include .header.h.

node, createnode'(

/

int *al)

char c)

node ,ne2node)

ne2node0'node ,(malloc'siOeof'node(()

if'JU## 00 ne2node(

/

printf'.4nGalloc "ailure..()

e1it'%()

6

printf'.4n nter a *alue in the node 7 .()

scanf'. 8c.-9c()

printf'.4n nter the priority *alue in the node 7 .()

scanf'.8d.-9*al()

ne2node->data 0 c)

ne2node->pri 0 *al)

ne2node->ne1t 0 JU##)

return ne2node)

6

*oid insert'node ,,front-node ,,rear(

/

node ,ne2node-,temp-,temp!)

temp 0 ',front()

ne2node 0 createnode'()

if 'JU## 00 ',front((

/

,front 0 ne2node)

,rear 0 ne2node)

6

else if 'JU## 00 ',front(->ne1t(

/

',front(->ne1t 0 ne2node)

',rear( 0 ne2node)

if'ne2node->pri >',front(->pri(

/

',front( 0 ne2node)

ne2node->ne1t 0 temp)

',rear( 0 temp)

',rear(->ne1t 0 JU##)

6

6

else

/

<<',rear(->ne1t 0 ne2node)

<<',rear( 0 ne2node)

if'',front(->pri < ne2node->pri(

/

',front( 0 ne2node)

',front(->ne1t 0 temp)

6

else

/

2hile 'JU## @0 temp->ne1t(

/

if''temp->ne1t->pri( < 'ne2node->pri((

/

temp! 0 temp->ne1t)

temp->ne1t 0 ne2node)

ne2node->ne1t 0 temp!)

breaC)

6

temp 0 temp->ne1t)

6

6

temp 0 ',front()

2hile 'JU## @0 temp->ne1t(

/

temp0 temp->ne1t)

6

',rear( 0 temp)

6

6

*oid del'node ,,front- node ,,rear(

/

node ,temp)

if 'JU## 00 ',front((

/

printf'.4nWueue underflo2..()

6

else

/

temp 0 ',front()

',front( 0 ',front(->ne1t)

printf'.4nThe node 2ith highest priority and *alue 8c is deleted..-temp->data()

free'temp()

temp 0 JU##)

6

6

*oid display'node ,,front(

/

node ,temp 0 ',front()

printf'.4nKisplaying Wueue.4n.()

2hile 'JU## @0 temp->ne1t(

/

printf'.8c-8d->.-temp->data-temp->pri()

temp 0 temp->ne1t)

6

printf'.8c-8d4n.-temp->data-temp->pri()

6

*oid free&node'node ,,front-node ,,rear(

/

node ,temp)

2hile 'JU## @0 ',front(->ne1t(

/

temp 0 ',front(->ne1t)

free',front()

',front( 0 JU##)

',front( 0 temp)

6

free'',rear(()

',rear( 0 JU##)

6

TREE

header.h

#include<stdio.h>

#include<stdlib.h>

struct node

/

int data)

struct node ,left)

struct node ,right)

6)

typedef struct node node)

node, createnode'()

*oid insert'node ,,()

*oid inorder'node ,()

*oid search'node ,,-int()

*oid del&case%'node ,,-node ,,()

*oid del&case!left'node ,,-node ,,()

*oid del&case!right'node ,,-node ,,()

*oid del&case:'node ,,-node ,,()

*oid le*el&order'node ,()

*oid postorder&free'node ,()

main.c

#include .header.h.

int main'(

/

node ,root 0 JU##)

node ,temp 0 JU##)

int ch-*al)

do

/

printf'.4n nter ! to insert- : to delete- ; to display and = to e1it 7 .()

scanf'.8d.-9ch()

s2itch'ch(

/

case ! 7 insert'9root()

breaC)

case : 7 printf'.4n nter the *alue to be deleted 7 .()

scanf'.8d.-9*al()

search'9root-*al()

breaC)

case ; 7 le*el&order'root()

printf'.4n+norder Tra*ersal 7 .()

inorder'root()

breaC)

case = 7 postorder&free'root()

printf'.4n 1iting4n.()

e1it'%()

6

62hile 'ch@0=()

return %)

6

func.c

#include .header.h.

#define $+Y I

node, createnode'(

/

node ,ne2node)

ne2node 0 'node ,(malloc'siOeof'node(()

if 'JU## 00 ne2node(

/

printf'.4nGalloc "ailure..()

e1it'%()

6

printf'.4n nter the data 7 .()

scanf'.8d.-9'ne2node->data(()

ne2node->left 0 JU##)

ne2node->right 0 JU##)

return ne2node)

6

*oid insert'node ,,root(

/

node ,ne2node 0 createnode'()

node ,temp)

if 'JU## 00 ',root((

/

',root( 0 ne2node)

6

else

/

temp 0 ',root()

2hile'!(

/

if ''temp->data( > 'ne2node->data((

/

if 'JU## 00 temp->left(

/

temp->left 0 ne2node)

breaC)

6

temp 0 temp->left)

6

if ''temp->data( < 'ne2node->data((

/

if 'JU## 00 temp->right(

/

temp->right 0 ne2node)

breaC)

6

temp 0 temp->right)

6

6

6

6

*oid search'node ,,root-int *al(

/

node ,t0',root()

node ,t!)

if 'JU## 00 t(

/

printf'.4nJo elements in the tree..()

return)

6

2hile '*al @0 t->data 99 t@0JU##(

/

if '*al > 't->data((

/

t! 0 t)

t 0 t->right)

6

else if '*al < 't->data((

/

t! 0 t)

t 0 t->left)

6

6

if 'JU## 00 t(

/

printf'.4ndata not found..()

return)

6

if ''JU## 00 t->left( 99 'JU## 00 t->right((

/

del&case%'9t-9t!()

6

else if ''JU## @0 t->left( 99 'JU## 00 t->right((

/

del&case!left'9t-9t!()

6

else if ''JU## @0 t->right( 99 'JU## 00 t->left((

/

del&case!right'9t-9t!()

6

else if ''JU## @0 t->right( 99 'JU## @0 t->left((

/

del&case:'9t-9t!()

6

6

*oid del&case%'node ,,t-node ,,t!(

/

if '',t!(->left 00 ',t((

/

',t!(->left 0 JU##)

6

else

/

',t!(->right 0 JU##)

6

free',t()

',t( 0 JU##)

6

*oid del&case!left'node ,,t-node ,,t!(

/

if '',t!(->left 00 ',t((

/

',t!(->left 0 ',t(->left)

6

else

/

',t!(->right 0 ',t(->left)

6

free',t()

',t( 0 JU##)

6

*oid del&case!right'node ,,t-node ,,t!(

/

if '',t!(->left 00 ',t((

/

',t!(->left 0 ',t(->right)

6

else

/

',t!(->right 0 ',t(->right)

6

free',t()

',t( 0 JU##)

6

*oid del&case:'node ,,t-node ,,t!(

/

node ,temp-,parent)

int C)

parent 0 ',t()

temp 0 ',t(->right)

2hile 'JU## @0 temp->left(

/

parent 0 temp)

temp 0 temp->left)

6

C 0 ',t(->data)

',t(->data 0 temp->data)

temp->data 0 C)

if ''JU## 00 temp->left( 99 'JU## 00 temp->right((

/

parent->right 0 JU##)

free'temp()

temp 0 JU##)

6

else if ''JU## @0 temp->right( 99 'JU## 00 temp->right((

/

del&case!right'9temp-9parent()

6

6

*oid inorder'node ,root(

/

node ,temp)

temp 0 root)

<<printf'.4n+norder tra*ersal 7 .()

if 'JU## @0 temp(

/

inorder'temp->left()

printf'.8d-.-temp->data()

inorder'temp->right()

6

6

*oid le*el&order'node ,root(

/

node ,RueueM$+Y N)

node ,temp 0 root)

int front-rear)

front 0 %)

rear 0 %)

RueueMrearN 0 root)

<<rear >0 !)

printf'.4n#e*el order tra*ersal 7 .()

do

/

printf'.8d- .-RueueMfrontN->data()

temp 0 RueueMfrontN)

if 'front 00 '$+Y -!((

/

front 0 -!)

6

front >>)

if 'JU## @0 temp->left(

/

if 'rear 00 '$+Y -!((

/

rear 0 -!)

6

rear>>)

RueueMrearN 0 temp->left)

6

if 'JU## @0 temp->right(

/

if 'rear 00 '$+Y -!((

/

rear 0 -!)

6

rear>>)

RueueMrearN 0 temp->right)

6

62hile 'front @0 rear()

printf'.8d.-RueueMfrontN->data()

6

*oid postorder&free'node ,root(

/

if 'JU## @0 root(

/

postorder&free'root->left()

postorder&free'root->right()

free'root()

root 0 JU##)

6

6

RASRING

header.h

#include<stdio.h>

#include<stdlib.h>

#define $+Y H

struct de*ice

/

int de*ice&id)

char ,de*ice&type)

6)

typedef struct de*ice de*ice)

struct presence

/

int id)

char ,name)

de*ice d)

struct presence ,ne1t)

6)

typedef struct presence presence)

int hash'int()

*oid insert'presence ,MN()

*oid display'presence ,MN()

*oid free&node'presence ,MN()

main.c

#include.header.h.

int main'(

/

presence ,aopM$+Y N)

int i-num)

for 'i0%)i<$+Y )i>>(

/

aopMiN 0 JU##)

6

do

/

printf'.4n nter ! for insert- : for display and ; to e1it 7 .()

scanf'.8d.-9num()

s2itch'num(

/

case ! 7 insert'aop()

breaC)

case : 7 display'aop()

breaC)

case ; 7 free&node'aop()

printf'.4n 1iting..()

e1it'%()

6

62hile 'num @0 ;()

return %)

6

func.c

#include.header.h.

 

*oid insert'presence ,ptrMN(

/

int num-i-len&name-len&de*-C)

char name&strM:%N)

char de*&typeM:%N)

memset'name&str-%-:%()

memset'de*&type-%-:%()

presence ,node)

len&name 0 %)

len&de* 0 %)

printf'.4n nter the number of records you 2ant to enter 7 .()

scanf'.8d.-9num()

for 'i0%)i<num)i>>(

/

node 0 'presence ,(malloc'siOeof'presence(()

if 'JU## 00 node(

/

printf'.4nGalloc "ailure..()

return )

6

printf'.4n nter name 7 .()

scanf'.8s.-name&str()

len&name0strlen'name&str()

name&strMlen&nameN054%5)

node->name 0 'char ,(malloc'siOeof'char( , 'len&name>!(()

if 'JU## 00 node->name(

/

printf'.4nGalloc "ailure..()

return )

6

memset'node->name-%-len&name()

printf'.4n nter de*ice type 7 .()

scanf'.8s.-de*&type()

len&de*0strlen'de*&type()

de*&typeMlen&de*N054%5)

node->d.de*ice&type 0 'char ,(malloc'siOeof'char( , 'len&de*>!(()

if 'JU## 00 node->d.de*ice&type(

/

printf'.4nGalloc "ailure..()

return )

6

memset'node->d.de*ice&type-%-len&de*()

node->id 0 %)

printf'.4n nter id 7 .()

scanf'.8d.-9'node->id(()

strncpy'node->name-name&str-len&name()

node->d.de*ice&id 0 %)

printf'.4n nter de*ice id 7 .()

scanf'.8d.-9'node->d.de*ice&id(()

strncpy'node->d.de*ice&type-de*&type-len&de*()

node->ne1t 0 JU##)

C 0 hash'node->id()

if 'JU## 00 ptrMCN(

/

ptrMCN 0 node)

6

else

/

node->ne1t 0 ptrMCN)

ptrMCN 0 node)

6

6

6

int hash'int n(

/

return 'n8$+Y ()

6

*oid display'presence ,ptrMN(

/

int i)

presence ,temp0JU##)

printf'.4nKisplaying details . .()

for 'i0%)i<$+Y )i>>(

/

temp 0 ptrMiN)

printf'.4n#ist number 7 8d.-i()

2hile 'JU## @0 temp(

/

printf'.4n+K 7 8d.-temp->id()

printf'.4nJAG 7 8s.-temp->name()

printf'.4nK Z+C +K 7 8d.-temp -> d.de*ice&id()

printf'.4nK Z+C TUV 7 8s.-temp -> d.de*ice&type()

temp 0 temp->ne1t)

6

temp 0 JU##)

printf'.4n.()

6

6

*oid free&node'presence ,ptrMN(

/

int i)

presence ,temp-,temp!)

for 'i0%)i<$+Y )i>>(

/

temp 0ptrMiN)

2hile'JU## @0 temp(

/

free'temp->name()

temp->name 0 JU##)

free'temp->d.de*ice&type()

temp->d.de*ice&type 0 JU##)

temp!0temp)

temp 0 temp!->ne1t)

free'temp!()

temp! 0 JU##)

6

6

6 SORTING AND BINARQ SEARCR

header.h

#include<stdio.h>

#define GAP !H

*oid bubble&sort'int MN-int()

*oid insertion&sort'int MN-int()

*oid RuicCsort'int MN-int-int()

*oid bin&search'int MN-int-int()

*oid display'int MN-int()

main.c

#include .header.h.

int main'(

/

int aMGAPN)

int siOe-num-i-ch)

printf'.4n nter the number of elements you 2ant to insert 7 .()

scanf'.8d.-9siOe()

printf'.4n nter the elements in the array 7 .()

for 'i0%)i<siOe)i>>(

/

scanf'.8d.-9aMiN()

6

printf'.4nThe array is 7 4n.()

display'a-siOe()

printf'.4n nter ! to sort by bubble sort- : to sort by insertion sort and ; to sort by RuicCsort 7 .()

scanf'.8d.-9ch()

s2itch'ch(

/

case ! 7 bubble&sort'a-siOe()

printf'.4nThe sorted array is 7 4n.()

display'a-siOe()

breaC)

case : 7 insertion&sort'a-siOe()

printf'.4nThe sorted array is 7 4n.()

display'a-siOe()

breaC)

case ; 7 RuicCsort'a-%-siOe-!()

printf'.4nThe sorted array is 7 4n.()

display'a-siOe()

breaC)

6

printf'.4n nter the element to search for 7 .()

scanf'.8d.-9num()

bin&search'a-siOe-num()

return %)

6

func.c

#include.header.h.

*oid bubble&sort'int aMN-int siOe(

/

int i-Q-temp)

for 'i0%)i<siOe)i>>(

/

for 'Q0i>!)Q<siOe)Q>>(

/

if 'aMiN > aMQN(

/

temp 0 aMiN)

aMiN 0 aMQN)

aMQN 0 temp)

6

6

6

6

*oid insertion&sort'int aMN-int siOe(

/

int i-Q-temp)

for 'i0%)i<siOe)i>>(

/

temp 0 aMiN)

Q 0 i-!)

2hile ''temp < aMQN( 99 'Q>0%((

/

aMQ>!N 0 aMQN)

Q 0 Q-!)

6

aMQ>!N 0 temp)

6

6

*oid RuicCsort'int aMN-int first-int last(

/

int pi*ot-i-Q-temp-pi*ot&item)

if 'first<last(

/

pi*ot 0 first)

i 0 first)

Q 0 last)

pi*ot&item 0 aMfirstN)

2hile 'i<Q(

/

2hile 'aMiN <0 pi*ot&item(

/

i >0 !)

6

2hile 'aMQN > pi*ot&item(

/

Q -0 !)

6

if 'i < Q(

/

temp 0 aMiN)

aMiN 0 aMQN)

aMQN 0 temp)

6

6

aMfirstN 0 aMQN)

aMQN 0 pi*ot&item)

RuicCsort'a-first-Q-!()

RuicCsort'a-Q>!-last()

6

6

*oid display'int aMN-int siOe(

/

int i)

for 'i0%)i<siOe)i>>(

/

printf'.8d4t.-aMiN()

6

6

*oid bin&search'int aMN-int siOe-int num(

/

int lo2er-upper-middle-flag)

flag 0 %)

lo2er 0 %)

upper 0 siOe-!)

2hile 'lo2er <0 upper(

/

middle 0 'lo2er>upper(<:)

if 'num 00 aMmiddleN(

/

flag0!)

breaC)

6

else if 'num < aMmiddleN(

/

upper 0 middle-!)

6

else

/

lo2er 0 middle>!)

6

6

if '% 00 flag(

/

printf'.4nThe number 8d is not found in the array..-num()

6

else

/

printf'.4nThe number 8d is found in the array..-num()

6

6

PUICH SORT NITR MIDDLE ELEMENT AS PIGOT

.oi" S!icC$ort0int '(+3int 9ir$t3int '$t2

6

int pi.ot3i3B3te4p3pi.ot_ite4,

pi.ot = 09ir$t A '$t2L8,

i = 9ir$t,

B = '$t,

pi.ot_ite4 = '(pi.ot+,

i9 09ir$t% '$t2

6

ret!rn,

@

/hi e 0i #= B2

6

/hi e 0'(i+ # pi.ot_ite42

6

i A= 7,

@

/hi e 0'(B+ % pi.ot_ite42

6

B ?= 7,

@

i9 0i #= B2

6

te4p = '(i+,

'(i+ = '(B+,

'(B+ = te4p,

iAA,

B??,

@

@

S!icC$ort0'39ir$t3B2,

S!icC$ort0'3i3 '$t2,

@

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close