Page 556 - Computer science 868 Class 12
P. 556

{
                        if (top>=0)
                     return stud[top--];
                     else
                     return " $$";
                     }
                     }
                     (b)  Name the entity used in the above data structure arrangement.                        [ISC 2018]
                Ans.  The entity used in the above data structure is Stack.
                 16.  (a)   A linked list is formed from the objects of the class Node. The class structure of the Node is given below:    [ISC 2018]
                        class Node
                        {
                        int n;
                        Node link;
                        }
                          Write an Algorithm OR a Method to search for a number from an existing linked list. The method declaration is as follows:
                        void FindNode(Node str, int b)
                Ans.  ALGORITHM :
                     Step 1. Start
                     Step 2. Set temporary pointer to the first node
                     Step 3. Repeat steps 4 and 5 until the pointer reaches null. Display number not found
                     Step 4. check for number , if found display, exit
                     Step 5. Move pointer to the next node
                     Step 6. End algorithm
                     METHOD:
                    void FindNode(Node str, int b)
                    {
                    Node temp=str;
                    while(temp!=null)
                    {
                    if (temp.n == b)
                    {
                    System.out.prinln(b+” is found “);
                    break;
                    }
                    temp=temp.link;
                    }
                    }
                     (b)   Answer the following questions from the diagram of a Binary Tree given below:       [ISC 2018]
                                   A



                             E           B


                          G     C           D


                             H            F

                         (i) Write the inorder traversal of the above tree structure.
                        (ii) State the height of the tree, if the root is at level 0 (zero).
                       (iii)  List the leaf nodes of the tree.
                Ans.   (i)  Inorder traversal: G,E,H,C,A,B,F,D
                     (ii) The height of the tree, if the root is at level 0 (zero) is 3.
                     (iii) The leaf nodes of the tree are G,H, and F




                554554  Touchpad Computer Science-XII
   551   552   553   554   555   556   557   558   559   560   561