Jump to content

C++: Returning a Match function

ExplOregon

hello, I was recently given a problem that requires me to take in a search name from main and then supply it to a

function that searches a circular linked list and then returns the match to main if there is a match.  My issue is that

I can't display anything from within my functions (data abstraction unit) and it has to be taken care of from main.  

I was wondering if anyone could show a little code example or some pseudocode as to how I would approach this.

 

Thanks, Exploregon

Link to comment
Share on other sites

Link to post
Share on other sites

From what I understand: When you call the search function, you should be passing the name into it. Once you have found the match within the search function, you need to return the matched name back to the main. Is this at all what you mean by getting it back to main?

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Reno2792 said:

From what I understand: When you call the search function, you should be passing the name into it. Once you have found the match within the search function, you need to return the matched name back to the main. Is this at all what you mean by getting it back to main?

Yes that is what I mean but what return type would it be if I wanted to return that and

if there is a struct that has the name and if theres a match I want all the stuff from the

struct to be displayed how would I approach that?

Link to comment
Share on other sites

Link to post
Share on other sites

You might need your return type to be a list of whatever data types you have within it. You could add each matching item to the list and then return it. Then your main could loop through the returned list and output each of the values.

Link to comment
Share on other sites

Link to post
Share on other sites

Just return the index in the array of the key (return -1 if nothing is found). Then to print other informations just get the element from the list.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×