Top Banner
EC6312 - OOPS AND DATA STRUCTURES LABORATORY LIST OF EXPERIMENTS S.NO. NAME OF THE CONCEPT / PROGRAM 1. Basic Programs for C++ Concepts. 1.1 C++ Programs without using classes and objects a) Displaying Stude nt Details b)Sum of !" !atural numbers c) # inding sum and a$erage of % mar&s 1.' C++ Programs without using classes and objects a) Displaying ti me in di(e rent for mats b)# actorial of the gi$en numbers c) eference $ariable s d) Constr uctors and Destructors e) # unction *$erloading f) *perator *$erloadi ng i. nary minus operator ii . Bi nary ad di ti on operator g),nheritance '. -rray implementation of ,S/ -D/ 0. in&ed ist ,mplementation of ,S/ -D/ . Cursor ,mplementation of ,S/ -D/ %. Stac& -D/ a) -rra y ,mple mentation b) in& ed ist ,mplementat ion 2. Program source 3les i. Stac& a ppli cati on 1 4 C hec &i ng parenthes is ii. -r ray i mp lementation of S/ -C5 -D/ -pplication 1 6 Chec&ing parenthesis -pplication ' 6 Chec&ing parenthesis ii i. i n& ed li st impl ementation of S/ -C5 -D/ -pplication 1 6 Chec&ing parenthesis -pplication ' 6 Chec&ing parenthesis i$. Stac& ap pl ication ' 4 Post637 e 7pression e$aluation $. Program with necessary header 3les 8. Stac& -pplication 9e7pression con$ersion ) 6 ,n37 to post37
70

DeepaOOP DS Lab Manual

Feb 17, 2018

Download

Documents

Deep An
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 1/70

EC6312 - OOPS AND DATA STRUCTURES LABORATORY

LIST OF EXPERIMENTS

S.NO. NAME OF THE CONCEPT / PROGRAM

1. Basic Programs for C++ Concepts.

1.1 C++ Programs without using classes andobjects

a)Displaying Student Detailsb)Sum of !" !atural numbersc) #inding sum and a$erage of % mar&s

1.' C++ Programs without using classes andobjects

a) Displaying time in di(erent formatsb)#actorial of the gi$en numbers

c) eference $ariablesd)Constructors and Destructorse)#unction *$erloadingf) *perator *$erloading

i. nary minus operatorii. Binary addition operator

g),nheritance'. -rray implementation of ,S/ -D/0. in&ed ist ,mplementation of ,S/ -D/

. Cursor ,mplementation of ,S/ -D/%. Stac& -D/

a) -rray ,mplementationb) in&ed ist ,mplementation

2. Program source 3lesi. Stac& application 1 4 Chec&ing parenthesisii. -rray implementation of S/-C5 -D/

• -pplication 1 6 Chec&ing parenthesis

• -pplication ' 6 Chec&ing parenthesis

iii. in&ed list implementation of S/-C5 -D/• -pplication 1 6 Chec&ing parenthesis

• -pplication ' 6 Chec&ing parenthesis

i$. Stac& application ' 4 Post637 e7pressione$aluation

$. Program with necessary header 3les8. Stac& -pplication 9e7pression con$ersion ) 6 ,n37 to

post37

Page 2: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 2/70

i. -rray ,mplementationii. in&ed ist ,mplementation

:. Stac& -pplication 4 String e$ersei. -rray ,mplementationii. in&ed ist ,mplementation

;. Stac& -pplication 9e7pression con$ersion ) 6 ,n37 topre37

i. -rray ,mplementationii. in&ed ist ,mplementation

1<. =>> -D/i. -rray ,mplementationii. in&ed ist ,mplementation

11. Search /ree -D/ 4 Binary Search /ree1'. =uic& Sort

Page 3: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 3/70

1.  BASIC C++ PROGRAMS

1.1 C++ Program – Without Classes And Obe!ts

a.  DISPLAYING STUDENT DETAILS 

#include<iostream.h>#include<conio.h>void main(){clrscr();char name[23],college[23],department[23];intregno;cout<<!!! "$%&' %&*" !!!+n;cout<<&nter name, %epatment, regno and college - +n;cin>>name>>department>>regno>>college;cout<<+n'&-+t<<name;cout<<+n%&/0&'-+t<<department;cout<<+n0&1. '-+t<<regno;cout<<+n**&1&-+t<<college;getch();4

b.  SUM OF ‘N’ NATURAL NUMBERS 

#include<iostream.h>#include<conio.h>void main(){inti,n,sum56;clrscr();cout<<!!! "$ 7 ' '$0* '$8&0" !!!;cout<<+n&nter the no. o9 terms - ;cin>>n;9or(i5:;i<5n;i){

sum5sumi;4cout<<+nhe sum o9<<n<< natural numer -<<sum;getch();4

O"#P"#

!!! "$%&' %&*"!!!

&nter name, %epatment,regno and college -

0a=a"&

2:6""&

 '& - 0a=a%&/0&' - "&0&1. ' - 2:6**&1& - ""&

O"#P"#

!!! "$ 7 ' '$0* '$8&0" !!!

&nter the no. o9 terms - 3he sum o9 3 natural

numers -

Page 4: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 4/70

c.  FINDING THE TOTAL AND AVERAGE OF FIVE MARKS 

#include<iostream.h>

#include<conio.h>void main(){

int m:,m2,m3,m?,m@;9loat total,avg;clrscr();cout<<!!! 7inding otal and verage o9 @ marAs !!!+n;cout<<+n&nter the value o9 9ive marAs - +n;cin>>m:>>m2>>m3>>m?>>m@;total5(m:m2m3m?m@);avg5(total)B@;

cout<<+nhe total o9 @ marAs is <<total<<and their average is<<avg;getch();4

O"#P"#

!!! 7inding otal andverage o9 @ marAs!!!

&nter the value o9 9ivemarAs -

CCCDCCEC@he total o9 @ marAs is

?D and their averageis CE

Page 5: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 5/70

1.$ C++PROGRAMS WI#% C&ASS'S A() OB*'C#S

a.  DISPLAYING TIME USING 12 HOURS AND 24 HOURS FORMAT

#include<iostream.h>#include<conio.h>class time{

 pulic-int hr,min,sec;void getdata();void displaF();

4;void time--getdata()

{ cout<<+n&nter the time - ;cin>>hr>>min>>sec;

4void time--displaF(){

i9(hr>2?)cout<<+nG0'1 '/$ %;

else{

i9(hr>:2)

{ cout<<+n2? hours 9ormat;cout<<hr<<-<<min<<-<<sec;cout<<+n:2 houts 9ormat;hr5hrH:2;cout<<hr<<-<<min<<-<<sec;

4else{

cout<<+n2? hour 9ormat;cout<<hr<<-<<min<<-<<sec;cout<<+n:2 hour 9ormat;cout<<hr<<-<<min<<-<<sec;

44

4void main(){

clrscr();time o=;cout<<!!! %isplaFing time in tIo 9ormats !!!+n;o=.getdata();

O"#P"# –

Comilation 1

!!! %isplaFing time intIo 9ormats !!!

&nter the time:D :D 3?

2? hours 9ormat :D-:D-3?:2 hours 9ormat -:D-3?

O"#P"# –

Comilation $

!!! %isplaFing time intIo 9ormats !!!

&nter the time:6 23 ?@

2? hours 9ormat :6-23-?@:2 hours 9ormat :6-23-?@

O"#P"# –

Comilation ,

!!! %isplaFing time in

tIo 9ormats !!!&nter the time@? 23 ?@

G0'1 '/$ %

Page 6: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 6/70

o=.displaF();getch();

4

b.  FACTORIAL OF THE GIVEN NUMBER

#include<iostream.h>

#include<conio.h>class 9actorial{

 pulic-intn,i,9act;void getdata();void calc();void displaF();

4;void 9actorial--getdata(){

cout<<+n&nter the numer - ;cin>>n;4void 9actorial--calc(){

9act5:;i9(n556)

displaF();else{

9or(i5:;i<5n;i)

9act59act!i;44void 9actorial--displaF(){

cout<<+nhe 9actorial o9 the given numer is<<9;4void main(){

clrscr();cout<<!!! 70* 7 J& 1K&' '$8&0 !!!+n;9actorial o=;o=.getdata();o=.calc();o=.displaF();getch();

4

O"#P"# – Comilation 1

!!! 70* 7 J& 1K&' '$8&0 !!!

&nter the numer - @he 9actorial o9 the given numer is :26

O"#P"# – Comilation $

!!! 70* 7 J& 1K&' '$8&0 !!!&nter the numer - 6he 9actorial o9 the given numer is :

Page 7: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 7/70

c.  REFERENCE VARIABLE 

#include<iostream.h>#include<conio.h>class re9erence{ pulic-void displaF();4;void re9erence--displaF(){9loat total5:66;9loat Lsum5total;cout<<nitial Kalues o9 total L "um - +n+n;

cout<<M+nM<<otal<<M+tM<<total;cout<<M+nM<<"um<<M+tM<<sum<<endl;cout<<+n9ter adding :6 to total -+n;total5total:6;cout<<M+nM<<otal<<M+tM<<total;cout<<M+nM<<"um<<M+tM<<sum;cout<<+n9ter assigning 6 to sum -+n;sum56;cout<<M+nM<<total<<M+tM<<total;cout<<M+nM<<sum<<M+tM<<sum;4

void main(){clrscr();cout<<!!! 0&7&0&'& K08*& !!!+n;re9erence o=;o=.displaF();

getch();4

O"#P"#

!!! 0&7&0&'&K08*& !!!

nitial Kalues o9 total Lsum -

otal :66"um :669ter adding :o to totalotal ::6"um ::69ter assigning 6 to sumotal 6"um 6

Page 8: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 8/70

.  CONSTRUCTOR AND DESTRUCTOR

#include<iostream.h>#include<conio.h>class code{

 pulic-int id;code(int a){

cout<<+nonstructor called+n;id5a;

4code(code LN)

{cout<<+nopF constructor called+n;id5N.id;

4Ocode(){

cout<<+n%estructor called+n;4void displaF(){

cout<<id<<endl;;

44;void main(){

clrscr();cout<<!!! '"0$0 '% %&"0$0 !!!+n+n;code (:66);code 8();code 5;cout<<+nid o9 is -;.displaF();

cout<<+nid o9 8 is -;8.displaF();cout<<+nid o9 is -;.displaF();getch();

4

O"#P"#

!! '"0$0'% %&"0$0!!!

onstructor called

opF constructor called

opF constructor called

id o9 is - :66

id o9 8 is - :66

id o9 is - :66

%estructor called

%estructor called

Page 9: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 9/70

!.  FUNCTION OVERLOADING

#include<iostream.h>#include<conio.h>class calc{inta,,c;9loat avg; pulic-void average(inta,int );void average(inta,int,int c);4;void calc--average(inta,int )

{avg5(a)B2;cout<<+nhe average o9 <<a<< and P<<<< is<<+t<<avg;4void calc--average(inta,int,int c){avg5(ac)B3;cout<<+nhe average o9 <<a<< , P<<<< and <<c<< is<<+t<<avg;4void main(){

clrscr();calc o=cout<<!!! K&01& $"'1 7$'' K&0*%'1 !!!+n+n;o=.average(:6,26);o=.average(:6,26,36);getch();4

O"#P"#

!!! K&01& $"'1

7$''K&0*%'1 !!!

he average o9 :6 and 26is :@

he average o9 :6 , 26 and36 is 26

Page 10: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 10/70

 ".  OPERATOR O#!$%&a'() 

(i) UNARY OPERATOR “ minus “

#include<iostream.h>#include<conio.h>class unarF{

intN,F,Q;inta,,c; pulic-void getdata(inta,int,int c);void displaF();

void operator H();4;void unarF--getdata(inta,int,int c){

cout<<endl;N5a;F5;Q5c;

4void unarF--displaF(){

cout<<N5<<N<<endl;cout<<F5<<F<<endl;cout<<Q5<<Q<<endl;

4void unarF--operator H(){

 N5HN; F5HF; Q5HQ;

4void main(){

clrscr();cout<<!!! $narF operator overloading !!!+n+n;unarF o=;intm,n,o;cout<<+n&nter the values o9 3 variales- +n;cin>>m>>n>>o;s.getdata(m,n,o);cout<<+nKalues e9ore overloading+n;s.displaF();BB$narF operator R is applied on the o=ect created

O"#P"#

!!! $narF operatoroverloading !!!

&nter the values o9 3variales-

@HE

Kalues e9ore overloadingN 5 @F 5 HQ 5 E

Kalues a9ter overloadingN 5 H@F 5 Q 5 HEs.displaF();

Page 11: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 11/70

Hs;cout<<+nKalues a9ter overloading+n;s.displaF();getch();

4

(ii) BINARY OPERATOR OVERLOADING “addition”

#include<iostream.h>#include<conio.h>class compleN{

doule a,; pulic-compleN(){

4compleN(doule real,doule img)

{ a5real; 5img;

4compleN operator (compleN c){

compleN temp;temp.a5ac.a;temp.5c.;return(temp);

4

compleN operator H(compleN c){compleN temp;temp.a5aHc.a;temp.5Hc.;return(temp);

4compleN operator !(compleN c){

compleN temp;temp.a5a!c.a;temp.5!c.;return(temp);

4compleN operator B(compleN c){

compleN temp;temp.a5aBc.a;temp.5Bc.;return(temp);

4void displaF()

Page 12: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 12/70

{cout<<a<<<<<<=;

44;

void main(){

clrscr();compleN c:,c2,c3;cout<<!!! 8inarF perator overloading !!!;c:5compleN(D,?);c25compleN(2,2);cout<<+nIo compleN numers +n;cout<<c:5;c:.displaF();cout<<+nc25;c2.displaF();cout<<+n+nddition - c3 5 c: c2;

c35c:c2;cout<<+n0&"$* 5 ;c3.displaF();cout<<+n+n"utraction - c3 5 c: H c2;c35c:Hc2;cout<<+n0&"$* 5 ;c3.displaF();cout<<+n+nultiplication - c3 5 c: ! c2;c35c:!c2;cout<<+n0&"$* 5 ;c3.displaF();

cout<<+n+n%ivision - c3 5 c: B c2;c35c:Bc2;cout<<+n0&"$* 5 ;c3.displaF();getch();

4

O"#P"#

Page 13: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 13/70

g. C++ Programs -or inheritan!e !on!et

0e9er programs on inheritance in chapter 2.

Page 14: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 14/70

$.  ARRA IMP&'M'(#A#IO O/ &IS# A)#

#include<iostream.h>#include<conio.h>#include<stdli.h>class arr { pulic-intN,i,sea,del,m[2@],p;void create();void displaF();void search();

void erase();void insert();4;void arr--create(){

cout<<+n&nter the no. o9 elements;cin>>N;cout<<+&nter the arraF elements;9or(i56;i<N;i){cin>>m[i];

44void arr--displaF(){

cout<<+nthe entered arraF is;9or(i56;i<N;i){cout<<+n<<m[i];4

4

Page 15: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 15/70

void arr--search(){

cout<<+n&nter the element to e searched;cin>>sea;9or(i56;i<N;i){

i9(sea55m[i]){

cout<<+nhe position o9 the element is<<i:;4else{cout<<+n&lement is not in the given list o9 arraFs;4

44void arr--erase(){

cout<<+n&nter the element to e deleted;

cin>>del;9or(i56;i<N;i){

i9(del55m[i]){m[i]56;4else{cout<<+nm[i]5<<m[i];4

44void arr--insert(){cout<<+nenter the no.o9 variales to e inserted;cin>>p;

cout<<+ninsert the variales;9or(i56;i<p;i){cin>>m[N];4

4void main(){

clrscr();arr a;int n;do{

cout<<+n:[email protected]+n.eNit;cout<<+n&nter the choice;

Page 16: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 16/70

cin>>n;sIitch(n){case :- a.create();

 reaA;case 2- a.displaF();

 reaA;case 3- a.search();

 reaA;case ?- a.erase(); reaA;

case @- a.insert(); reaA;

case - eNit(:); reaA;

de9ault-cout<<+n'K*%; reaA;4

4Ihile(n<);

getch();4

O"#P"#

:. create2. displaF3. search?. erase

@. insert. eNit&nter the choice :&nter the no. o9 elements @&nter the arraF elements :23?@

:. create2. displaF3. search?. erase@. insert. eNit&nter the choice 2he entered arraF is:23?

Page 17: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 17/70

@

:. create

2. display

3. search

4. erase

5. insert

6. exit

Enter the choice 3Enter the element to be searched 2

Not found

Location of the element is 2

Not found

Not found

Not found

1. create

2. display

3. search

4. erase

5. insert

6. exit

Enter the choice 4

Enter the element to be deleted 5

m[i]=1

m[i]=2

m[i]=3

m[i]=4

1. create

2. display

3. search

4. erase

5. insert

6. exit

Enter the choice 2

The entered array is

1

2

3

4

0

1. create

2. display

3. search

4. erase

5. insert

6. exit

Page 18: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 18/70

Enter the choice 5

Enter the no. of elements to be inserted 3

Insert the variables 99

88

77

1. create

2. display

3. search

4. erase5. insert

6. exit

Enter the choice 6

,.  &I(0') &IS# IMP&'M'(#A#IO( O/ &IS# A)#

#include<iostream.h>#include<conio.h>struct node{int data;node !neNt;4!head,!temp,!nnode,!prev;class sll{ pulic-sll(){head5'$**;4intn,pos,sea,9,del;void create();void displaF();void deleg();void delend();void delpos();void search();void inseg();void inspos();void insend();4;void sll--create(){

Page 19: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 19/70

cout<<+n&nter the no. o9 elements to e created;cin>>n;9or(inti56;i<n;i){

nnode5neI node;cout<<+n&nter data;cin>>nnodeH>data;nnodeH>neNt5'$**;

i9(head55'$**){head5nnode;temp5nnode;

4else{

tempH>neNt5nnode;temp5tempH>neNt;

44

4void sll--displaF(){

temp5head;Ihile(tempH>neNtS5'$**){

cout<<+n<<tempH>data;temp5tempH>neNt;

4cout<<+n<<tempH>data;

4

void sll--delend(){temp5head;Ihile(tempH>neNtS5'$**){

 prev5temp;temp5tempH>neNt;

4 prevH>neNt5'$**;cout<<+n<<tempH>data<<is deleted;delete temp;

4void sll--delpos(){

temp5head;cout<<+n&nter the element to e deleted;cin>>del;Ihile(tempH>neNtS5'$**){

i9(tempH>data55del){

 prevH>neNt5tempH>neNt;

Page 20: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 20/70

delete temp; reaA;

4 prev5temp;temp5tempH>neNt;4

4void sll--deleg()

{ temp5head;head5headH>neNt;delete temp;

4void sll--inspos(){

temp5head;nnode5neI node;cout<< enter the element a9ter Ihich neI element is to e inserted;cin>>pos;

Ihile(tempH>neNtS5'$**){i9(pos55tempH>data){

cout<<+n&nter data to e inserted;cin>>nnodeH>data;nnodeH>neNt5tempH>neNt;tempH>neNt5nnode; reaA;

4else

{ temp5tempH>neNt;4

44void sll--insend(){

temp5head;nnode5neI node;cout<<+n enter the data-;cin>>nnodeH>data;nnodeH>neNt5'$**;Ihile(tempH>neNtS5'$**){

temp5tempH>neNt;4tempH>neNt5nnode;

4void sll--inseg(){

temp5head;nnode5neI node;

Page 21: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 21/70

cout<<enter the data-;cin>>nnodeH>data;nnodeH>neNt5head;head5nnode;

4void sll--search(){

temp5head;

cout<<enter the element to e searched-;cin>>sea;Ihile(tempH>neNtS5'$**){

i9(tempH>data55sea){

95:; reaA;

4else{

temp5tempH>neNt;44i9(955:){

cout<<+n&lement 9ound;4else{

cout<<+n&lement not 9ound;4

4void main(){

clrscr();int m;sll s;do{

cout<<+n:.create<<+n<<2.displaF<<+n<<3.search<<+n<<?.deletion in egining<<+n<<@.deletion in end<<+n

<<.deletion o9 selected element<<+n<<E.insertion in eginning<<+n<<D.insertion inend<<+n<<C.insertion in given position+n;

cout<<+n&nter the choice;cin>>m;sIitch(m){

case :- s.create(); reaA;

case 2- s.displaF(); reaA;

case 3- s.search(); reaA;

Page 22: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 22/70

case ?- s.deleg();s.displaF(); reaA;

case @- s.delend();s.displaF(); reaA;

case - s.delpos();s.displaF();

 reaA;case E- s.inseg();s.displaF(); reaA;

case D- s.insend();s.displaF(); reaA;

case C- s.inspos();s.displaF(); reaA;

4

4Ihile(m<:6);getch();4O"#P"#

"'1*& *'T&% *":.create2.displaF3.search?.delete at the [email protected] at the end

.delete at the given positionE.insert at the eginningD.insert at the endC.insert at the given position:6.eNitenter Fou choice-:enter the numer o9 element to e created-@enter the neI data-:6enter the neI data-26enter the neI data-36enter the neI data-?6enter the neI data-@6:.create2.displaF3.search?.delete at the [email protected] at the end.delete at the given positionE.insert at the eginningD.insert at the endC.insert at the given position:6.eNit

Page 23: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 23/70

enter Four choice-2:62636?6@6:.create2.displaF

3.search?.delete at the [email protected] at the end.delete at the given positionE.insert at the eginningD.insert at the endC.insert at the given position:6.eNitenter Four choice-3enter the element to e searched-36element 9ound

:.create2.displaF3.search?.delete at the [email protected] at the end.delete at the given positionE.insert at the eginningD.insert at the endC.insert at the given position:6.eNitenter Four choice-?

2636?6@6:.create2.displaF3.search?.delete at the [email protected] at the end.delete at the given positionE.insert at the eginningD.insert at the endC.insert at the given position:6.eNitenter Four choice-@2636?6:.create2.displaF3.search?.delete at the eginning

Page 24: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 24/70

@.delete at the end.delete at the given positionE.insert at the eginningD.insert at the endC.insert at the given position:6.eNitenter Four choice-:6

.  C"RSOR IMP&'M'(#A#IO( O/ &IS# A)#

22222222222222

33!ursor%eader.h

22222222222222

#include<iostream.h>#include<conio.h>#de9ine "/&U"V& :6struct 'ode

{ int data;int 'eNt;

4;tFpede9 int /tro'ode;tFpede9 /tro'ode /"';tFpede9 /tro'ode *";struct 'ode cursor["/&U"V&];void nitialiQeursor(){

int i;9or(i56;i<5"/&U"V&H:;i)

{ cursor[i].'eNt5i:;cursor[i].data56;

4cursor["/&U"V&H:].'eNt5H:;

4/"' ursorlloc(){

/"' /;/5cursor[6].'eNt;cursor[6].'eNt5cursor[/].'eNt;cursor[/].data5H:;

Page 25: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 25/70

cursor[/].'eNt5H:;return /;

4

void ursor7ree(/"' /){

cursor[/].'eNt5cursor[6].'eNt;cursor[6].'eNt5/;cursor[/].data56;

4

void nsert(int W,/"' /){

/"' emp;emp5ursorlloc();i9(emp55H:)

cout<<+nut o9 space;else i9(cursor[/].data556)

cout<<+n/osition is not in the list;else{

cursor[emp].data5W;cursor[emp].'eNt5cursor[/].'eNt;cursor[/].'eNt5emp;

44int s*ast(/"' /){

return cursor[/].'eNt55H:;4int s&mptF(*" *){

return cursor[*].'eNt55H:;

4

/"' 7ind(int W,*" *){

/"' emp;emp5cursor[*].'eNt;Ihile(empS5H:LLcursor[emp].dataS5W)

emp5cursor[emp].'eNt;return emp;

4

/"' 7ind/revious(int W,*" *)

{ /"' emp;emp5*;Ihile(empS5H:LLcursor[cursor[emp].'eNt].dataS5W)

emp5cursor[emp].'eNt;return emp;

4

void %elete(int W,*" *){

/"' /,emp;/57ind/revious(W,*);

Page 26: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 26/70

i9(Ss*ast(/)){

emp5cursor[/].'eNt;cursor[/].'eNt5cursor[emp].'eNt;ursor7ree(emp);

44

void aAe&mptF(*" *)

{Ihile(Ss&mptF(*))%elete(cursor[cursor[*].'eNt].data,*);

4

void %isplaF(){

int i;9or(i56;i<5"/&U"V&H:;i)cout<<+n<<i<<+t<<cursor[i].data<<+t<<cursor[i].'eNt;

4

22222222222222

33 !ursoriml.!

22222222222222

#include<iostream.h>#include<conio.h>#include<process.h>

#includecursorJeader.h

class cursor%emo{

 pulic-*" *;cursor%emo(){*5H:;4/"' /;int choice,place,N;void menu();

4;

void cursor%emo--menu(){

Ihile(:){cout<<+n:.reate+n2.nsert+n3.%elete+n?.aAe&mptF+n@.%isplaF+n.7ind+nE.&Nit;cout<<+n&nter ur choice-+t;cin>>choice;sIitch(choice){case :-i9(*55H:)

Page 27: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 27/70

{nitialiQeursor();*5ursorlloc();cout<<*ist created.. ;

4else

cout<<+n*ist is alreadF created; reaA;case 2-

i9(*55H:)cout<<+n*ist is not Fet initialiQed;else{

cout<<+nGhere u Iant to insertX;cin>>place;cout<<+n&nter the element to insert;cin>>N;nsert(N,place);

4 reaA;case 3-

i9(*55H:)cout<<+n*ist is not Fet initialiQed;

else{

cout<<+nGhich element Fou Iant to deleteX;cin>>N;%elete(N,*);

4 reaA;case ?-i9(*55H:)

cout<<+n*ist is not Fet initialiQed;

elseaAe&mptF(*);

 reaA;case @-i9(*55H:)

cout<<+n*ist is not Fet initialiQed;else

%isplaF(); reaA;case -i9(*55H:)

cout<<+n*ist is not Fet initialiQed;

else{cout<<+nGhich element Fou Iant to searchX;cin>>N;/57ind(N,*);cout<<+nhe element is at <</;

4 reaA;case E-

eNit(6);de9ault-

cout<<&nter a valid choice..;

Page 28: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 28/70

4cout<<+n&nter anF AeF to continue..;getch();clrscr();

4

4void main(){

clrscr();cout<<!!! ursor mplementation o9 *ist % !!!+n;cursor%emo o=;o=.menu();4

(ote

:. "ave oth the 9iles PcursorJeader.h and Pcursorimpl.cpp and eNecute the cpp 9ile

4.  S#AC0 A)#

a.  ARRAY IMPLEMENTATION 

#include<iostream.h>#include<conio.h>#de9ine siQe 3class stacA {

 pulic-int s[siQe];inttop,i,n;stacA(){

top5H:;4intisemptF();intis9ull();void displaF();void push(int n);void pop();

4;int stacA--isemptF(){

i9(top55H:){

return :;4else{

return 6;4

4

Page 29: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 29/70

int stacA--is9ull(){

i9(top55siQeH:){

return :;4else{

return 6;

44void stacA--push(int n){

{top;s[top]5n;cout<<+nelement<<n<<is inserted;

44void stacA--pop()

{int a;a5top;topHH;cout<<+nhe element<<s[a]<<is deleted;

4void stacA--displaF(){

i9(top55H:){

cout<<+n' &*&&'" ' "T;4

else{9or(i5top;i>56;iHH){

cout<<+n<<s[i];44

4void main(){

clrscr();stacA o=;

intch,item,n;do{

cout<<+n:.push+n2.pop+n3.displaF+n;cout<<+n&nter the choice;cin>>ch;sIitch(ch){

case :- i9(o=.is9ull())+cout<<+n"T K&07*G-'"&0'B0&' /""8*&;else{

Page 30: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 30/70

cout<<+n&nter the element to e pushed;cin>>item;o=.push(item);o=.displaF();4 reaA;

case 2- i9(o=.isemptF())cout<<+n"T $'%&07*G-%&*&' /""8*&;else

{o=.pop();o=.displaF();4 reaA;

case 3- o=.displaF(); reaA;

de9ault-cout<<+n&nter the correct option;4

4 Ihile(ch<?);getch();4

O"#P"#

rraF implementation using stacA adt:.push 2.pop 3.displaF ?.eNit&nter Four choice-:&nter the element-&lement is insersted on to the stacA :.push 2.pop 3.displaF ?.eNit

&nter Four choice-:&nter the element-@&lement @ is inserted on to the stacA :.push 2.pop 3.displaF ?.eNit&nter Four choice-3@:.push 2.pop 3.displaF ?.eNit&nter Four choice-:"tacA is over 9loI Fou cannot insert an element:.push 2.pop 3.displaF ?.eNit

&nter Four choice-2&lement is deleted 9rom the stacA :.push 2.pop 3.displaF ?.eNit&nter Four choice-3@:.push 2.pop 3.displaF ?.eNitenter Four choice-?

Page 31: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 31/70

b.  &in5ed &ist Imlementation

#include<iostream.h>#include<conio.h>struct node{

int data;node !neNt;

4!snode,!top,!temp;

class llstacA {

 pulic-int n;llstacA(){

top5'$**;4void push();void pop();void displaF();void topstacA();

4;void llstacA--push(){

cout<<+n&nter the no. o9 elements to e inserted;cin>>n;9or(inti56;i<n;i){

snode5neI node;cout<<+n&nter the element to e inserted;cin>>snodeH>data;

Page 32: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 32/70

i9(top55'$**){

snodeH>neNt5'$**;top5snode;

4else{

snodeH>neNt5top;top5snode;

44

4void llstacA--pop(){

cout<<+n%&*&';i9(top55'$**){

cout<<+nstacA under9loI;4else{

temp5top;top5topH>neNt;delete temp;

44void llstacA--displaF(){

temp5top;Ihile(tempH>neNtS5'$**){

cout<<+n<<tempH>data;temp5tempH>neNt;

4cout<<+n<<tempH>data;

4void llstacA--topstacA(){

temp5top;cout<<+nhe element is-<<tempH>data;

4void main(){

clrscr();llstacA s;

intch;do{

cout<<+n:.push+n2.pop+n3.displaF+n?.top element o9 the stacA;cout<<+nenter the choice;cin>>ch;sIitch(ch){

case :- s.push();s.displaF(); reaA;

case 2- s.pop();

Page 33: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 33/70

s.displaF(); reaA;

case 3- s.displaF(); reaA;

case ?- s.topstacA(); reaA;

de9ault- cout<<+n&nter the correct choice; reaA;

4

4Ihile(ch<@);getch();4

O"#P"#

*inAed list implememntation o9 stacA enus:.push 2.pop 3.displaF ?.top element @.eNit&nter Four choice-:&nter the no.o9 elements to e inserted-2&nter the element-2

&nter the element-:2enus:.push 2.pop 3.displaF ?.top element @.eNit&nter Four choice-3:22enus:.push 2.pop 3.displaF ?.top element @.eNit&nter Four choice-?op element is :2enus:.push 2.pop 3.displaF ?.top element @.eNit&nter Four choice -2:2 is deleted 9rom stacA enus:.push 2.pop 3.displaF ?.top element @.eNit&nter Four choice-2stacA under9loI cannot deleteenus:.push 2.pop 3.displaF ?.top element @.eNit&nter Four choice-?op element is 6

Page 34: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 34/70

enus:.push 2.pop 3.displaF ?.top element @.eNit&nter Four choice-@

6.  SO"RC' /I&'S

i) /rogram source 9ile 9or stacA application : R hecAing parenthesis#include<iostream.h>#include<conio.h>#include<stdli.h>33In!lusion o- ne!essar7 header -iles is must -or the e8e!ution o- this rogram

#de9ine "V& :6void main(){

char item;char ans,racAet["V&];stAUclass o=;int i;clrscr();cout<<!!! "T //*' : H G&** 70&% /0'J&"" !!!+n+n;cout<<+n &nter an eNpression(add Y at end) - ;cin>>racAet;i56;i9(racAet[i]55M)M)

cout<<+n &Npression never starts Iith opening paranthesis..;else{

do{

Ihile(racAet[i]55M(M){

o=.push(racAet[i]);i;

4

Page 35: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 35/70

Ihile(racAet[i]55M)M){

item5o=.pop();i;

44Ihile(racAet[i]S5MYM);i9(So=.stemptF())

cout<<+n 'o alanced paranthesis in the given eNpression;elsecout<<+n &ntered eNpression has Iell 9ormed parenthesis;

4getch();4

ii) rraF implementation o9 stacA %

"tacAar.h BB 9ile to e included 9or application : H parenthesis

#de9ine "V& :6class stAUclass{

 pulic-

char s["V&];int top;stAUclass(){

top5H:;4void push(char);int stemptF();int st9ull();char pop();

4;

void stAUclass--push(char item){

top;s[top]5item;

4int stAUclass--stemptF(){

i9(top55H:)return :;

elsereturn 6;

Page 36: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 36/70

4int stAUclass--st9ull(){

i9(top55"V&)return :;

elsereturn 6;

4

char stAUclass--pop(){char item;item5s[top];topHH;return(item);

4

"tA.h BB 9ile to e included 9or application 2 R pot 9iN eNpression evaluation

#de9ine W :6class stAUclass{

doule s[W];int top; pulic-

stAUclass(){

top56;4void push(doule val);doule pop();int isemptF();int is9ull();

4;int stAUclass--isemptF(){

i9(top55H:)return :;

elsereturn 6;

4int stAUclass--is9ull(){

i9(top55W)return :;

elsereturn 6;

Page 37: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 37/70

4void stAUclass--push(doule val){

top;s[top]5val;

4doule stAUclass--pop(){

doule val;val5s[top];topHH;return(val);

4

iii: &in5ed list imlementation o- sta!5 A)#

"tacA:.h BB 9ile to e included 9or application : H parenthesis

class stAUclass{

 private-

tFpede9 struct stacA {

char data;struct stacA ! neNt;

4node;node !top;

 pulic-stAUclass(){

top5'$**;4

void push(char item);int stemptF();void pop();

4;void stAUclass--push(char item){

node ! 'eI; 'eI5neI node;i9('eI55'$**)

cout<<+n memorF cannot e allocated +n;else

Page 38: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 38/70

{ 'eIH>data5item; 'eIH>neNt5top;top5'eI;

44int stAUclass--stemptF(){

i9(top55'$**)return :;else

return 6;4void stAUclass--pop(){

node !temp;temp5top;top5topH>neNt;delete temp;

4

"tA2.h BB 9ile to e included 9or application 2 R pot 9iN eNpression evaluation

class stAUclass{

B! data structure 9or the linAed stacA!BtFpede9 struct stacA {

char data;

struct stacA !neNt;4node; pulic-node !top;stAUclass(){

top5'$**;4void push(char item);char pop();

4;

void stAUclass--push(char item){

node !'eI; 'eI5neI node; 'eIH>data 5item; 'eIH>neNt5top;top5'eI;

4char stAUclass--pop(){

char item;

Page 39: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 39/70

node !temp;item5topH>data;temp5top;top5topH>neNt;delete temp;return item;

4

i;:Program sour!e -ile -or sta!5 ali!ation $ – ';aluating ost-i8 e8ression

#include<iostream.h>#include<conio.h>#include<stdli.h>#include<string.h>#include<math.h>33In!lusion o- ne!essar7 header -iles is must -or e8e!ution o- this rogram

#de9ine siQe D6void main(){

char eNp[siQe];int len;doule result;doule post(char eNp[]);clrscr();cout<<!!! "T //*' 2 H &K*$' 7 /"7W &W/0&""' !!!+n+n;cout<<&nter the post9iN eNpression+n;cin>>eNp;len5strlen(eNp);eNp[len]5MYM;B!append Y at the end a end marAer!Bresult5post(eNp);cout<<he value o9 the eNpression is <<result;getch();eNit(6);

4doule post(char eNp[]){

stAUclass o=;char ch,!tFpe;

Page 40: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 40/70

doule result ,val,op:,op2;int i;i56;ch5eNp[i];Ihile(chS5MYM){

i9(ch>5M6MLLch<5MCM)tFpe5operand;

else i9(ch55MMZZch55MHMZZch55MMZZch55M!MZZch55MBM)tFpe5operator;i9(strcmp(tFpe,operand)556)B! i9 the character is operator!B{

val5chH?D;o=.push(val);

4else i9(strcmp(tFpe,operator)556)B! i9 it is operator!B{

op25o=.pop();op:5o=.pop();

sIitch(ch){case MM-result5op:op2; reaA;case MHM-result5op:Hop2; reaA;case M!M-result5op:!op2; reaA;case MBM- result5op:Bop2; reaA;case MM-result5poI(op:,op2);

 reaA;4o=.push(result);

4i;ch5eNp[i];

4resultHo=.pop();B!pop the result!Breturn(result);

4

9;: Program using sta!5 header -iles

7or the program code (i) and (iv), include the header 9iles o9 (ii) and (iii) 9or its eNecution.

Page 41: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 41/70

<.  Sta!5 Ali!ation – In-i8 to Post-i8 Con;ersion

a.  "tacA % implemented as 00\"

#include<iostream.h>#include<conio.h>#include<string.h>#de9ine W 26

class intopo{ pulic-char stacA[W];int top;intopo(){

top5H:;4char pop();void push(char item);int prcd(char);int isoperator();int isoperator(char);void convertip(char[],char[]);

4;int intopo--prcd(char sFmol){

sIitch(sFmol){

case MM-case MHM-return 2;

Page 42: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 42/70

case M!M-case MBM-return ?;case MM-return ;case M(M-case M)M-case M#M-return :;

44

int intopo--isoperator(char sFmol){sIitch(sFmol){

case MM-case MHM-case M!M-case MBM-case MM-case M(M-case M)M-return :;

de9ault-return 6;44void intopo--push(char item){

top;stacA[top]5item;

4char intopo--pop(){

char a;

a5stacA[top];topHH;return a;

4void intopo--convertip(char in9iN[],char post9iN[]){

int i,sFmol,=56;stacA[top]5M#M;9or(i56;i<strlen(in9iN);i){

sFmol5in9iN[i];i9(isoperator(sFmol)556){

 post9iN[=]5sFmol; =;

4else{

i9(sFmol55M(M) push(sFmol);

else i9(sFmol55M)M){

Page 43: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 43/70

Ihile(stacA[top]S5M(M){

 post9iN[=]5pop(); =;

4 pop();BBpop out (.

4else

{ i9(prcd(sFmol)>prcd(stacA[top])) push(sFmol);

else{

Ihile(prcd(sFmol)<5prcd(stacA[top])){

 post9iN[=]5pop(); =;

4 push(sFmol);

444

4Ihile(stacA[top]S5M#M){

 post9iN[=]5pop(); =;

4 post9iN[=]5M+6M;BBnull terminate string.

4

void main(){char in9iN[26],post9iN[26];clrscr();intopo in;cout<<!!! n9iN to post9iN conversion using stacA arraF !!!+n;cout<<&nter the valid in9iN string- ;cin>>in9iN;in.convertip(in9iN,post9iN);cout<<he corresponding post9iN string is- P;cout<<post9iN;getch();

4

O"#P"# – !omilation1

!!! n9iN to post9iNconversion using stacAarraF !!!&nter the valid in9iNstring- ?@!HE

he corresponding post9iNstring is- ?@!EH

O"#P"# – !omilation

$

!!! n9iN to post9iNconversion using stacAarraF !!!&nter the valid in9iNstring-a!cHd

he corresponding post9iNstring is- ac!dH

Page 44: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 44/70

 .  "tacA % implemented as *'T&% *"

#include<iostream.h>#include<conio.h>#include<string.h>class intopo{

 pulic-struct stacA {

int data;struct stacA !neNt;

4!top,!nnode;intopo(){

top5'$**;4char pop();void push(char item);int prcd(char);int isoperator();int isoperator(char);void convertip(char[],char[]);

4;int intopo--prcd(char sFmol){

sIitch(sFmol){

case MM-case MHM-return 2;

Page 45: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 45/70

case M!M-case MBM-return ?;case MM-return ;case M(M-case M)M-case M#M-return :;

44

int intopo--isoperator(char sFmol){sIitch(sFmol){

case MM-case MHM-case M!M-case MBM-case MM-case M(M-case M)M-return :;

de9ault-return 6;44void intopo--push(char item){

nnode5neI stacA;nnodeH>data5item;nnodeH>neNt5'$**;i9(top55'$**)

top5nnode;else

{ nnodeH>neNt5top;top5nnode;

44char intopo--pop(){

char a;a5topH>data;nnode5top;top5topH>neNt;delete nnode;return a;

4void intopo--convertip(char in9iN[],char post9iN[]){

int i,sFmol,=56;nnode5neI stacA;nnodeH>data5M#M;nnodeH>neNt5top;top5nnode;9or(i56;i<strlen(in9iN);i)

Page 46: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 46/70

{sFmol5in9iN[i];i9(isoperator(sFmol)556){

 post9iN[=]5sFmol; =;

4else

{ i9(sFmol55M(M) push(sFmol);

else i9(sFmol55M)M){

Ihile(topH>dataS5M(M){

 post9iN[=]5pop(); =;

4 pop();BBpop out (.

4else{

i9(prcd(sFmol)>prcd(topH>data)) push(sFmol);

else{

Ihile(prcd(sFmol)<5prcd(topH>data)){

 post9iN[=]5pop(); =;

4 push(sFmol);4

44

4Ihile(topH>dataS5M#M){

 post9iN[=]5pop(); =;

4 post9iN[=]5M+6M;BBnull terminate string.

4void main(){

char in9iN[26],post9iN[26];clrscr();intopo in;cout<<!!! n9iN to post9iN conversion using linAed stacA !!!+n;cout<<&nter the valid in9iN string- ;cin>>in9iN;in.convertip(in9iN,post9iN);

Page 47: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 47/70

cout<<he corresponding post9iN string is- ;cout<<post9iN;getch();

4

=.  S#AC0 APP&ICA#IO( – S#RI(G R'>'RS'

a. A$$a* I+,%!+!(-a-'&(

#include<string.h>#include<iostream.h>#include<conio.h>#de9ine W :66

class stacA%emo{

 pulic-int top,i,len;char "tacA[W];void get%ata();void push(char);void displaF();char pop();

4;void stacA%emo -- push(char N){

 i9(top55WH:) {

 cout<<stacA over9loI+n; return;

4 "tacA[top]5N; return;

4char stacA%emo -- pop(void)

O"#P"# – !omilation

1

!!! n9iN to post9iNconversion using linAedstacA !!!&nter the valid in9iNstring- ?@!HE

he corresponding post9iNstring is- ?@!EH

O"#P"# – !omilation

$

!!! n9iN to post9iNconversion using linAedstacA !!!&nter the valid in9iNstring- a!cHd

he corresponding post9iNstring is- ac!dH

Page 48: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 48/70

{ char F; F5"tacA[top]; "tacA[topHH]56; return F;

4

void stacA%emo -- get%ata()

{ char stA[26];cout<<+n&nter the string - ;cin>>stA;len5strlen(stA);9or(i56;i<len;i) push(stA[i]);

4void stacA%emo -- displaF(){

cout<<+nhe reversed string is -;

9or(i56;i<len;i)cout<<pop();4int main(){

char "tacA[W];clrscr();stacA%emo o=;cout<<!!! "T //*' H "0'1 0&K&0"& !!! +n;o=.get%ata();o=.displaF();

getch();return 6;4

O"#P"#

!!! "T//*' H"0'10&K&0"& !!!

&nter the string -stacA application

he reversedstring is -noitacilppa Acats

Page 49: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 49/70

b.  L'(! L'/- I+,%!+!(-a-'&(

#include<iostream.h>#include<conio.h>#include<string.h>struct node{

char data;

node !neNt;4!snode,!top,!temp;class llstacA {

 pulic-int n;char stA[26];llstacA(){

top5'$**;4void push(char);char pop();void displaF();void get%ata();

4;

void llstacA--push(char c){

snode5neI node;snodeH>data5c;i9(top55'$**)

Page 50: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 50/70

{snodeH>neNt5'$**;top5snode;

4else{

snodeH>neNt5top;top5snode;

44char llstacA--pop(){

char ch;i9(topS5'$**){

temp5top;top5topH>neNt;ch5tempH>data;return (ch);

44

void llstacA--displaF(){

temp5top;cout<<+nhe reversed string is - ;Ihile(tempS5'$**){

cout<<tempH>data;temp5tempH>neNt;

44void llstacA -- get%ata(){

cout<<+n&nter the string - ;cin>>stA;int len5strlen(stA);9or(int i56;i<len;i)

 push(stA[i]);4void main(){

clrscr();llstacA s;cout<<!!! *inAed stacA implementation H "tring 0everse !!!+n;s.get%ata();s.displaF();getch();

4

Page 51: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 51/70

?.  S#AC0 APP&ICA#IO( 9'@PR'SSIO( CO(>'RSIO(: – I(/I@ #O PR'/I@

a. rraF mplementation

#include<string.h>#include<iostream.h>#include<ctFpe.h>#include<conio.h>#include stacAar.h

class in9iN{ pulic-char in9N[@6],pr9N[@6],ch,elem;int i,A;in9iN(){

i56;A56;

4int pr(char);void get%ata();void displaF();

4;int in9iN--pr(char elem){  sIitch(elem)  {  case M#M- return 6;  case M)M- return :;  case MM-

O"#P"#

!!! *inAed stacAimplementation R 

"tring 0everse !!!

&nter the string -stacA application

he reversedstring is -noitacilppa Acats

Page 52: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 52/70

  case MHM- return 2;  case M!M-  case MBM- return 3;  44void in9iN--get%ata(){

cout<<+n+n&nter the n9iN &Npression - ;

cin>>in9N; push(M#M);strrev(in9N);Ihile( (ch5in9N[i]) S5 M+6M){ h(ch);[H

else i9(isalnum(ch)) pr9N[A]5ch;else i9( ch 55 M(M){  Ihile( s[top] S5 M)M)

  e( pr(s[top]) >5 pr(ch) )

pr9N[A]5pop(); push(ch);4

  4  Ihile( s[top] S5 M#M)

 pr9N[A]5pop();  pr9N[A]5M+6M;  strrev(pr9N);  strrev(in9N);

cout<<+n+n1iven n9iN &Npression- <<in9N<< /re9iN &Npression- <<pr9N;4

void main(){

clrscr();cout<<!!! "tacA pplication H n9iN to pre9iN conversion using stacA arraF !!!+n;in9iN o=;stacA st;

o=.get%ata();getch();

4

O"#P"#

!!! "tacApplication H n9iNto pre9iNconversion usingstacA arraF !!!

&nter the n9iN&Npression - a

1iven n9iN&Npression- a /re9iN&Npression- a

Page 53: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 53/70

 . *inAed *ist mplementation

#de9ine "V& 26#include<string.h>#include<iostream.h>#include<ctFpe.h>#include<conio.h>

class in9iN{ pulic-char in9N[@6],pr9N[@6],ch,elem;int i,A;struct node{

char data;struct node !neNt;

4!top,!snode;in9iN(){

top5'$**;i56;A56;

4void push(char);char pop();int pr(char);void get%ata();void displaF();

Page 54: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 54/70

4;void in9iN -- push(char elem){

snode5neI node;snodeH>data5elem;snodeH>neNt5'$**;i9(top55'$**)

top5snode;

else{snodeH>neNt5top;top5snode;

44char in9iN -- pop(){  char c;  c5topH>data;  top5topH>neNt;

  return c;4

int in9iN--pr(char elem){  sIitch(elem)  {  case M#M- return 6;  case M)M- return :;  case MM-  case MHM- return 2;

  case M!M-  case MBM- return 3;  44void in9iN--get%ata(){

cout<<+n+n0ead the n9iN &Npression - ;cin>>in9N; push(M#M);strrev(in9N);Ihile( (ch5in9N[i]) S5 M+6M){

i9( ch 55 M)M) push(ch);else i9(isalnum(ch)) pr9N[A]5ch;else i9( ch 55 M(M){  Ihile( topH>data S5 M)M)

 pr9N[A]5pop();  elem5pop(); B! 0emove ) !B4else{

Page 55: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 55/70

Ihile( pr(topH>data) >5 pr(ch) ) pr9N[A]5pop(); push(ch);

4  4  Ihile( topH>data S5 M#M)

 pr9N[A]5pop();  pr9N[A]5M+6M;

  strrev(pr9N);  strrev(in9N);  cout<<+n+n1iven n9iN &Npression- <<in9N<< /re9iN &Npression- <<pr9N;4

void main(){

clrscr();cout<<!!! "tacA pplication H n9iN to pre9iN conversion using linAed stacA!!!+n;in9iN o=;o=.get%ata();

getch();4

O"#P"#

!!! "tacApplication H n9iNto pre9iN

conversion usinglinAed stacA!!!

&nter the n9iN&Npression - a

1iven n9iN&Npression- a /re9iN&Npression- a

Page 56: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 56/70

1.  "'"' A)#

a.  A$$a* I+,%!+!(-a-'&(

#include<iostream.h>#include<conio.h>#de9ine "V& @class arrueue

{  pulic-int ["V&],9ront,rear,i,n,N,a;arrueue(){

9ront56;rear5H:;

4void creation();void deueue();void displaF();void 9iueue();

4;void arrueue--creation(){

i9(rear55"V&){

cout<<K&07*G;4else

Page 57: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 57/70

{cout<<&nter the variale;cin>>N;rear;[rear]5N;

44void arrueue--deueue()

{ i9(9ront55"V&){

cout<<+n$'%&07*G;4else{

[a]5[9ront];9ront;cout<<+nhe element<<[a]<<is deleted;

4

4void arrueue--displaF(){

9or(i59ront;i<5rear;i){

cout<<+n<<[i];4

4void arrueue--9iueue(){

cout<<+n<<[9ront]<<is the 9irst element in the ueue;

4void main(){

clrscr();intch;arrueue a;do{

cout<<+n:.enueue+n2.deueue+n3.displaF+n?.9irst element in ueue;cout<<+n&nter the choice;cin>>ch;sIitch(ch){

case :-a.creation(); reaA;

case 2-a.deueue(); reaA;

case 3-a.displaF(); reaA;

case ?-a.9iueue(); reaA;

de9ault-cout<<+n&nter the correct choice;

Page 58: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 58/70

 reaA;4

4Ihile(ch<@);getch();4

b.  L'(! L'/- I+,%!+!(-a-'&(

#include<iostream.h>#include<conio.h>struct node{

int data;node! neNt;

4!9ront,!rear,!node,!temp;class ueuel{

 pulic-intn,i;ueuel(){

9ront5'$**;4void enueue();void deueue();void displaF();void 9iueue();

4;void ueuel--enueue(){

cout<<+n&nter the no. o9 elements;cin>>n;9or(i56;i<n;i){

node5neI node;cout<<+n&nter the data;

Page 59: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 59/70

cin>>nodeH>data;nodeH>neNt5'$**;{

i9(9ront55'$**){

9ront5node;rear5node;

4

else{rearH>neNt5node;rear5node;

44

44void ueuel--deueue(){

temp59ront;

9ront59rontH>neNt;cout<<+nhe element<<+t<<tempH>data<<+t<<is deleted;delete temp;

4void ueuel--displaF(){

temp59ront;

Ihile(tempS5'$**){

cout<<+n<<tempH>data;

temp5tempH>neNt;44void ueuel--9iueue(){

temp59ront;cout<<+nhe 9irst element o9 the ueue is<<+t<<tempH>data;

4void main(){

clrscr();intch;ueuel s;do{

cout<<+n:.&nueue+n2.%eueue+n3.%isplaF+n?.7irst element;cout<<+n&nter the choice;cin>>ch;sIitch(ch){

case :- s.enueue(); reaA;

Page 60: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 60/70

case 2- s.deueue(); reaA;

case 3- s.displaF(); reaA;

case ?- s.9iueue(); reaA;

de9ault- cout<<+nIrong numer; reaA;

44Ihile(ch<);getch();4

11. S'ARC% #R'' A)# – BI(AR S'ARC% A)#

#include<iostream.h>

#include<stdli.h>

#include<conio.h>

struct node

{

int in9o;

struct node !le9t;

struct node !right;

4!root;

class 8"

{

 pulic-

void 9ind(int, node !!, node !!);

void insert(node !, node !);

void del(int);

void caseUa(node !,node !);void caseU(node !,node !);

void caseUc(node !,node !);

void preorder(node !);

void inorder(node !);

void postorder(node !);

void displaF(node !, int);

8"()

{

Page 61: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 61/70

  root 5 '$**;

4

4;

int main()

{

  int choice, num;

  clrscr();  8" st;

  node !temp;

  Ihile (:)

  {

cout<<:.nsert &lement <<endl;

cout<<2.%elete &lement <<endl;

cout<<3.norder raversal<<endl;

cout<<?./reorder raversal<<endl;

cout<<@./ostorder raversal<<endl;

cout<<.%isplaF<<endl;cout<<E.^uit<<endl;

cout<<&nter Four choice - ;

cin>>choice;

sIitch(choice)

{

case :-

  temp 5 neI node;

  cout<<&nter the numer to e inserted - ;

  cin>>tempH>in9o;

  st.insert(root, temp);

  reaA;

case 2-

  i9 (root 55 '$**)

  {

cout<<ree is emptF, nothing to delete<<endl;

continue;

  4

  cout<<&nter the numer to e deleted - ;

  cin>>num;  st.del(num);

  reaA;

case 3-

  cout<<norder raversal o9 8"-<<endl;

  st.inorder(root);

  cout<<endl;

  reaA;

case ?-

Page 62: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 62/70

  cout<</reorder raversal o9 8"-<<endl;

  st.preorder(root);

  cout<<endl;

  reaA;

case @-

  cout<</ostorder raversal o9 8"-<<endl;

  st.postorder(root);

  cout<<endl;  reaA;

case -

  cout<<%isplaF 8"-<<endl;

  st.displaF(root,:);

  cout<<endl;

  reaA;

case E-

  eNit(:);

de9ault-

  cout<<Grong choice<<endl;4

getch();

clrscr();

  4

4

void 8"--9ind(int item, node !!par, node !!loc)

{

node !ptr, !ptrsave;

i9 (root 55 '$**)

{

!loc 5 '$**;

!par 5 '$**;

return;

4

i9 (item 55 rootH>in9o)

{

!loc 5 root;

!par 5 '$**;

return;4

i9 (item < rootH>in9o)

 ptr 5 rootH>le9t;

else

 ptr 5 rootH>right;

 ptrsave 5 root;

Ihile (ptr S5 '$**)

{

Page 63: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 63/70

i9 (item 55 ptrH>in9o)

{

!loc 5 ptr;

!par 5 ptrsave;

  return;

4

 ptrsave 5 ptr;

i9 (item < ptrH>in9o) ptr 5 ptrH>le9t;

else

 ptr 5 ptrH>right;

4

!loc 5 '$**;

!par 5 ptrsave;

4

void 8"--insert(node !tree, node !neInode)

{i9 (root 55 '$**)

{

root 5 neI node;

rootH>in9o 5 neInodeH>in9o;

rootH>le9t 5 '$**;

rootH>right 5 '$**;

cout<<0oot 'ode is dded<<endl;

return;

4

i9 (treeH>in9o 55 neInodeH>in9o)

{

cout<<&lement alreadF in the tree<<endl;

return;

4

 i9 (treeH>in9o > neInodeH>in9o)

{

i9 (treeH>le9t S5 '$**)

{

insert(treeH>le9t, neInode);4

else

{

treeH>le9t 5 neInode;

(treeH>le9t)H>le9t 5 '$**;

(treeH>le9t)H>right 5 '$**;

 cout<<'ode dded o *e9t<<endl;

 return;

Page 64: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 64/70

4

  4

  else

{

i9 (treeH>right S5 '$**)

{

  insert(treeH>right, neInode);

4else

{

  treeH>right 5 neInode;

  (treeH>right)H>le9t 5 '$**;

  (treeH>right)H>right 5 '$**;

  cout<<'ode dded o 0ight<<endl;

  return;

4

  4

4void 8"--del(int item)

{

node !parent, !location;

i9 (root 55 '$**)

{

cout<<ree emptF<<endl;

return;

4

9ind(item, Lparent, Llocation);

i9 (location 55 '$**)

{

cout<<tem not present in tree<<endl;

return;

4

i9 (locationH>le9t 55 '$** LL locationH>right 55 '$**)

caseUa(parent, location);

i9 (locationH>le9t S5 '$** LL locationH>right 55 '$**)

caseU(parent, location);

  i9 (locationH>le9t 55 '$** LL locationH>right S5 '$**)caseU(parent, location);

  i9 (locationH>le9t S5 '$** LL locationH>right S5 '$**)

caseUc(parent, location);

  9ree(location);

4

void 8"--caseUa(node !par, node !loc )

{

i9 (par 55 '$**)

Page 65: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 65/70

{

root 5 '$**;

4

else

{

i9 (loc 55 parH>le9t)

 parH>le9t 5 '$**;

else parH>right 5 '$**;

4

4

void 8"--caseU(node !par, node !loc)

{

node !child;

  i9 (locH>le9t S5 '$**)

child 5 locH>le9t;

  else

child 5 locH>right;  i9 (par 55 '$**)

  {

root 5 child;

  4

  else

  {

i9 (loc 55 parH>le9t)

  parH>le9t 5 child;

else

  parH>right 5 child;

  4

4

void 8"--caseUc(node !par, node !loc)

{

node !ptr, !ptrsave, !suc, !parsuc;

 ptrsave 5 loc;

 ptr 5 locH>right;

Ihile (ptrH>le9t S5 '$**)

{ ptrsave 5 ptr;

 ptr 5 ptrH>le9t;

4

suc 5 ptr;

 parsuc 5 ptrsave;

 i9 (sucH>le9t 55 '$** LL sucH>right 55 '$**)

caseUa(parsuc, suc);

else

Page 66: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 66/70

caseU(parsuc, suc);

 i9 (par 55 '$**)

root 5 suc;

else

{

i9 (loc 55 parH>le9t)

 parH>le9t 5 suc;

else parH>right 5 suc;

  4

  sucH>le9t 5 locH>le9t;

  sucH>right 5 locH>right;

4

void 8"--preorder(node !ptr)

{

i9 (root 55 '$**)

{

cout<<ree is emptF<<endl;return;

  4

  i9 (ptr S5 '$**)

  {

cout<<ptrH>in9o<< ;

 preorder(ptrH>le9t);

 preorder(ptrH>right);

  4

4

void 8"--inorder(node !ptr)

{

i9 (root 55 '$**)

{

cout<<ree is emptF<<endl;

return;

4

i9 (ptr S5 '$**)

{

inorder(ptrH>le9t);cout<<ptrH>in9o<< ;

inorder(ptrH>right);

4

4

void 8"--postorder(node !ptr)

{

i9 (root 55 '$**)

{

Page 67: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 67/70

cout<<ree is emptF<<endl;

return;

4

i9 (ptr S5 '$**)

{

 postorder(ptrH>le9t);

 postorder(ptrH>right);

cout<<ptrH>in9o<< ;4

4

void 8"--displaF(node !ptr, int level)

{

int i;

i9 (ptr S5 '$**)

{

displaF(ptrH>right, level:);

cout<<endl;

i9 (ptr 55 root) cout<<0ootH>- ;

else

{

 9or (i 5 6;i < level;i)

cout<< ;

4

cout<<ptrH>in9o;

displaF(ptrH>le9t, level:);

  4

4

Page 68: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 68/70

1$. "IC0 SOR#

BB program to implement ^uicA sort

#include<iostream.h>

#include<conio.h>

classsort

{ pulic-

int /artition(int[],int,int);

void "ort(int[],int,int);

4;

intsort--/artition(int a[], int eg, int end)

{

int p5eg, pivot5a[eg], loc;

9or(loc5eg:;loc<5end;loc)

{

i9(pivot>a[loc])

{

a[p]5a[loc];

a[loc]5a[p:];

a[p:]5pivot;

Page 69: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 69/70

 p5p:;

4

4

return p;

4

voidsort--"ort(int a[], int eg, int end)

{

i9(eg<end)

{

int p5/artition(a,eg,end);

"ort(a,eg,pH:);

"ort(a,p:,end);

4

4

void main()

{

clrscr();

sort ;

int a[:66],i,n,eg,end;

cout<<+n!!! ^$T "0 !!!+n;

cout<<&nter the numer o9 &lements - ;cin>>n;

cout<<+n&nter the elements - +n;

9or(i5:;i<5n;i)

cin>>a[i];

 eg5:;

end5n;

."ort(a,eg,end);

cout<<+nhe sorted elements are - +n;

9or(i5:;i<5n;i)

cout<<a[i]<<+t;

getch();

4

Page 70: DeepaOOP DS Lab Manual

7/23/2019 DeepaOOP DS Lab Manual

http://slidepdf.com/reader/full/deepaoop-ds-lab-manual 70/70