ca i journal

Upload: anandnilewar

Post on 07-Apr-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 CA I Journal

    1/60

    Sr

    .

    No

    Name of Experiment Page No. Date Grade Signature

    1 Write algorithm and performprogramming using simple

    numeric computations.2 Write algorithm and perform

    programming using compound

    statement (if, else)

    3 Write algorithm and perform

    programming using compound

    statement (loop)

    4 Write algorithm and perform

    programming for seriescalculation

    5 Write algorithm and perform

    programming using function6 Write algorithm and perform

    programming for sorting

    7 Write algorithm and perform

    programming for searching

    8 Write algorithm and perform

    programming for variousmatrix operations

    9 Write algorithm and performprogramming for linked list

    10 Write algorithm and perform

    programming for stack11 Write algorithm and perform

    programming for queue

    12 Write algorithm and perform

    programming for tree

    1

  • 8/3/2019 CA I Journal

    2/60

    Experiment No. 1

    Title: Write algorithm and perform programming

    using simple numeric computations

    2

  • 8/3/2019 CA I Journal

    3/60

    Experiment No. 1

    Aim: Program and algorithm to calculate Simple Interset.

    //Program

    #include

    #include

    void main()

    {

    float p, r, t, si;

    clrscr();

    printf(Enter the value of principal = );

    scanf(%f,&p);

    printf(Enter the rate of interest =);

    scanf(%f,&r);

    printf(Enter the time period=);

    scanf(%f,&t);

    si=p*r*t/100;

    printf( Simple Interest =%f,si);

    getch();

    }

    Output:

    o Enter the value of principal =1000

    the rate of interest =3.8

    the time period=2

    Simple Interest =76.00

    3

  • 8/3/2019 CA I Journal

    4/60

    Experiment No. 1

    Algorithm:

    Step 1: [NAME]

    Algorithm to calculate Simple Interest

    Step 2: [INITIALIZATION]

    p is float variable for principal amount

    r is float variable for rate of interest

    t is float variable for time in years

    si is float variable for simple interest

    Step 3: [INPUT]

    READ (p,n,r)

    Step 4: [CALCULATE]

    si p*r*t/100

    Step 5: [OUTPUT/DIAPLAY]

    WRITE (si)

    Step 6: [FINISH]

    HALT

    4

  • 8/3/2019 CA I Journal

    5/60

    Experiment No. 2

    Title: Write algorithm and perform programming

    using compound statement (if..else)

    5

  • 8/3/2019 CA I Journal

    6/60

    Experiment No. 2

    Aim: Program and algorithm to find largest of three numbers entered.

    //Program

    #include

    #include

    Void main()

    {

    int a,b,c;

    clrscr();

    printf(Enter a=);scanf(%d, &a);

    printf(Enter b=);

    scanf(%d, &b);

    printf(Enter c=);

    scanf(%d, &c);

    if(a>b && a>c)

    printf(\n\n Largest is a=%d, a);

    if(b>a && b>c)

    printf(\n\n Largest is b=%d, b);

    if(c>a && c>b)

    printf(\n\n Largest is c=%d, c);

    getch();

    }

    6

  • 8/3/2019 CA I Journal

    7/60

    Experiment No. 2

    OUTPUT

    Enter a=15

    Enter b=-6

    Enter c=0

    Largest is a=15

    7

  • 8/3/2019 CA I Journal

    8/60

    Experiment No .2

    Algorithm:

    STEP 1: [NAME]

    Algorithm to find largest of three numbers

    STEP 2: [INITIALIZATION]

    a, b, c are integer variables

    STEP 3: [INPUT]

    READ (a, b, c)

    STEP 4: [CALCULATE]

    IF (a > b AND a > c)Go to Step 5

    IF (b > a AND b > c)

    Go to Step 6

    IF (c > a AND c > b)

    Go to Step 7

    STEP 5: [OUTPUT/DISPLAY]

    WRITE (a)ENDIF

    STEP 6: [OUTPUT/DISPLAY]

    WRITE (b)

    ENDIF

    STEP 7: [OUTPUT/DISPLAY]

    WRITE (c)

    ENDIF

    STEP 8: [FINISH]

    HALT

    8

  • 8/3/2019 CA I Journal

    9/60

    Experiment No. 3

    Title: Write algorithm and perform programming

    using compound statement (loop)

    9

  • 8/3/2019 CA I Journal

    10/60

    Experiment No. 3

    Aim: Program and algorithm to print table from 1 to 10.

    //Program

    #include

    Experiment No. 3

    Aim: Write algorithm and perform programming using compound statement (loop)

    //PROGRAM

    #include

    void main()

    {

    int I, j, k;

    clrscr();

    for(i=1;i

  • 8/3/2019 CA I Journal

    11/60

    Experiment No. 3

    Algorithm:

    Step 1: [NAME]

    Algorithm to print table from 1 to 10

    Step 2: [INITIALIZATION]

    I, j, k are integer variables

    Step 3: [OUTER LOOP]

    Repeat FOR i 0 to i

  • 8/3/2019 CA I Journal

    12/60

    Experiment No. 4

    Title: Write an algorithm and perform program for series calculation.

    12

  • 8/3/2019 CA I Journal

    13/60

    Experiment No.4

    Aim: Program and algorithm to print Fibonacci series

    //program

    #include

    #include

    Void main()

    {

    Float a=1,b=0,c,I,n;

    Clrscr();

    printf (Enter the number of terms of Fibonacci series);scanf (%f,&n);

    For(i=0;i

  • 8/3/2019 CA I Journal

    14/60

    Experiment No. 4

    Algorithm:

    Step 1: [NAME]

    Algorithm to print Fibonacci series

    Step 2: [INITIALIZATION]

    a 1, b 0, c, I, n are float variables

    Step 3: [INPUT]

    READ (n)

    Step 4: [LOOP]

    Repeat FOR i 0 to I

  • 8/3/2019 CA I Journal

    15/60

    Experiment No.5

    Title: Write an algorithm and perform program using function.

    15

  • 8/3/2019 CA I Journal

    16/60

    Experiment No.5

    Aim: Program and algorithm to calculate factorial of number using recursion

    //program

    #include

    #include

    float factorial(float n);

    Void main()

    {

    Float fact, num;

    clrscr();

    printf (Enter the number=);

    scanf (%f, &num);

    Fact = factorial(num);

    printf (factorial of %0.0f=%0.0f, num, fact);

    getch();

    }

    float factorial (float n)

    {

    float temp;

    If(n==0)

    {

    temp = 1;

    return (temp)

    }

    else

    {

    temp = n*factorial(n-1);

    16

  • 8/3/2019 CA I Journal

    17/60

    Experiment No.5

    return ( temp);

    }

    }

    Output:

    Enter the number=34

    Factorial of 34=295232822996533287000000000000000000000

    17

  • 8/3/2019 CA I Journal

    18/60

    Experiment No.5

    Algorithm:

    Step 1: [NAME]

    Algorithm to calculate factorial of number using recursion

    Step 2: [INITIALIZATION]

    fact, num are float variables

    Step 3: [INPUT]

    READ (num)

    Step 4: [CALL PROCEDURE]

    Call factorial(num) such that fact factorial(num)

    Step 5: [OUTPUT/DISPLAY]

    WRITE(fact)

    Step 6: [FINISH]

    HALT

    Sub Algorithm:

    Step 1: [NAME]

    factorial(num)

    Num is float variable received from main procedure

    Step 2: [INITIALIZATION]

    temp is float variable

    Step 3: [CONDITION]

    If num=0 goto Step 4 ELSE goto Step 6

    Step 4: [CALCULATE]

    Temp1

    Step 5: [FINISH]

    RETURN

    Step 6: [CALL PROCEDURE]

    Call factorial(num) such that tempn* factorial(n-1)

    18

  • 8/3/2019 CA I Journal

    19/60

    Step 7: [FINISH]

    RETURN(temp)

    Experiment No.6

    Title: Write an algorithm and perform program using function.

    19

  • 8/3/2019 CA I Journal

    20/60

    Experiment No.6

    Aim: Program and algorithm to sort array by bubble sort

    //program

    #include

    #include

    #define size 10

    void main()

    {

    int arr[size];

    int I,j,temp;

    clrscr();

    printf (Enter the elements of array:\n);

    for(i=0;i

  • 8/3/2019 CA I Journal

    21/60

    Experiment No.6

    {

    printf(%d\t,arr[i]);

    }

    getch();

    }

    Output:

    Enter the elements of array:

    Enter 1 element=54

    Enter 2 element=69

    Enter 3 element=02

    Enter 4 element=87

    Enter 5 element=48

    Enter 6 element=156

    Enter 7 element=354

    Enter 8 element=01

    Enter 9 element=45

    Enter 10 element=645

    Sorted Array:

    1 2 45 48 54 69 87 156 354 645

    21

  • 8/3/2019 CA I Journal

    22/60

    Experiment No.6

    Algorithm:

    Step 1: [NAME]

    Algorithm to sort array by bubble sort

    Step 2: [INITIALISATION]

    SIZE is global variable with size 10

    arr[SIZE] is an integer array

    I, j, temp are integer variables

    Step 3: [LOOP]Repeat FOR i 0 to i SIZE by i i+1 through step 4

    Step 4: [INPUT]

    READ(arr[i])

    ENDREPEAT

    Step 5: [OUTER LOOP]

    Repeat FOR i 0 to i SIZE by i i+1 through step 8

    Step 6: [OUTER LOOP]Repeat FOR j 0 to j SIZE by j i+1 through step 8

    STEP 7: [CONDITION]

    IF( arr [j] > arr[j+1])

    GOTO Step 8

    Step 8: [SWAP]

    temp = arr[j]

    arr[j] = arr[j+1]

    arr[j+1] = temp

    ENDIF

    ENDREPEAT

    ENDREPEAT

    Step 9: [CALCULATE]

    k i * j

    22

  • 8/3/2019 CA I Journal

    23/60

    Step 10: [OUTPUT/DISPLAY]

    WRITE (k)

    ENDRPEAT

    ENDRPEAT

    Experiment No.6

    Step 11: [LOOP]

    Repeat FOR i 0 to i SIZE by i i+1 through step 12

    Step 12: [OUTPUT]

    WRITE (arr[i])

    ENDREPEAT

    Step 13: [FINISH]HALT

    23

  • 8/3/2019 CA I Journal

    24/60

    Experiment No. 7

    Title: Write algorithm and perform programming for searching.

    24

  • 8/3/2019 CA I Journal

    25/60

    Experiment No. 7

    Aim:Program and algorithm to search number in the array using binary search.

    //Program

    #include

    #include

    #define size 10

    void main()

    {int arr[size];

    int low, up, mid, i, j, temp, item;

    clrscr();

    printf(Enter the element af array:\n);

    for(i=0; i

  • 8/3/2019 CA I Journal

    26/60

    {

    printf(%d\t, arr[i]);

    scanf(%d, &item);

    low = 0;

    up = size 1;

    Experiment No.7

    while (low arr[mid])

    low=mid +1;

    if(item < arr[mid])

    low = mid + 1;

    if(item ++ arr[mid])printf(\nElement %d found at %d position, item, mid+1);

    if(low > up)

    printf(\nElement %d not founr in array, item);

    }

    getch();

    }

    OUTPUT:

    Enter the element of array:Enter 1 element=54

    Enter 2 element=69

    Enter 3 element=02

    Enter 4 element=87

    Enter 5 element=48

    Enter 6 element=156

    Enter 7 element=354

    Enter 8 element=10

    Enter 9 element=45

    Enter 10 element=625

    Sorted Array:

    2 10 45 48 54 69 87 156 354 625

    Enter the number to be searched:54

    26

  • 8/3/2019 CA I Journal

    27/60

    Element 54 found at 5 position

    Experiment No. 7

    ALGORITHM:

    Step 1: [NAME]Algorithm to search number in the array using binary search

    Step 2: [INITIALIZATION]SIZE is a global variable with size 10

    arr[SIZE} is an integer array which is sorted in ascending orderI, j, are integer variables

    Item is an integer variables to locate minimum and maximum number in the array

    Step 3: [LOOP]

    Repeat FOR i 0 to i

  • 8/3/2019 CA I Journal

    28/60

    High mid 1

    ENDIF

    Experiment No. 8

    Title: Write algorithm and perform programming for various matrix operations.

    28

  • 8/3/2019 CA I Journal

    29/60

    Experiment No. 8

    Aim: Program and algorithm to calculate addition of matrix.

    //Program

    #include#include

    #include

    #define row 3

    #define col 3

    void main()

    {

    Int mat[row][col];

    Int i,j,item, k=0;

    clrscr();

    printf(Enter the element of matrix:\n);

    for(i=0; i

  • 8/3/2019 CA I Journal

    30/60

    for(j=0;j

  • 8/3/2019 CA I Journal

    31/60

    3 is found at 1*3 position

    3 is found at 2*3 position

    3 is found at 3*3 position

    Experiment no.8

    Algorithm:

    Step 1: [NAME]Algorithm to sort array by bubble sort

    Step 2: [INITIALIZATION]

    row is global variable of size 3

    col is a global variable of size 3

    i, j, k are integer variables

    item is an integer variable to be search in matrix

    mat[row] [col] is two dimensional array (matrix) of size row col

    Step 3: [OUTER LOOP]Repeat FOR i 0 to i < row by i i+1 through step 6

    Step 4: [OUTER LOOP]

    Repeat FOR j 0 to j < row by j j+1 through step 6

    Step 5: [CONDITION]

    IF (item == mat[i][j]) GOTO step 6

    Step 6: [OUTPUT & CALCULATE]

    WRITE (Number found)

    k k+1

    ENDIF

    ENDREPEAT

    Step 7: [CONDITION]

    IF(k=0) GOTO Step 8

    31

  • 8/3/2019 CA I Journal

    32/60

    Step 8: [OUTPUT]

    WRITE (Number not found)

    Step 9: [FINISH]

    HALT

    Experiment No. 9

    Title: Write algorithm and perform programming for linked list.

    32

  • 8/3/2019 CA I Journal

    33/60

    Experiment No. 9

    Aim:Write Algorithm and perform programming for linked list

    //Program:

    #include

    #include

    Class linklist

    {

    private:

    struct node

    {

    int data;

    node*link;}*p;

    public:

    linklist();

    void append(int num);

    void addatbeg(int num);

    void addafter(int c,int num);

    void del(int num);

    void display();

    Int count();

    ~linklist();

    };

    linklist::linklist()

    {

    p=NULL;

    }

    void linklist::append(int num)

    33

  • 8/3/2019 CA I Journal

    34/60

    {

    node*q,*t;

    If(p==NULL)

    {

    p=new node;

    pdata=num;

    plink=NULL;

    }

    else

    {

    q=p;

    while(qlink!=NULL)

    Experiment No.9

    q=qlink;

    t=new node;tdata=num;

    tlink=NULL;

    qlink=t;

    }

    display();

    }

    void linklist::addatbeg(int num){

    node *q;

    q=new node;

    qdata=num;

    qlink=p;

    p=q;

    }

    void linklist::del(int num)

    {

    node*q,*t;

    int i;

    for(i=0,q=p;i

  • 8/3/2019 CA I Journal

    35/60

    cout

  • 8/3/2019 CA I Journal

    36/60

    node*q;

    cout

  • 8/3/2019 CA I Journal

    37/60

    11.display();

    cout

  • 8/3/2019 CA I Journal

    38/60

    Experiment No. 9Algorithm: To insert node at the end.

    Step 1: [NAME]

    Algorithm to insert node at the end.

    Step 2: [INITIALIZATION]

    FIRST is a pointer variable which indicates address of first link in list.

    X is the information stored in new node.

    NODE is a global variable.

    NEW(POINTER), SAVE are local variables

    Step 3: [CREATE NEW NODE]

    NEW NODE

    Step 4: [INITIALIZE INFORMATION OF NODE]

    NEW(INFO) X

    NEW(LINK) NULL

    Step 5: [CHECK FOR FIRST NODE]IF FIRST=NULL THEN

    RETURN(NEW)

    END IF

    Step 6: [INITIALIZE THE SEARCH FOR THE LAST NODE]

    SAVEFIRST

    38

  • 8/3/2019 CA I Journal

    39/60

    Step 7: [SEARCH FOR THE LAST NODE]

    Repeat WHILE SAVE(LINK)!= NULL through Step 8

    Step 8: [ASSIGNMENT]

    SAVESAVE(LINK)

    ENDREPEAT

    Step 9: [ASS NEW NODE AT THE NODE]

    SAVE(LINK)NEW

    Step 10: [FINISH]

    RETURN

    39

  • 8/3/2019 CA I Journal

    40/60

    Experiment No. 9

    Algorithm: To insert node at the front.

    Step 1: [NAME]

    Algorithm to insert node at front.

    Step 2: [INITIALIZATION]

    FIRST is a pointer variable which indicates address of first link in list.

    X is the information stored in new node.

    NODE is a global variable.

    NEW(POINTER), SAVE are local variables

    Step 3: [CREATE NEW NODE]

    NEW NODE

    Step 4: [INITIALIZE INFORMATION OF NODE]

    NEW(INFO) X

    Step 5: [ASSIGN ADDRESS TO NEW NODE]

    NEW(LINK) FIRST

    Step 6: [FINISH]

    RETURN

    40

  • 8/3/2019 CA I Journal

    41/60

    Experiment No. 9

    Algorithm: To delete node at the end.

    Step 1: [NAME]

    Algorithm to delete node at the end.

    Step 2: [INITIALIZATION]

    FIRST is a pointer variable which indicates address of first link in list.

    Step 3: [CHECK FOR EMPTY]

    IF FIRST=0 Then GOTO Step 4

    Step 4: [DISPLAY AND FINISH]

    WRITE(EMPTY LIST)

    RETURN

    Step 5: [ACCESS THE NODE]

    PFIRST

    Step 6: [LOOP]

    Repeat WHILE P!=Z through Step 6

    Step 7: [ASSIGNMENT]

    TP

    PLINK(P)

    END REPEAT

    Step 8: DELETE NODE]

    XDATA(Z)

    LINK(T)LINK(Z)

    LINK1(Z)0

    Step 9: [FINISH]

    RETURN

    41

  • 8/3/2019 CA I Journal

    42/60

    Experiment No. 10

    Title: Write algorithm and perform programming for stack.

    42

  • 8/3/2019 CA I Journal

    43/60

    Experiment No .10

    AIM: WRITE A PROGRAM FOR STACK

    //PROGRAM:

    #include

    #include

    #define max 10

    class stack

    {

    private:

    int arr[max]

    int top;

    public:

    stack()

    {

    top=-1;

    }

    void push(int item)

    {

    if(top==max-1)

    {cout

  • 8/3/2019 CA I Journal

    44/60

    }

    Experiment No .10

    }

    void main()

    {

    clrscr();

    stack s;

    s.push(11);

    s.push(12);

    s.push(13);

    s.push(14);

    s.push(15);

    s.push(16);s.push(17);

    s.push(18);

    s.push(19);

    s.push(20);

    s.push(21);

    s.push(22);

    int i=s.pop();

    cout

  • 8/3/2019 CA I Journal

    45/60

    */

    Experiment No .10

    Algorithm to PUSH element X into stack

    Step 2: [INITIALIZATION]

    S is an array of size N

    TOP is a global pointer variable which indicates topmost node of the stack.

    X is the information to be stored in new node.

    Step 3: [CHECK FOR OVERFLOW]

    IF TOP>=N GOTO Step 4

    Step 4: [DISPLAY]

    WRITE(Overflow Stack)

    ENDIF

    Step 5: [INCREAMENT TOP]

    TOPTOP+1

    Step 6: [INSERT NEW ELEMENT]

    D[TOP]X

    Step 7: [FINISH]

    RETURN

    Algorithm: To POP element X into stack

    Step 1: [NAME]

    Algorithm to POP element X into stack

    Step 2: [INITIALIZATION]S is an array of size N

    TOP is a global pointer variable which indicates topmost node of the stack.

    TEMP is integer variable

    Step 3: [CHECK FOR UNDERFLOW]

    IF TOP=0 GOTO Step 4

    45

  • 8/3/2019 CA I Journal

    46/60

    Step 4: [DISPLAY]

    Experiment No .10

    WRITE(Empty Stack)

    ENDIF

    Step 5: [REMOVE ELEMENT]

    TEMPS[TOP]

    Step 6: [DECREAMENT TOP]

    TOPTOP-1

    Step 7: [FINISH]

    RETURN

    46

  • 8/3/2019 CA I Journal

    47/60

    Experiment No. 11

    Title: Write algorithm and perform programming for queue.

    47

  • 8/3/2019 CA I Journal

    48/60

    EXPERIMENT NO.11

    AIM: Write algorithm and perform programming for linear queue

    //Program:

    #include

    #include

  • 8/3/2019 CA I Journal

    49/60

    }

    Data=arr[front];

    If(front==rear)

    Experiment No .11

    Front=rear=-1;

    Else

    Front++;

    Return data;

    }

    };

    Void main()

    {

    Clrscr();

    queue a;

    a.addq(11);a.addq(12);

    a.addq(13);

    a.addq(14);

    a.addq(15);

    a.addq(16);

    a.addq(17);

    a.addq(18);

    a.addq(19);

    a.addq(20);

    a.addq(21);int i=a.delq();

    cout

  • 8/3/2019 CA I Journal

    50/60

    Experiment No .11

    Algorithm:

    STEP 1: [NAME]

    Algorithm to insert element X into Linear Queue

    STEP 2: [INITIALIZATION]

    Q is an array of N elements

    F ,R are global pointer variables which denotes Front end

    and Rear end of the queue respectively

    X is the information to be stored in new node

    STEP 3: [CHECK FOR OVERFLOW]IF R >= N GOTO Step 4

    STEP 4: [DISPLAY]

    WRITE (Queue Overflow)

    STEP 5: [INCREMENT REAR POINTER]

    R R + 1

    STEP 6: [INSERT NEW ELEMENT]

    Q [ R ] X

    STEP 7: [FINISH]

    RETURN

    50

  • 8/3/2019 CA I Journal

    51/60

    Experiment No .11

    Algorithm:

    STEP 1: [NAME]

    Algorithm to delete element X into Linear Queue

    STEP 2: [INITIALIZATION]

    Q is an array of N elements

    F ,R are global pointer variables which denotes Front end

    and Rear end of the queue respectively

    STEP 3: [CHECK FOR OVERFLOW]

    IF F = - 1 GOTO Step 4

    STEP 4: [DISPLAY]

    WRITE (Empty Queue)

    STEP 5: [REMOVE ELEMENT]

    TEMP Q [ F ]

    STEP 6: [RESETTING POINTERS]

    IF = R THEN

    F R - 1

    ELSE

    F F + 1

    STEP 7: [FINISH]

    RETURN

    51

  • 8/3/2019 CA I Journal

    52/60

    Experiment No. 12

    Title: Write algorithm and perform programming on trees

    52

  • 8/3/2019 CA I Journal

    53/60

    Experiment No.12

    AIM:WRITE A PROGRAM FOR TREE

    //PROGRAM:

    #include

    #include

    #define true1

    #define false0

    class tree

    {

    private:struct node{

    node *l;

    int data;

    node *r;

    }*p;

    public:tree();

    void search(int n,int &found,node *&parent);

    void insert(int n);

    void traverse();

    void in(node *q);void pre(node *q);

    void post (node *q);

    void post(node *q);

    }

    tree::tree()

    {

    P=null;

    }

    Void tree::search(int,int &found ,node *&parent)

    {

    node *q;

    found=false;

    parent=NULL;

    if(p==NULL)

    return;

    q=p;

    53

  • 8/3/2019 CA I Journal

    54/60

    while(q!=NULL)

    {

    Experiment No.12

    if (q->data==n)

    {

    found=true;

    return;

    }

    if (q->data>n)

    {

    parent=q;

    q=q->1;

    }

    else

    {parent=q;

    q=q->r;

    }

    }

    }

    void tree::insert(int n)

    {

    int found;

    node *t,*parent;

    search(n,found,parent);if(found==true)

    coutdata>n?parent->1=t:parent->r=t;

    }

    }

    void tree::traversal()

    {

    54

  • 8/3/2019 CA I Journal

    55/60

    int choice;

    cout

  • 8/3/2019 CA I Journal

    56/60

    }

    void main()

    {

    tree tt,ss,qq;

    Experiment No.12

    int I, num;

    clrscr();

    for(i=0;i

  • 8/3/2019 CA I Journal

    57/60

    Experiment No .12

    Experiment No.12

    Algorithm:

    STEP 1: [NAME]

    Algorithm to count number of nodes in tree

    STEP 2: [INITIALIZATION]

    X indicates data of new node.

    Global Variable: NODE (POINTER)

    Local Variable: NEW (POINTER)

    STEP 3: [CREATE A NEW NODE]

    NEW NODE

    STEP 4: [INITIALISE COUNT OF NEW NODE]

    INFO(NEW) X

    LPTR(NEW) NULL

    RPTR(NEW) NULL

    STEP 5: [LOCATE THE POSITION OF NEW NODE]

    REPEAT WHILE != NULL through Step 6

    STEP 6: [FINISH]

    RETURN

    57

  • 8/3/2019 CA I Journal

    58/60

    Experiment No.12

    Algorithm:

    STEP 1: [NAME]

    Algorithm to arrange a tree in Inorder

    STEP 2: [INITIALIZATION]

    T is the pointer shown address of staring node

    STEP 3: [IS TREE EMPTY]

    IF T=NULL

    RETURN

    ENDIF

    STEP 4: [TRAVERSE THE LEFT SUB TREE]IF LPTR (T) != NULL THEN (T)

    CALL IN ORDER LPTR THEN(T)

    STEP 5: [PROCESS THE ROOT NODE]

    WRITE (INFO[T])

    STEP 6: [TRAVERSE THE RIGHT SUBTREE}

    IF RPTR(T) != NULL THEN

    CALL IN ORDER RPTR (T)

    STEP 7: [FINISH]

    RETURN

    58

  • 8/3/2019 CA I Journal

    59/60

    Experiment No.12

    Algorithm:

    STEP 1: [NAME]

    Algorithm to arrange a tree in Preorder

    STEP 2: [INITIALIZATION]

    T is the pointer shown address of staring node

    STEP 3: [IS TREE EMPTY]

    IF T=NULL

    RETURN

    ENDIF

    STEP 4: [PROCESS THE ROOT NODE]WRITE (INFO[T])

    STEP 5: [TRAVERSE THE LEFT SUB TREE]

    IF LPTR (T) != NULL THEN (T)

    CALL IN ORDER LPTR THEN(T)

    STEP 6: [TRAVERSE THE RIGHT SUBTREE}

    IF RPTR(T) != NULL THEN

    CALL IN ORDER RPTR (T)

    STEP 7: [FINISH]

    RETURN

    59

  • 8/3/2019 CA I Journal

    60/60

    Experiment No .12

    Algorithm:

    STEP 1: [NAME]

    Algorithm to arrange a tree in Postorder

    STEP 2: [INITIALIZATION]

    T is the pointer shown address of staring node

    STEP 3: [IS TREE EMPTY]

    IF T=NULL

    RETURN

    ENDIF

    STEP 4: [TRAVERSE THE LEFT SUB TREE]IF LPTR (T) != NULL THEN (T)

    CALL IN ORDER LPTR THEN(T)

    STEP 5: [TRAVERSE THE RIGHT SUBTREE}

    IF RPTR(T) != NULL THEN

    CALL IN ORDER RPTR (T)

    STEP 6: [PROCESS THE ROOT NODE]

    WRITE (INFO[T])

    STEP 7: [FINISH]

    RETURN