[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

07/25/2007 at 02:59AM PDT, ID: 22719341
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

Binary search tree using Pascal

Asked by cipher007 in Pascal Programming Language

Tags: pascal, binary, tree, search

Could anybody change the following BST code so that the input could be read from a text file and the searched data could be output to the screen.
===================================================================================
Program Bsearch(input,output);
Uses wincrt;
Const exitpro = -1;
Type
    Element = Word;


    Ptr = ^Nodetype;


    Nodetype = Record
               Key:Element;
               Left,Right:Ptr;
               End;


    Treeptrtype = Ptr;


Var Select:Integer;
    Rootptr:Treeptrtype;
    Targettype:Element;
    Positionptr:Ptr;
    Depthtype:Word;
    Newnodeptr:Treeptrtype;
    Nextnode:Element;


Procedure InitTree(Var Root:TreePtrType);
Begin
     Root := nil;
     Writeln('The tree has been initialised.');
     Delay(1000);
End;


Function TreeEmpty(Root:TreePtrType):boolean;
Begin
     TreeEmpty := (root = nil)
End;


Procedure SearchTree(Root:TreePtrType; Target:word;
                   Var Position:Ptr; Var Depth:word);
Begin
     If root = nil then
        Position := nil
     Else
     Begin
          If root^.key = target then
             Begin
                  Position := root;
                  Depth := 1;
             End
          Else if target < root^.key then
               Begin
                    Depth := depth+1;
                    SearchTree(root^.left,target,position,depth);
               End
               Else Begin
                    Depth := depth+1;
                    SearchTree(root^.right,target,position,depth);
                    End;
     End;
End;


Procedure AddToTree(Var Root:TreePtrType; NewNode:TreePtrType);
Begin
     If root = nil then
     Begin
          Root := newnode;
          Root^.left := nil;
          Root^.right := nil;
     End
     Else if newnode^.key < root^.key then
             AddToTree(root^.left,newnode)
          Else
              AddToTree(root^.right,newnode);
End;


Procedure PreOrder(Root:TreePtrType);
Begin
     If root <> nil then
     Begin
          Writeln(Root^.key);
          PreOrder(Root^.left);
          PreOrder(Root^.right);
     End;
End;


Procedure PostOrder(Root:TreePtrType);
Begin
     If root <> nil then
     Begin
          PostOrder(Root^.left);
          PostOrder(Root^.right);
          Writeln(Root^.key);
     End;
End;


Procedure InOrder(Root:TreePtrType);
Begin
     If root <> nil then
     Begin
          InOrder(Root^.left);
          Writeln(Root^.key);
          InOrder(Root^.right);
     End;
End;


Procedure Screen(Var Choice:integer);
Begin
     Clrscr;
     Writeln;
     Writeln('1.     Initialise a tree');
     Writeln('2.     Add an item to a tree <a positive integer>');
     Writeln('3.     Search for an item in the tree');
     Writeln('4.     Preorder printout of tree');
     Writeln('5.     Postorder printout of tree');
     Writeln('6.     Inorder printout of tree');
     Writeln('7.     Quit');
     Writeln;
     Write('Please enter your choice: ');
     Readln(choice);
     Writeln;
     If (Choice < 1) or (Choice > 7) then
     Begin
        Writeln('Only options 1 to 7 are available.');
        Delay(1000);
     End;
End;


Begin {Main}
     Repeat
           Screen(select);
           Case select of
                1 : InitTree(rootptr);
                2 : Begin
                    Writeln('Enter ',exitpro:1,' to stop.');
                    Write('Enter next data value or ',exitpro:1,' to stop.');
                    Readln(newnodeptr.key);
                    While nextnode <> exitpro do
                    AddToTree(rootptr,nextnode);


                    End;
                3 : SearchTree(rootptr,targettype,positionptr,depthtype);
                4 : Preorder(rootptr);
                5 : Postorder(rootptr);
                6 : Inorder(rootptr);
           End;
     Until select = 7;
End.
==================================================================================
thanks
 
Keywords: Binary search tree using Pascal
 
Loading Advertisement...
 
[+][-]07/25/07 05:43 AM, ID: 19564809

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/25/07 07:33 AM, ID: 19565695

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/25/07 08:15 AM, ID: 19566220

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/25/07 02:50 PM, ID: 19570133

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/25/07 10:42 PM, ID: 19572105

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/26/07 06:05 AM, ID: 19574016

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/26/07 06:30 PM, ID: 19579649

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/27/07 01:25 AM, ID: 19580885

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/28/07 03:55 PM, ID: 19586326

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/30/07 07:41 AM, ID: 19592746

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Pascal Programming Language
Tags: pascal, binary, tree, search
Sign Up Now!
Solution Provided By: dinilud
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07/31/07 08:29 AM, ID: 19601300

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/31/07 11:09 AM, ID: 19602743

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]07/31/07 10:06 PM, ID: 19606383

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091028-EE-VQP-85