how would i go about sorting multiple items in a binary search tree..
for example if i have a list of first last and middle names and i want to sort it in a tree by last name, how would i store all three of them in each node..
should i create a struct with them in it and a separate struct for my tree?
whats the easiest way to do this?
nadleeh
0
Newbie Poster
Recommended Answers
Jump to PostThere are 2 concepts involved here
Concept 1: In a Binary Search tree if you print all of the nodes inorder then the output will be an array sorted in ascending order. Extending this to your problem, you can use the last name as an index for inserting data …
Jump to PostYou don't sort a binary search tree because it's inherently sorted. Just use the last name as your key for insertion.
Jump to PostDude, wtf. Just build your freaking tree. It's already sorted! You don't need a linked list, you don't need a separate sorting step:
#include <stdio.h> #include <string.h> struct person { char first_name[20]; char last_name[20]; }; struct node { struct person data; struct node *link[2]; }; struct node …
All 9 Replies
abhimanipal
91
Master Poster
nadleeh
0
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
nadleeh
0
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
nadleeh
0
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
nadleeh
0
Newbie Poster
Narue
5,707
Bad Cop
Team Colleague
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.