0

I need to search through its contents with a recursive function, so it returns a boolean response depending whether the value I read was found or not. I dunno how to make it work. Here's the type for the tree I defined:

  text=string[30];
  list=^nodeL;
  nodeL=record
    title:text;
    ISBN:text;
    next:list;
  end;
  tree=^nodeT;
  nodeT=record
    cod:text;
    l:list;
    LC:tree;
    RC:tree;
  end;
Etto
  • 5
  • 1
  • 2

1 Answers1

0

This looks like a "please do my assignment for me post", which I won't do. I will try and help you do the assignment yourself.

I don't know exactly what your assignment is, so I'm going to have to make some guesses.

I think your assignment is to write a recursive function that will search a tree and return a boolean response depending on whether a value (input to the function) is found or not.

I don't know how the tree gets its content. You say, you defined the tree type, so I'm guessing that means you are not provided with a tree that already has content. So, at least for testing purposes, you are going to have to write code to add content to the tree (so you can search it).

I don't know exactly what kind of tree you are supposed to create. Usually trees have rules about how the items are arranged in the tree. A common type of tree, is a binary tree, where for each node, the item in the left node (if present) is "less than" the item in the right node (if present). You probably need this when adding items (i.e. content) to the tree.

I think you need to change your definition of the tree node, nodeT (I could be wrong). A tree is a kind of linked list, it does not usually contain linked lists. Usually each tree node contains an item of data (not a list of items).

If I were doing in this assignment (and learning to program in Pascal) I would do the following (in this order):

  1. Make sure I understand linked lists (at least singe-linked list). Write at least one program to add data to a linked list, and search it (do not use recursion).

  2. Make sure I understand recursion. Read some tutorials on recursion (that do not use linked lists, or trees). For example "First Textbook Examples of Recursion". Write at least one program that uses recursion (do not use linked lists or trees).

  3. Make sure I understand trees. Read some tutorials on trees. For example, "Binary Search Trees"

  4. Do the assignment.

P.S. You might want to change the name of your text type from "text", because, in Pascal, "text" is the name of a predefined type, for text files.

Stuart
  • 1,428
  • 11
  • 20
  • Thanks a bunch, Stuart! I'm sorry I kinda asked my assignment to be done for me, I already had the rest of the code written, but this particular issue kept messing with me. I'm gonna follow your advice and give this function another round, I'll also try to make better questions next time I come here. – Etto Sep 30 '20 at 03:20