0

I am new to programming. My question is: is it possible to store a four-member struct into a binary search tree? I have an input txt file containing data that I have already read. The input file looks like this:

 30005886 Vanessa Yorson 19601202
 30007518 Cara Yarrow 19490413
 30011718 Sally Mooney 19760111

so this is my struct:

struct dataRec {
    int ssn;
    string firstName;
    string lastName;
    int dob;
};

how would I go about storing this info into a BST? Thanks!

user149379
  • 11
  • 5

2 Answers2

0

Yes, it is.

Just when you create the node of a tree make that node like struct dataRec *node;

After this , you can use malloc to allocate the memory and then you can assign the respective values.

Priyansh Goel
  • 2,660
  • 1
  • 13
  • 37
0

Unless you are trying to learn binary search tree, you can use std::map to solve this problem.

http://en.cppreference.com/w/cpp/container/map Maps are usually implemented as red-black trees.

Red black trees are a kind of self balancing binary search tree.

STL doesn't have tree containers Why does the C++ STL not provide any "tree" containers? but the functionality is available through map.

If you are using a map your problem is simple std::map<int, dataRec> storage;

Community
  • 1
  • 1