简体   繁体   中英

Struct pointing to a function that points to a file pointer?

I have been tasked with writing a program that will be a unbalanced BST of linked lists, basically a linked list of linked lists. My struct for the nodes is as follows:

typedef struct node
{
    int node_num;
    struct node *right, *left;
} node_t;

Now according to my professor I must use this "interface" (his words not mine).

node_t *buildTree(FILE *); 

Can someone explain the above "interface?" I gather that,

buildTree(File *);

is my function declaration and

node_t

is my typedef struct. But I am not understanding seeing it all together. I have not run across this type of declaration before.

I appreciate the help.

this is a function, that is given an open file (someone else opened the file and gave you the FILE* ).

You are to read some data out of that file, and turn it into a bunch of nodes for your BST.

Finally, you are to return a pointer to the top / head node (a node_t* )

So, you start with:

node_t* buildTree(FILE* myFile)
{
    node_t* treeRoot = NULL;

    fread( [??], [??], [??], myFile );   /* Read something from the file */

    [...]

    return treeRoot;
}

What you do with [...] is how you earn your paycheck. :)

The function node_t *buildTree(FILE *); will accept a pointer to type FILE and return a pointer to your type node_t

You function will build a binary tree with the help of FILE pointer, that will be used to read data from an actual file from a disk. The pointer FILE can be passed along to other functions or recursively.

The returned pointer node_t will point to the start of the binary tree.

node_t* buildTree(FILE *);  // Is a function declaration
    |              |
    |              |
    |              +-------a FILE pointer as argument
    |
    +-------return type: A pointer to struct node_t

Basically you need to "build" a tree using input from a file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM