ds & oops lab manual.doc

Upload: eyigeechidambaram

Post on 02-Jun-2018

245 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    1/96

    EX.NO:1.A FUNCTION WITH DEFAULT ARGUMENTS

    DATE :

    AIM:

    To write a C++ program to find the sum for the given variables using function withdefault arguments.

    ALGORITHM:

    1) Start the program.

    2) Declare the variables and functions.3) ive the values for two arguments in the function declaration itself.

    !) Call function sum") with three values such that it ta#es one default arguments.

    $) Call function sum") with two values such that it ta#es two default arguments.%) Call function sum") with one values such that it ta#es three default arguments

    $) &nside the function sum")' calculate the total.%) (eturn the value to the main") function.) Displa* the result.

    ) Stop the program.

    PROGRAM:

    1

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    2/96

    ,include-iostream.h

    ,include-conio.h

    void main")/

    float sum"float a'int b01'int c01$'int d02)

    int a02'b03'c0!'d0$clrscr")

    cout--4nsum0--sum")

    cout--4nsum0--sum"a'b'c'd)cout--4nsum0--sum"a'b'c)

    cout--4nsum0--sum"a'b)

    cout--4nsum0--sum"a)

    cout--4nsum0--sum"b'c'd)getch")

    5

    float sum"float i' int 6' int #' int l)

    /return"i+6+#+l)

    5

    OUTPUT:

    2

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    3/96

    sum0!$

    sum01!

    sum027sum0!

    sum0!

    sum032

    RESULT:

    Thus' the given program for function with default arguments has been written and e8ecutedsuccessfull*.

    EX.NO:1.B IMPLEMENTATION OF CALL BY VALUE

    DATE :

    3

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    4/96

    AIM:

    To write a C++ program to find the value of a number raised to its power that

    demonstrates a function using call b* value.

    ALGORITHM:

    1) Start the program.2) Declare the variables.

    3) et two numbers as input

    !) Call the function power to which a cop* of the two variables is passed .

    $) &nside the function' calculate the value of 8 raised to power * and store it in p.%) (eturn the value of p to the main function.

    ) Displa* the result.

    ) Stop the program.

    PROGRAM:

    ,include-iostream.h

    ,include-conio.h

    4

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    5/96

    void main")

    /

    int 8'*double power"int' int)

    clrscr")

    cout--9nter 8'*:--endlcin8*

    cout--8-- to the power --* -- is -- power"8'*)

    getch")5

    double power"int 8'int *)

    /

    double pp01.

    if"*0)

    while"*;;)

    pT9( ? ' @:

    2 32 TA TB9 A9( 3 &S

    5

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    6/96

    RESULT:

    Thus' the given program for implementation of call b* value has been written ande8ecuted successfull*.

    EX. NO: 1.C IMPLEMENTATION OF CALL BY ADDRESS

    DATE:

    AIM:

    6

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    7/96

    To write a C++ program and to implement the concept of Call b* Eddress.

    ALGORITHM:

    1. Start the program.

    2. &nclude suitable header file.3. Declare a function swap with two pointes variables arguments.

    !. Declare and initialiFe the value as two variable in main ").

    $. rint the value of two variable before swapping.%. Call the swap function b* passing address of the two variable as arguments.

    . rint the value of two variable after swapping.

    . Stop the program.

    PROGRAM:

    ,include-iostream.h

    ,include-conio.hvoid swap"int

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    8/96

    /

    clrscr")

    int i'6i01

    602

    cout--4n the value of i before swapping is:--icout--4n the value of i before swapping is:--6

    swap "Gi'G6)

    cout--4n the value of i after swapping is:--icout--4n the value of i after swapping is:--6

    getch")

    return")

    5void swap"int

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    9/96

    RESULT:

    Thus to write a c++ program and to implement the concept of Call b* Eddress wassuccessfull* completed.

    EX. NO: 2 COPY CONSTRUCTORS

    DATE:

    AIM:

    To write the c++ program and to implement the concept of cop* constructor

    ALGORITHM:

    9

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    10/96

    1. Start the program

    2. &nclude suitable header file

    3. Declare constructor with empt* arguments and another 'ob6ect as arguments!. &nitialiFe the value of a variable b* calling a constructor in main function

    $. Essign the value of one ob6ect to another ob6ect

    %. 98ecute the program. rint the statement

    . Stop the program

    PROGRAM:

    ,include-iostream.h,include-conio.hclass code

    /

    int id

    public:code")/5

    code"int a)

    10

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    11/96

    /

    5

    code"codeG8)/

    id08.id

    5void displa*"void)

    /

    cout--id5

    5

    int main")

    /clrscr")

    code a"1)

    code b"a)

    code c0acode d

    d0acout--4nid of a: a.displa*")

    cout--4nid of b: b.displa*")

    cout--4nid of c: c.displa*")cout--4nid of d: d.displa*")

    getch")

    return

    5

    OUTPUT:

    id of E:1id of H:1

    id of C:1id of D:1

    11

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    12/96

    RESULT:

    Thus to write the c++ program and implement the concept of cop* constructor was

    successfull* completed.

    EX. NO: 3.A OPERATOR OVERLOADING

    DATE:

    AIM:

    To write a c++ program to concatenate two string using the concept of operator

    Averloading.

    ALGORITHM:

    12

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    13/96

    1. Start the program

    2. &nclude suitable header file

    3. Create a class with necessar* variables and function!. et the value as two variables as concatenating

    $. Averload an operator to concatenate two string

    %. 98ecute the program. Stop the program

    PROGRAM:

    ,include-iostream.h

    ,include-string.h,include-conio.hconst int bufsiFe0$

    class string

    /

    private:char strIbufsiFeJ

    public:

    13

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    14/96

    string")

    /

    strcp*"str' )5

    string"char

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    15/96

    OUTPUT:

    Hefore str30str10str2

    str10stud

    str20entstr30

    Efterstr30str1+str2:

    str10stud

    str20ent

    str30student

    15

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    16/96

    RESULT:

    Thus to write a c++ program to concatenate two string using the concept of operator

    overloading was successfull* completed.EX.NO: 3.B UNARY OPERATOR OVERLOADING

    DATE :

    AIM:

    To perform increment and decrement operations using unar* operator overloading.

    ALGORITHM:

    1) Start the program.

    2) Create Class unar* with one constructors.3) The constructor ta#es no arguments and is used to create ob6ects that are not initialised.

    !) Declare a function operator K++L and K;; inside the class unar* which are the function

    16

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    17/96

    where overloading is done.

    $) Create an ob6ect for the class.

    %) Call the functions with declared ob6ect.) Stop the program.

    PROGRAM:

    ,include-iostream.h,include-conio.h

    class unar*

    /

    private:int 8'*'F

    public:unar*"void)

    /

    cout-- 9nter En* Three &nteger >os. :

    cin8*F5

    17

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    18/96

    void displa*"void)

    /

    cout-- endl-- The Three >os. Ere : -- 8-- ' -- *-- ' -- F5

    void operator ;;")

    /8 0 ;;8

    * 0 ;;*

    F 0 ;;F5

    void operator ++")

    /

    8 0 ++8* 0 ++*

    F 0 ++F

    5

    5void main")

    /clrscr")

    unar* s

    s.displa*");;s

    cout-- endl-- endl-- endl--

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    19/96

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    20/96

    %. 98ecute the program

    . Stop the program

    PROGRAM:

    ,include -iostream.h

    ,include-conio.h

    class comple8/

    float 8

    float *public:

    comple8")/5

    comple8"float real'float image)

    /80real

    *0image

    20

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    21/96

    5

    comple8 operator + "comple8)

    void displa*"void)5

    comple8 comple8::operator+"comple8 c)

    /comple8 temp

    temp.808+c.8

    temp.*0*+c.*return"temp)

    5

    void comple8::displa*"void)

    /cout--8--+6--*

    5

    int main")

    /clrscr")

    comple8 c1'c2'c3c10comple8"2.$'3.$)

    c20comple8"1.%'2.)

    c30c1+c2cout--c1 0

    c1.displa*")

    cout--c2 0

    c2.displa*")cout--c3 0

    c3.displa*")

    getch")return

    5

    OUTPUT:

    c102.$+63.$

    c201.%+62.c30!.1+6%.2

    21

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    22/96

    RESULT:

    Thus to write a c++ program to concatenate two string using the concept Hinar* operator

    overloading was successfull* completed.EX. NO: 3.D FUNCTION OVERLOADING

    DATE:

    AIM:To write a c++ program to find the volume using function overloading concept

    ALGORITHM:

    1. Start the program

    2. &nclude suitable header file3. Declare the function of same name with different parameter

    !. Define the function for calculating the volume

    $. Call the respective functions%. rint the volume

    7. Stop the program

    22

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    23/96

    PROGRAM:

    ,include-iostream.h

    ,include-conio.hint volume"int)

    double volume"double'int)

    long volume"long'int'int)int main")

    /

    clrscr")cout--Nvolume of cube0N

    cout--volume"1)--4n

    cout--Nvolume of c*linder0N

    cout--volume"2.$')--4ncout--Nvolume of cubiod0N

    cout--volume"1'$'1$)--4n

    23

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    24/96

    return

    getch")

    5int volume"int s)

    /

    return"s

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    25/96

    RESULT:

    Thus to write a c++ program to find the volume using function overloading concept was

    successfull* completed.EX. NO: 4.A MULTIPLE INHERITANCE

    DATE:

    AIM:

    To write a c++ program to implement the concept of multiple inheritance.

    ALGORITHM:

    1. Start the program.2. &nclude the suitable header file.

    3. create a base class O and >.!. Declare a variable m and void getm function in class O.

    $. Declare a variable n and void getn function in class >.

    %. Derive a class from the base class OG> and declare a function void displa*.. Define the function void getm 'void getn and void displa* outside their respective class.

    . et the value for the variable in getm and getn function.

    25

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    26/96

    7. Call the displa* function for displa*ing the output.

    1. Stop the program..

    PROGRAM:

    ,include-iostream.h

    class O/

    protected:

    int m

    public:void getm"int)

    5

    class >

    /protected:

    int npublic:

    void getn"int)

    5

    class :public O'public >/

    26

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    27/96

    public:

    void displa*"void)

    5void O::getm"int 8)

    /

    m085

    void >::getn"int *)

    /n0*

    5

    void ::displa*"void)

    /cout--m0--m--4n

    cout--n0--n--4n

    cout--m

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    28/96

    RESULT:

    Thus to write a c++ program for multiple inheritance was successfull* completed.

    EX. NO:4.B HYBRID INHERITANCE

    DATE:

    AIM:

    To write a c++ program to implement the concept of h*brid inheritance.

    ALGORITHM:

    1. Start the program.

    2. &nclude suitable header files.

    3. Create a base class student and sports.

    !. &n the base class student define the function void get number and put number.$. &n the base class sports define the function void get score and void put score.

    %. Derive a class test form base student and define the function get mar# and put mar#.

    . Derive a class result from test and sports class and define function void displa*.. et the value for get number' get mar#s and get score function through main function.

    7. Call the displa* function in class result.

    1. Stop the program.

    28

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    29/96

    PROGRAM:

    ,include-iostream.hclass student

    /protected:

    int rollPnumber

    public

    void getPnumber"int a)/

    rollPnumber0a

    5void putPnumber"void)

    /cout--(AQQ >A:--rollPnumber--4n5

    5

    class test :public student

    /protected:

    float part1'part2

    29

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    30/96

    public:

    void getPmar#s"float 8'float *)

    /part108

    part20*

    5void putPmar#s"void)

    /

    cout--mar#s obtined:--4n--part10--part1--4n

    --part20--part2--4n

    5

    5class sports

    /

    protected:

    float scorepublic:

    void getPscore"float s)/

    score0s

    5void putPscore"void)

    /

    cout--sports wt:--score--4n4n

    55

    class result:public test'public sports

    /float total

    public:

    void displa*"void)5

    void result::displa*"void)

    /

    total0part1+part2+scoreputPnumber")

    putPmar#s")

    putPscore")cout--total score:--total--4n

    5

    int main")/

    result studentP1

    studentP1.getPnumber"123!)

    studentP1.getPmar#s"2.$'33.)

    30

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    31/96

    studentP1.getPscore"%.)

    studentP1.displa*")

    return 5

    OUTPUT:

    (oll no: 123!

    Oar#s obtained:art102.$

    art2033

    Total score: %%.$

    31

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    32/96

    RESULT:

    Thus to write a c++ program for h*brid inheritance was successfull* completed.

    EX.NO:5 ARRAY IMPLEMENTATION OF LIST ADT

    DATE:

    AIM:To rite a C++ rogram for arra* implementation of list EDT.

    ALGORITHM:

    Step1: Create nodes first'last'ne8t'prev and cur then set the value as >RQQ.Step 2: (ead the list operation t*pe.

    step 3: &f operation t*pe is create then process the following steps.

    1. Ellocate memor* for node cur.2. (ead data in curs data area.

    3. Essign cur node as >RQQ.

    !. Essign first0last0cur.Step !: &f operation t*pe is &nsert then process the following steps.

    1. Ellocate memor* for node cur.

    2. (ead data in curs data area.

    3. (ead the position the Data to be insert.!. Evailabilit* of the position is true then assing curs node as first and first0cur.

    $. &f availabilit* of position is false then do following steps.

    Step$: &f operation t*pe is delete then do the following steps.

    32

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    33/96

    1. (ead the position .

    2. Chec# list is 9mpt* .&f it is true displa* the message Qist empt*.

    3. &f position is first.1. Essign cur as first.

    2. Essign irst as first of node.

    3. (eallocate the cur from memor*.!. &f position is last.

    Step %: &f operation is traverse.

    1. Essign current as first.2. (epeat the following steps until cursor becomes >RQQ.

    Step : Stop the program.

    PROGRAM:

    ,include-iostream.h,include-conio.h

    ,include-process.h

    void create")void insert")

    void deletion")

    void search")void displa*")

    int a'bI2J'n'd'e'f'i

    void main")

    /int c

    char g0*

    clrscr")

    do/

    cout--4n Oain Oenucout--4n 1.Create 4n 2.Delete 4n 3.Search 4n !.insert 4n $.Displa* 4n %.98it

    cout--4n enter *our choice4n

    cinc

    switch"c)/

    33

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    34/96

    case 1: create") brea#

    case 2: deletion") brea#

    case 3: search") brea#case !: insert") brea#

    case $: displa*") brea#

    case %: e8it") brea#default:

    cout--The given number is not between 1;$4n

    5cout--4nDo u want to continue 4n

    cing

    clrscr")

    5while"g00*UU g00@)

    getch")

    5

    void create")/

    cout--4n 9nter the number4ncinn

    for"i0i-ni++)

    /cinbIiJ

    5

    5

    void deletion")/

    cout--9nter the limit u want to delete 4n

    cindfor"i0i-ni++)

    /

    if"bIiJ00d)/

    bIiJ0

    5

    55

    void search")

    /cout--9nter the limit 4n

    cine

    for"i0i-ni++)/

    if"bIiJ00e)

    /

    cout--Malue found the position4n--bIiJ

    34

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    35/96

    5

    5

    5void insert")

    /

    cout--enter how man* number u want to insert 4ncinf

    for"i0i-fi++)

    /cinbIn++J

    5

    5

    void displa*")/cout--4n4n4n

    for"i0i-ni++)

    /

    cout--4n4n4n--bIiJ5

    5

    OUTPUT:

    Oain Oenu

    1.Create

    2.Delete3.Search

    !.&nsert

    $.Displa*%.98it

    9nter *our choice

    19nter the number

    2

    3

    !Do u want to continue

    n

    35

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    36/96

    RESULT:

    Thus' the arra* implementation of list EDT program has been written and e8ecuted

    successfull*.

    EX.NO:5 ARRAY IMPLEMENTATION OF LIST ADT

    DATE :

    AIM:

    To rite a C++ rogram for arra* implementation of list EDT.

    ALGORITHM:

    Step1: Create nodes first'last'ne8t'prev and cur then set the value as >RQQ.

    Step 2: (ead the list operation t*pe.Step 3: &f operation t*pe is create then process the following steps.

    1. Ellocate memor* for node cur.

    2. (ead data in curs data area.3. Essign cur node as >RQQ.

    !. Essign first0last0cur.

    Step !: &f operation t*pe is &nsert then process the following steps.1. Ellocate memor* for node cur.

    2. (ead data in curs data area.

    3. (ead the position the Data to be insert.!. Evailabilit* of the position is true then assing curs node as first and first0cur.

    $. &f availabilit* of position is false then do following steps.

    1. Essign ne8t as cur and count as Fero.

    2. (epeat the following steps until count less than postion.1 .Essign prev as ne8t

    2. >e8t as prev of node.

    3. Edd count b* one.

    36

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    37/96

    !. &f prev as >RQQ then displa* the message &>MEQ&D AS&T&A>.

    $. &f prev not Vual to >RQQ then do the following steps.

    1. Essign curs node as prevs node.2. Essign prevs node as cur.

    Step$: &f operation t*pe is delete then do the following steps.

    1. (ead the position .2. Chec# list is 9mpt* .&f it is true displa* the message Qist empt*.

    3. &f position is first.

    1. Essign cur as first.2. Essign irst as first of node.

    3. (eallocate the cur from memor*.

    !. &f position is last.

    1. Oove the current node to prev.2. curs node as >ull.

    3. (eallocate the Qast from memor*.

    !. Essign last as cur.

    $. &f position is enter Oediate.1. Oove the cur to reVuired postion.

    2. Oove the revious to curs previous position3. Oove the >e8t to curs >e8t position.

    !. >ow Essign previous of node as ne8t.

    $. (eallocate the cur from memor*.

    Step %: &f operation is traverse.

    1. Essign current as first.2. (epeat the following steps untill cur becomes >RQQ.

    Step :Stop the program.

    37

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    38/96

    PROGRAM:

    ,include-iostream.h

    ,include-conio.h,include-process.h

    void create")

    void insert")

    void deletion")void search")

    void displa*")

    int a'bI2J'n'd'e'f'ivoid main")

    /

    int cchar g0*

    clrscr")

    do

    /cout--4n Oain Oenu

    cout--4n 1.Create 4n 2.Delete 4n 3.Search 4n !.insert 4n $.Displa* 4n %.98it

    cout--4n enter *our choice4n

    cincswitch"c)

    /case 1: create") brea#

    case 2: deletion") brea#

    case 3: search") brea#

    case !: insert") brea#case $: displa*") brea#

    38

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    39/96

    case %: e8it") brea#

    default:

    cout--The given number is not between 1;$4n5

    cout--4nDo u want to continue 4n

    cingclrscr")

    5

    while"g00*UU g00@)getch")

    5

    void create")

    /cout--4n 9nter the number4n

    cinn

    for"i0i-ni++)

    /cinbIiJ

    55void deletion")

    /

    cout--9nter the limit u want to delete 4ncind

    for"i0i-ni++)

    /

    if"bIiJ00d)/

    bIiJ0

    555void search")

    /

    cout--9nter the limit 4ncine

    for"i0i-ni++)

    /

    if"bIiJ00e)/

    cout--Malue found the position4n--bIiJ

    555void insert")

    /

    cout--enter how man* number u want to insert 4ncinf

    for"i0i-fi++)

    /

    cinbIn++J

    39

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    40/96

    5

    5

    void displa*")/

    cout--4n4n4n

    for"i0i-ni++)/

    cout--4n4n4n--bIiJ

    55

    OUTPUT:

    Oain Oenu1.Create

    2.Delete

    3.Search!.&nsert

    $.Displa*

    %.98it

    9nter *our choice1

    9nter the number

    23

    !

    Do u want to continuen

    40

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    41/96

    RESULLT:

    Thus' the arra* implementation of list EDT program has been written and e8ecutedsuccessfull*.

    EX.NO: LIN!ED LIST IMPLEMENTATION OF LIST ADT

    DATE :

    AIM:

    To rite a C++ rogram for lin#ed list implementation of list EDT.

    ALGORITHM:

    Step1: Create nodes first'last'ne8t'prev and cur then set the value as >RQQ.

    Step 2: (ead the list operation t*pe.

    step 3: &f operation t*pe is create then process the following steps.1. Ellocate memor* for node cur.

    2. (ead data in curs data area.3. Essign cur lin# as >RQQ.

    !. Essign first0last0cur.Step !: &f operation t*pe is &nsert then process the following steps.

    1. Ellocate memor* for node cur.

    2. (ead data in curs data area.3. (ead the position the Data to be inserting.

    !. Evailabilit* of the position is true then assign curs lin# as first and first0cur.

    $. &f availabilit* of position is false then do following steps.1. Essign ne8t as cur and count as Fero.

    2. (epeat the following steps until count less than position.

    1 .Essign prev as ne8t2. >e8t as prev of lin#.

    3. Edd count b* one.

    !. &f prev as >RQQ then displa* the message &>MEQ&D AS&T&A>.

    $. &f prev not Vual to >RQQ then do the following steps.1. Essign curs lin# as prevs lin#.

    2. Essign prevs lin# as cur.

    Step$: &f operation t*pe is delete then do the following steps.

    41

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    42/96

    1. (ead the position .

    2. Chec# list is 9mpt* .&f it is true displa* the message Qist empt*.

    3. &f position is first.1. Essign cur as first.

    2. Essign irst as first of lin#.

    3. (eallocate the cur from memor*.!. &f position is last.

    1. Oove the current node to prev.

    2. curs lin# as >ull.3. (eallocate the Qast from memor*.

    !. Essign last as cur.

    $. &f position is enter Oediate.

    1. Oove the cur to reVuired position.2. Oove the revious to curs previous position

    3. Oove the >e8t to curs >e8t position.

    !. >ow assign previous of lin# as ne8t.

    $. (eallocate the cur from memor*.Step %: &f operation is traverse.

    1. Essign current as first.2. (epeat the following steps until cur becomes >RQQ.

    Step : Stop the program.

    42

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    43/96

    PROGRAM:

    ,include-iostream.h

    ,include-conio.h,include-stdlib.h

    class list

    /struct node

    /

    int data

    node RQQ)

    /

    p0new node

    p;data08p;lin#0>RQQ

    43

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    44/96

    5

    else

    /V0p

    while"V;lin#X0>RQQ)

    V0V;lin#t0new node

    t;data08

    t;lin#0>RQQV;lin#0t

    5

    cout--4n4n&nserted successfull* at the end..

    disp")5

    void list:: insbeg"int 8)

    /

    node

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    45/96

    cout--4n4n9lement *ou entered --8-- is not found..

    5

    void list:: delbeg")/

    cout--4n4nThe list before deletion:

    disp")node RQQ)

    /

    cout--4n4nThere is no data in the list..return

    5

    if"V;lin#00>RQQ)/

    p0V;lin#

    delete Vreturn

    5

    while"V;lin#;lin#X0>RQQ)

    V0V;lin#V;lin#0>RQQ

    return

    5list::Wlist")

    /

    node RQQ)

    /

    V0p;lin#

    45

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    46/96

    delete p

    p0V

    55

    void list::disp")

    /node RQQ)

    /

    cout--V;data--4nV0V;lin#

    55

    void list :: insne8t"int value'int position)

    /node

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    47/96

    int list::see#"int value)

    /

    node S9(T&A>

    cout--4n4n1.&nsertion at begining4n2.&nsertion at the end

    cout--4n3.&nsertion between two >odescout--4n4n9nter ur choice:

    cinps

    cout--9nter the value to insert:cinv

    switch"ps)

    /case 1:

    l.insbeg"v)

    brea#

    case 2:

    47

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    48/96

    l.inslast"v)

    brea#

    case 3:cout--4n9nter the position to insert the value:

    cinp

    l.insne8t"v'p)brea#

    default:

    cout--4nThe choice is invalidreturn

    5

    brea#

    case 2:clrscr")

    cout--4n1.Delete the first element4n2.Delete the last element

    cout--4n3.9nter the element to delete from the list

    cout--4n4n9nter ur choice:cinps

    switch"ps)/

    case 1:

    l.delbeg")cout--4nThe list after deletion:

    l.disp")

    brea#

    case 2:l.dellast")

    cout--4nThe list after deletion:

    l.disp")brea#

    case 3:

    l.disp")cout--4n9nter the element to delete :

    cinv

    l.delelement"v)

    cout--4nThe list after deletion:l.disp")

    brea#

    default:cout--4nThe option is invalid...

    brea#

    5brea#

    case 3:

    clrscr")

    l.disp")

    48

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    49/96

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    50/96

    OUTPUT:

    Singl* Qin#ed Qist1.Create

    2.&nsert

    3.Delete

    !.98it9nter @our Choice : 1

    9nter The Data: 1

    11.Create

    2.&nsert

    3.Delete!.98it

    9nter @our Choice : 2

    9nter The Data: 39nter The osition: 1

    3

    1

    1.Create2.&nsert

    3.Delete

    !.98it9nter @our Choice : 3

    9nter The osition : 2

    Qist &s 9mpt*

    50

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    51/96

    RESULT:

    Thus' the lin#ed list implementation of list EDT for singl* lin#ed list program has beenwritten and e8ecuted successfull*.

    EX.NO:7 CURSOR IMPLEMENTATION OF LIST ADT

    DATE :

    AIM:

    To rite a C++ rogram for Cursor implementation of list EDT.

    ALGORITHM:

    Step1: Create nodes first'last'ne8t'prev and cur then set the value as >RQQ.

    Step 2: (ead the list operation t*pe.

    Step 3: &f operation t*pe is create then process the following steps.

    1. Ellocate memor* for node cur.2. (ead data in curs data area.

    3. Essign cur lin# as >RQQ.!. Essign first0last0cur.

    Step !: &f operation t*pe is &nsert then process the following steps.

    1. Ellocate memor* for node cur.2. (ead data in curs data area.

    3. (ead the position the Data to be inserting.

    !. Evailabilit* of the position is true then assign curs lin# as first and first0cur.$. &f availabilit* of position is false then do following steps.

    1. Essign ne8t as cur and count as Fero.

    2. (epeat the following steps until count less than position.1 .Essign prev as ne8t2. >e8t as prev of lin#.

    3. Edd count b* one.

    !. &f prev as >RQQ then displa* the message &>MEQ&D AS&T&A>.$. &f prev not Vual to >RQQ then do the following steps.

    1. Essign curs lin# as prevs lin#.

    2. Essign prevs lin# as cur.Step$: &f operation t*pe is delete then do the following steps.

    1. (ead the position .

    2. Chec# list is 9mpt* .&f it is true displa* the message Qist empt*.

    3. &f position is first.1. Essign cur as first.

    2. Essign irst as first of lin#.

    3. (eallocate the cur from memor*.!. &f position is last.

    1. Oove the current node to prev.

    2. curs lin# as >ull.3. (eallocate the Qast from memor*.

    51

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    52/96

    !. Essign last as cur.

    $. &f position is enter Oediate.

    1. Oove the cur to reVuired position.2. Oove the revious to curs previous position

    3. Oove the >e8t to curs >e8t position.

    !. >ow assign previous of lin# as ne8t.$. (eallocate the cur from memor*.

    Step %: &f operation is traverse.

    1. Essign current as first.2. (epeat the following steps until cur becomes >RQQ.

    52

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    53/96

    PROGRAM:

    ,include-iostream.h,include-conio.h

    ,include-process.h

    ,define ma8 $struct node

    /

    int data

    int ne8t5

    t*pedef struct node >AD9

    int avail'list 0 ;1>AD9 cursIma8J

    void initial")

    /int i

    avail 0

    for"i0i-ma8;1i++)cursIiJ.ne8t0i+1

    cursIiJ.ne8t0;1

    5

    void create")/

    int n'i'item'temp

    cout--4n9nter the no of elements: cinn

    ==cout--n

    if"n0ma8)cout--4n SiFe e8ists

    else

    /

    initial")if"avail00;1)

    /

    cout--4nThere is no space to insert

    e8it")5

    list 0 availif"n00ma8;1) avail 0 ;1

    else avail0n+1

    cout--4n9nter the elements one b* one:

    for"i0i-ni++)/

    53

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    54/96

    cout--4n 9nter the --i+1--th element

    cinitem

    cout--4t==cout--item

    cursIi+1J.data0item

    5cursInJ.ne8t0;1

    5

    5void displa*")

    /

    int i

    cout--4nCursor space: cout--4n4nEvail 0 --avail-- 4t

    cout--Qist 0 --list--4n

    cout--PPPPPPPPPPPPPPP

    cout--4n DETE >9?T 4ncout--PPPPPPPPPPPPPPP

    i0while"i-ma8)

    /

    cout--4n--cursIiJ.data-- 4t --cursIiJ.ne8tcout--4nPPPPPPPPPPPPPPP

    i++

    5

    5void insbeg")

    /

    int item'icout--4n9nter the item to be inserted:

    cinitem

    ==cout--itemcout--4n

    i0avail

    avail0cursIavailJ.ne8t

    cursIiJ.data0itemcursIiJ.ne8t0cursIlistJ.ne8t

    cursIlistJ.ne8t0i

    5void insend")

    /

    int item'icout--4n9nter the item to be inserted:

    cinitem

    ==cout--item

    cout--endl

    54

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    55/96

    i0list

    while"cursIiJ.ne8tX0;1)

    i0cursIiJ.ne8tcursIiJ.ne8t0avail

    avail0cursIavailJ.ne8t

    i0cursIiJ.ne8tcursIiJ.data0item

    cursIiJ.ne8t0;1

    5void insint")

    /

    int item'i'pos'count'temp

    cout--4n9nter the item to be inserted: cinitem

    ==cout--item

    cout--endl

    cout--4n9nter the position of the item: cinpos

    ==cout--poscout--endl

    i0list

    count01while"count-pos)

    /

    i0cursIiJ.ne8t

    count0count+15

    temp0avail

    avail0cursIavailJ.ne8tcursItempJ.data0item

    cursItempJ.ne8t0cursIiJ.ne8t

    cursIiJ.ne8t0temp5

    void delbeg")

    /

    int ii0cursIlistJ.ne8t

    cursIlistJ.ne8t0cursIiJ.ne8t

    cursIiJ.ne8t0availavail0i

    cursIavailJ.data0

    if"cursIlistJ.ne8t00;1)/

    cursIlistJ.ne8t0avail

    avail0list

    list0;1

    55

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    56/96

    5

    5

    void delend")/

    int i'prev

    i0listwhile"cursIiJ.ne8tX0;1)

    /

    prev0ii0cursIiJ.ne8t

    5

    cursIprevJ.ne8t0;1

    cursIiJ.ne8t0availavail0i

    cursIavailJ.data0

    if"cursIlistJ.ne8t00;1)

    /cursIlistJ.ne8t0avail

    avail0listlist0;1

    5

    5void delint")

    /

    int pos'i'count'prev

    cout--4n9nter the position: cinpos

    ==cout--pos

    cout--endli0list

    count01

    while"count-0pos)/

    prev0i

    i0cursIiJ.ne8t

    count0count+15

    cursIprevJ.ne8t0cursIiJ.ne8t

    cursIiJ.ne8t0availavail0i

    cursIavailJ.data0

    if"cursIlistJ.ne8t00;1)/

    cursIlistJ.ne8t0avail

    avail0list

    list0;1

    56

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    57/96

    5

    5

    void main")/

    int ch

    clrscr")do

    /

    cout--4n

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    58/96

    else delend")

    brea#

    case :if"list00;1) cout--4n>o element to delete

    else delint")

    brea#case :

    displa*")

    brea#case 7:

    cout--4n9nd of the operation

    brea#

    default:cout--4n9nter onl* 1 to 7:

    5

    5while"chX07)

    5

    OUTPUT:

    Q&ST1. Create

    58

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    59/96

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    60/96

    PPPPPPPPPPPPPPP

    $ ;1

    PPPPPPPPPPPPPPPQ&ST

    1. Create

    2. &nsert at begin3. &nsert at end

    !. &nsert at intermediate

    $. Delete at begin%. Delete at end

    . Delete at intermediate

    . Displa*

    7. 98it9nter *our choice:%

    %

    Q&ST

    1. Create2. &nsert at begin

    3. &nsert at end!. &nsert at intermediate

    $. Delete at begin

    %. Delete at end. Delete at intermediate

    . Displa*

    7. 98it

    9nter *our choice:

    Cursor space:

    Evail 0 ! Qist 0 PPPPPPPPPPPPPP

    DETE >9?T

    PPPPPPPPPPPPPP 1

    PPPPPPPPPPPPPPP

    2 2

    PPPPPPPPPPPPPPP3 3

    PPPPPPPPPPPPPPP

    ! ;1PPPPPPPPPPPPPPP

    ;1

    PPPPPPPPPPPPPPPQ&ST

    1. Create

    2. &nsert at begin

    3. &nsert at end

    60

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    61/96

    !. &nsert at intermediate

    $. Delete at begin

    %. Delete at end. Delete at intermediate

    . Displa*

    7. 98it9nter *our choice:2

    2

    9nter the item to be inserted: %%

    Q&ST

    1. Create

    2. &nsert at begin3. &nsert at end

    !. &nsert at intermediate

    $. Delete at begin

    %. Delete at end. Delete at intermediate

    . Displa*7. 98it

    9nter *our choice:

    Cursor space:

    Evail 0 ;1 Qist 0

    PPPPPPPPPPPPPP

    DETE >9?TPPPPPPPPPPPPPP

    !

    PPPPPPPPPPPPPPP2 2

    PPPPPPPPPPPPPPP

    3 3PPPPPPPPPPPPPPP

    ! ;1

    PPPPPPPPPPPPPPP

    % 1PPPPPPPPPPPPPPP

    Q&ST

    1. Create2. &nsert at begin

    3. &nsert at end

    !. &nsert at intermediate$. Delete at begin

    %. Delete at end

    . Delete at intermediate

    . Displa*

    61

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    62/96

    7. 98it

    9nter *our choice:

    9nter the position: 2

    2

    Q&ST1. Create

    2. &nsert at begin

    3. &nsert at end!. &nsert at intermediate

    $. Delete at begin

    %. Delete at end

    . Delete at intermediate. Displa*

    7. 98it

    9nter *our choice:

    Cursor space:

    Evail 0 1 Qist 0 PPPPPPPPPPPPPP

    DETE >9?T

    PPPPPPPPPPPPPP !

    PPPPPPPPPPPPPPP

    ;1

    PPPPPPPPPPPPPPP3 3

    PPPPPPPPPPPPPPP

    ! ;1PPPPPPPPPPPPPPP

    % 2

    PPPPPPPPPPPPPPPQ&ST

    1. Create

    2. &nsert at begin

    3. &nsert at end!. &nsert at intermediate

    $. Delete at begin

    %. Delete at end. Delete at intermediate

    . Displa*

    7. 98it9nter *our choice:3

    3

    9nter the item to be inserted: 7

    7

    62

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    63/96

    Q&ST

    1. Create

    2. &nsert at begin3. &nsert at end

    !. &nsert at intermediate

    $. Delete at begin%. Delete at end

    . Delete at intermediate

    . Displa*7. 98it

    9nter *our choice:

    Cursor space:Evail 0 ;1 Qist 0

    PPPPPPPPPPPPPP

    DETE >9?T

    PPPPPPPPPPPPPP !

    PPPPPPPPPPPPPPP7 ;1

    PPPPPPPPPPPPPPP

    3 3PPPPPPPPPPPPPPP

    ! 1

    PPPPPPPPPPPPPPP

    % 2PPPPPPPPPPPPPPP

    Q&ST

    1. Create2. &nsert at begin

    3. &nsert at end

    !. &nsert at intermediate$. Delete at begin

    %. Delete at end

    . Delete at intermediate

    . Displa*7. 98it

    9nter *our choice:$

    Q&ST1. Create

    2. &nsert at begin

    3. &nsert at end!. &nsert at intermediate

    $. Delete at begin

    %. Delete at end

    . Delete at intermediate

    63

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    64/96

    . Displa*

    7. 98it

    9nter *our choice:

    Cursor space:

    Evail 0 ! Qist 0 PPPPPPPPPPPPPP

    DETE >9?T

    PPPPPPPPPPPPPP 2

    PPPPPPPPPPPPPPP

    7 ;1

    PPPPPPPPPPPPPPP3 3

    PPPPPPPPPPPPPPP

    ! 1

    PPPPPPPPPPPPPPP ;1

    PPPPPPPPPPPPPPPQ&ST

    1. Create

    2. &nsert at begin3. &nsert at end

    !. &nsert at intermediate

    $. Delete at begin

    %. Delete at end. Delete at intermediate

    . Displa*

    7. 98it9nter *our choice:!

    !

    9nter the item to be inserted: 2121

    9nter the position of the item: 2

    2

    Q&ST1. Create

    2. &nsert at begin

    3. &nsert at end!. &nsert at intermediate

    $. Delete at begin

    %. Delete at end. Delete at intermediate

    . Displa*

    7. 98it

    9nter *our choice:

    64

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    65/96

    Cursor space:

    Evail 0 ;1 Qist 0 PPPPPPPPPPPPPP

    DETE >9?T

    PPPPPPPPPPPPPP 2

    PPPPPPPPPPPPPPP

    7 ;1PPPPPPPPPPPPPPP

    3 !

    PPPPPPPPPPPPPPP

    ! 1PPPPPPPPPPPPPPP

    21 3

    PPPPPPPPPPPPPPP

    Q&ST1. Create

    2. &nsert at begin

    3. &nsert at end!. &nsert at intermediate

    $. Delete at begin

    %. Delete at end

    . Delete at intermediate. Displa*

    7. 98it

    9nter *our choice:7

    RESULT:

    Thus' the cursor implementation of list EDT for singl* lin#ed list program has been

    written and e8ecuted successfull*.EX.NO:" STAC! ADT# ARRAY IMPLEMENTATION

    DATE:

    AIM:

    To write a C++ rogram to Stac# EDT implementation using arra*

    ALGORITHM:

    Step 1: Define a stac# siFe.

    Step 2: (ead the stac# operation.

    65

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    66/96

    Step 3: (ead the stac# element.

    Step !: Chec# the stac# operation is ush or op.

    Step $: &f operation is push then chec# the stac# status.i. &f stac# status is over flow we canLt push the element in to stac#.

    ii. Atherwise we can add the data into stac# .

    iii. Oove top to ne8t position.Step %: Stop the program.

    PROGRAM:

    ,include-iostream.h

    ,include-conio.h,include-stdlib.h==using namespace std

    class stac#

    /

    int st#I$Jint top

    public:

    66

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    67/96

    stac#")

    /

    top0;15

    void push"int 8)

    /if"top !)

    /

    cout --stac# over flowreturn

    5

    st#I++topJ08

    cout --inserted --85

    void pop")

    /

    if"top -)/

    cout --stac# under flowreturn

    5

    cout --deleted --st#Itop;;J5

    void displa*")

    /

    if"top-)/

    cout -- stac# empt*

    return5

    for"int i0topi0i;;)

    cout --st#IiJ -- 5

    5

    main")

    /Clrscr")

    int ch

    stac# stwhile"1)

    /

    cout --4n1.push 2.pop 3.displa* !.e8it4n9nter ur choicecin ch

    switch"ch)

    /

    case 1: cout --enter the element

    67

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    68/96

    cin ch

    st.push"ch)

    brea#case 2: st.pop") brea#

    case 3: st.displa*")brea#

    case !: e8it")5

    5

    return ")5

    OUTPUT:

    1.push

    2.pop

    3.displa*

    !.e8it9nter ur choice2

    stac# under flow

    1.push

    2.pop3.displa*

    68

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    69/96

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    70/96

    RESULT:

    Thus' the stac# EDT; arra* implementation program has been written and e8ecuted

    Successfull*.

    EX.NO:$ STAC! ADT# LIN!ED LIST IMPLEMENTATION

    DATE :

    AIM:

    To rite a C++ rogram to Stac# EDT implementation using lin#ed list

    ALGORITHM:

    Step 1: create a list.

    i) Create a new empt* node top.ii) (ead the stac# element and store it in tops data area.

    iii) Essign tops lin# part as >RQQ "i.e. top;lin#0>RQQ).

    iv) Essign temp as top "i.e. temp0top).

    70

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    71/96

    Step 2: (ead ne8t stac# operation.

    i) &f it is Create then go to step1.

    ii) &f it is ush then it process following stepsa) Chec# Oain memor* for node creation.

    b) Create a new node top.

    c) (ead the stac# element and store it in tops data area.d) Essign tops lin# part as temp "i.e. top;lin#0temp).

    e) Essign temp as top "i.e. temp0top).

    iii) &f it is pop then it process following stepsa) &f top is >RQQ then displa* stac# is empt*.

    b) Atherwise assign top as temp "i.e. top0temp' bring the top to top position)

    c) Essign temp as temps lin#. "i.e. temp0temp;lin#' bring the temp to tops previous

    position).d) Delete top from memor*.

    iv) &f it is traverse then process the following steps

    a) Hring the top to stac#Ls top position"i.e. top0temp)

    b) (epeat until top becomes >RQQi) Displa* the tops data.

    ii) Essign top as tops lin# "top0top;lin#).

    PROGRAM:

    ,include-iostream.h

    ,include-conio.h,include-stdlib.h

    ==using namespace std

    class node

    /public:

    class node

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    72/96

    int tos

    public:

    stac#")/

    tos0;1

    5void push"int 8)

    /

    if "tos - )/

    head 0new node

    head;ne8t0>RQQ

    head;data08tos ++

    5

    else

    /node

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    73/96

    5

    5

    void pop")/

    node RQQ)/

    temp0temp;ne8t

    5

    temp;ne8t0>RQQ5

    5main")

    /

    Clrscr")stac# s1

    int ch

    while"1)

    /cout --4n1.RSB4n2.A4n3.D&SQE@4n!.9?&T4n enter ur choice:

    cin ch

    switch"ch)/

    case 1: cout --4n enter a element

    cin chs1.push"ch)

    brea#

    case 2: s1.pop")brea#

    case 3: s1.displa*")brea#

    case !: e8it")

    55

    return ")

    5

    73

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    74/96

    OUTPUT:

    1.RSB2.A

    3.D&SQE@

    !.9?&T

    enter ur choice:1

    enter a element23

    1.RSB

    2.A

    3.D&SQE@!.9?&T

    enter ru choice:1

    enter a element%

    74

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    75/96

    1.RSB

    2.A3.D&SQE@

    !.9?&T

    enter ru choice:3

    23 %

    1.RSB

    2.A

    3.D&SQE@

    !.9?&Tenter ru choice:2

    1.RSB

    2.A3.D&SQE@

    !.9?&Tenter ru choice:3

    23

    1.RSB

    2.A

    3.D&SQE@!.9?&T

    enter ru choice:2

    1.RSB

    2.A

    3.D&SQE@!.9?&T

    enter ru choice:2

    stac# under flow

    1.RSB

    2.A3.D&SQE@

    !.9?&T

    enter ru choice:!

    75

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    76/96

    RESULT:

    Thus' the stac# EDT; lin#ed list implementation program has been written and e8ecutedSuccessfull*.

    EX.NO: 1%.1 &UEUE ADT# ARRAY IMPLEMENTATION

    DATE:

    AIM:

    To write a C++ program to Yueue EDT implementation using arra*

    ALGORITHM:

    Step 1: &nitialiFe the Vueue variables front 0 and rear 0 ;1

    Step 2: (ead the Vueue operation t*pe.

    Step 3: Chec# the Vueue operations status.i). &f it is &nsertion then do the following steps

    1. Chec# rear - VueuePsiFe is true increment the rear b* one and read the Vueue

    element and also displa* Vueue. otherwise displa* the Vueue is full.

    2. o to step2.ii). &f it is deletion then do the following steps

    1. Chec# rear- front is true then displa* the Vueue is empt*.

    2. Oove the elements to one step forward "i.e. move to previous inde8 ).

    76

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    77/96

    3. Decreases the rear value b* one "rear0rear;1).

    !. Displa* Vueue

    $. o to step2.

    PROGRAM:

    ,include-iostream.h

    ,include-conio.h

    ,include-stdlib.h==using namespace std

    class Vueue

    /

    int Vueue1I$Jint rear'front

    public:

    Vueue")/

    rear0;1

    front0;15

    void insert"int 8)

    /

    if"rear !)

    77

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    78/96

    /

    cout --Vueue over flow

    front0rear0;1return

    5

    Vueue1I++rearJ08cout --inserted --8

    5

    void delet")/

    if"front00rear)

    /

    cout --Vueue under flowreturn

    5

    cout --deleted --Vueue1I++frontJ

    5void displa*")

    /if"rear00front)

    /

    cout -- Vueue empt*return

    5

    for"int i0front+1i-0reari++)

    cout --Vueue1IiJ-- 5

    5

    main")/

    Clrscr")

    int chVueue Vu

    while"1)

    /

    cout --4n1.insert 2.delet 3.displa* !.e8it4n9nter ur choicecin ch

    switch"ch)

    /case 1: cout --enter the element

    cin ch

    Vu.insert"ch)brea#

    case 2: Vu.delet") brea#

    case 3: Vu.displa*")brea#

    case !: e8it")

    78

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    79/96

    5

    5

    return ")5

    OUTPUT:

    1.insert

    2.delete3.displa*

    !.e8it

    9nter ur choice1

    enter the element21

    inserted21

    1.insert

    2.delete

    3.displa*

    !.e8it9nter ur choice1

    enter the element22

    inserted22

    1.insert2.delet

    79

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    80/96

    3.displa*

    !.e8it

    9nter ur choice1

    enter the element1%

    inserted1%

    1.insert

    2.delete3.displa*

    !.e8it

    9nter ur choice3

    21 22 1%

    1.insert

    2.delet3.displa*

    !.e8it9nter ur choice2

    deleted21

    1.insert

    2.delet

    3.displa*!.e8it

    9nter ur choice3

    22 1%

    1.insert2.delet

    3.displa*

    !.e8it

    9nter ur choice :!

    80

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    81/96

    RESULT:

    Thus' the Vueue EDT; arra* implementation program has been written and e8ecutedsuccessfull*.

    EX.NO:1%.2 &UEUE ADT# LIN!ED LIST IMPLEMENTATION

    DATE:

    AIM:

    To rite a C++ rogram to Yueue EDT implementation using lin#ed list

    ALGORITHM:

    Step 1: &nitialiFe the Vueue variables front 0 and rear 0 ;1

    Step 2: (ead the Vueue operation t*pe.

    Step 3: Chec# the Vueue operations status.i). &f it is &nsertion then do the following steps

    3. Chec# rear not eVual to null is true increment the rear b* one and read the Vueue

    element and also displa* Vueue. otherwise displa* the Vueue is full.!. o to step2.

    ii). &f it is deletion then do the following steps

    %. Chec# rear- front is true then displa* the Vueue is empt*.

    . Oove the elements to one step forward "i.e. move to previous inde8 ).. Decreases the rear value b* one "rear0rear;1).

    7. Displa* Vueue

    1. o to step2.

    81

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    82/96

    PROGRAM:

    ,include-iostream.h,include-conio.h

    ,include-stdlib.h

    ==using namespace stdclass node

    /

    public:class node

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    83/96

    if "rare - )

    /

    head 0new nodehead;ne8t0>RQQ

    head;data08

    rare ++5

    else

    /node

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    84/96

    cout --Vueue under flow

    return

    5if"front 00 rare)

    /

    front 0 rare 0;1head0>RQQ

    return

    5front++

    head0head;ne8t

    5

    5main")

    /

    Clrscr")

    Vueue s1int ch

    while"1)/

    cout --4n1.RSB4n2.A4n3.D&SQE@4n!.9?&T4n enter ru choice:

    cin chswitch"ch)

    /

    case 1:

    cout --4n enter a elementcin ch

    s1.push"ch) brea#

    case 2: s1.pop")brea#case 3: s1.displa*")brea#

    case !: e8it")

    55

    return ")

    5

    84

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    85/96

    OUTPUT:

    1.RSB

    2.A

    3.D&SQE@!.9?&T

    enter ru choice:1

    enter a element23

    1.RSB

    2.A3.D&SQE@

    !.9?&T

    enter ru choice:1

    enter a element$!

    1.RSB

    2.A

    3.D&SQE@!.9?&T

    enter ru choice:3

    23 $!

    85

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    86/96

    1.RSB

    2.A3.D&SQE@

    !.9?&T

    enter ru choice:2

    1.RSB

    2.A3.D&SQE@

    !.9?&T

    enter ru choice:2

    1.RSB

    2.A

    3.D&SQE@

    !.9?&Tenter ru choice:2

    Vueue under flow

    1.RSB

    2.A

    3.D&SQE@

    !.9?&Tenter ur choice:!

    86

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    87/96

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    88/96

    PROGRAM:

    ,include-iostream.h

    ,include-conio.h,include-stdlib.h

    ==using namespace std

    void insert"int'int )void delte"int)

    void displa*"int)

    int search"int)int search1"int'int)

    int treeI!J't01's'8'i

    main")

    /clrscr")

    int ch'*

    for"i01i-!i++)treeIiJ0;1

    while"1)

    /

    cout --1.&>S9(T4n2.D9Q9T94n3.D&SQE@4n!.S9E(CB4n$.9?&T4n9nter *ourchoice:

    cin chswitch"ch)

    /

    case 1:

    cout --enter the element to insertcin ch

    88

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    89/96

    insert"1'ch)

    brea#

    case 2:cout --enter the element to delete

    cin 8

    *0search"1)if"*X0;1) delte"*)

    else cout--no such element in tree

    brea#case 3:

    displa*"1)

    cout--4n

    for"int i0i-032i++)cout --i

    cout --4n

    brea#

    case !:cout --enter the element to search:

    cin 8*0search"1)

    if"* 00 ;1) cout --no such element in tree

    else cout --8 -- is in --* --positionbrea#

    case $:

    e8it")

    55

    5

    void insert"int s'int ch )/

    int 8

    if"t001)/

    treeIt++J0ch

    return

    580search1"s'ch)

    if"treeI8Jch)

    treeI2

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    90/96

    treeI8J0;1

    else if"treeI2

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    91/96

    /

    cout --no element in tree

    return ;15

    if"treeIsJ00;1)

    return s=2if"treeIsJ ch)

    search1"2S9(T2.D9Q9T9

    3.D&SQE@

    !.S9E(CB$.9?&T

    9nter *our choice:3

    no element in tree:123!$%71112131!1$1%111722122232!2$2%222733132

    1. &>S9(T2.D9Q9T9

    3.D&SQE@

    !.S9E(CB$.9?&T

    9nter *our choice:1

    9nter the element to insert 1

    1.&>S9(T

    2.D9Q9T9

    3.D&SQE@!.S9E(CB

    $.9?&T9nter *our choice: !

    9nter the element to search: 1

    1 is in 1 position

    91

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    92/96

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    93/96

    PROGRAM:

    ,include-iostream.h

    ,include-conio.hclass YuiSort

    /

    int i'6'pivotpublic:

    int n'aI2J

    void Vuic#"int aIJ'int left'int right)

    void swap"int aIJ'int i'int 6)5

    void YuiSort :: Vuic#"int aIJ'int first'int last)

    /if"first-last)

    /

    pivot0aIfirstJi0first

    60last

    while"i-6)

    /while"aIiJ-0pivotGGi-last)

    i++

    while"aI6J0pivotGG6first)

    6;;if"i-6)

    swap"a'i'6)5

    swap"a'first'6)

    Vuic#"a'first'6;1)

    Vuic#"a'6+1'last)5

    93

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    94/96

    5

    void YuiSort :: swap"int aIJ'int i'int 6)

    /int temp

    temp0aIiJ

    aIiJ0aI6JaI6J0temp

    5

    void main")/

    YuiSort ob6

    clrscr")

    cout--4n4nYR&CZ SA(Tcout--4n4n9nter the limit :

    cinob6.n

    clrscr")

    cout--4n4n9nter the element4n4nfor"int i0i-ob6.ni++)

    cinob6.aIiJob6.Vuic#"ob6.a''ob6.n;1)

    cout--4n4nThe sorted list is 4n4n

    for"i0i-ob6.ni++)cout--ob6.aIiJ--

    getch")

    5

    94

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    95/96

    OUTPUT:

    9nter the limit: $

    9nter the elements$

    !3

    2

    1

    The sorted list is1 2 3 ! $

    95

  • 8/11/2019 DS & OOPS LAB MANUAL.doc

    96/96

    RESULT:

    Thus' the Vuic# sort program has been written and e8ecuted successfull*.