Pascal programming DFS(depth first search) and BFS(bredth first search) problems.?
These are the algorythms for searching a tree strucutre or a graph.
Could anybody show me (or send to me) where can I find these problems solved?
(Programs need to be Pascal console apps and data should be read from txt file)

Program BinarySearchTrees;

type nodepointer = ^node;

     node = record
     data : string[30];
     left : nodepointer;
     right : nodepointer;
end;


const Datafile = 'TreeNum.TXT';

{------------------------------------------------------------------}

Procedure InOrderTraversal (root : nodepointer) ;

begin
   If root^.left <> nil then begin
      InOrderTraversal (root^.left);
      writeln (root^.data);
      end;
   If root^.right <> nil then
      InOrderTraversal (root^.right);

end;

{------------------------------------------------------------------}


Procedure Insert_Into_Tree (n : nodepointer; var root : nodepointer);

begin
     if root = nil then
        root := n
     else begin
        if n^.data > root^.data then
           Insert_Into_Tree(n, root^.right)
        else
           Insert_Into_Tree(n, root^.left)
     end;


end;

{------------------------------------------------------------------}

Procedure Build_Tree;

var s : string;
    newnode: nodepointer;
    root : nodepointer;
begin
     root := nil ;
     assign (input, DataFile);
     reset (input);
     while not eof(input) do begin
           new(newnode);
           readln (input, s);
           newnode^.data := s;
           Insert_Into_Tree (newnode, root);

     end;
     close (input);

end;

{---------------------------------------------------------}


begin

Build_Tree;

end.

Pascal programming DFS(depth first search) and BFS(bredth first search) problems.?
These are the algorythms for searching a tree strucutre or a graph.
Could anybody show me (or send to me) where can I find these problems solved?
Programs need to be Pascal console apps and data should be read from txt file

Program BinarySearchTrees;


type nodepointer = ^node;

     node = record
     data : string[30];
     left : nodepointer;
     right : nodepointer;
end;


const Datafile = 'TreeNum.TXT';

{------------------------------------------------------------------}

Procedure InOrderTraversal (root : nodepointer) ;

begin
   If root^.left <> nil then begin
      InOrderTraversal (root^.left);
      writeln (root^.data);
      end;
   If root^.right <> nil then
      InOrderTraversal (root^.right);

end;

{------------------------------------------------------------------}


Procedure Insert_Into_Tree (n : nodepointer; var root : nodepointer);

begin
     if root = nil then
        root := n
     else begin
        if n^.data > root^.data then
           Insert_Into_Tree(n, root^.right)
        else
           Insert_Into_Tree(n, root^.left)
     end;


end;

{------------------------------------------------------------------}

Procedure Build_Tree;

var s : string;
    newnode: nodepointer;
    root : nodepointer;
begin
     root := nil ;
     assign (input, DataFile);
     reset (input);
     while not eof(input) do begin
           new(newnode);
           readln (input, s);
           newnode^.data := s;
           Insert_Into_Tree (newnode, root);

     end;
     close (input);

end;

{---------------------------------------------------------}


begin

Build_Tree;

end.

This code doesn't really work. Need help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.