hi

i've been given a task to do the following program without using structures or linked list and ... . just with arrays and simple things.

the application will accept some data as follow :
N1 F N2
N2 F N3
and then print them out from grandfather to son which is in the above case :
N1 N2 N3
i had some ideas but they were not good enough for big families .

i'd appreciate it if someone could give me a help with that .

thanks

Recommended Answers

All 8 Replies

i know i should sort it , but sort what ? how to read them ?
im just creating an array with all 0 value , and then i add 1 to the index of the fathers in the array and then -1 to the childs . but its not working in some conditions . its not a good algorithm .

i forgot to say that it might be more comlicated than the above one . it might be like this or even worst xD
N1 F N2
N2 F N3
N1 F N4
N3 F N5
N3 F N7
N5 F N6
and so one

What is sorted order? Depth or breadth walk first?

The real trick is deciding wht the prof wants. Reality is secondary in school, interviews and under tech managers with high self esteem.

So is N2 a child of N1 ? No facility for siblings, half-siblings, step-siblings, adopted siblings?

No . Its just a father with His sons . A father might have Alot of sons bht no adobted or so . Just like the example .

Well, popen sort is text oriented, simplest, no struct or linked list or such. A qsort can do arrays. Make sure the text is nicely formatted as output, padded to standard length with *printf() or the like.

i've solved it , i've considered a matrix for saving data's ( rows for fathers and columns for sons ) and if a father had a son i'll set the son to 1 . and at the end i'll print the rows if they were 1 . it seems to be the best solotion for this .

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.