We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,355 Members — Technology Publication meets Social Media

# Need help with tree sort in C

Need help from daniweb community. I suck at programming. It doesn't make sense to me. I'm not going to be programming in my career but it's part of my major. I'm desperately trying to get an c- just to pass. Would love some help. I would appreciate some explanation but it is not necessarily needed.

Given the following struct:

``````typdef struct node {
int data;
struct node * left;
struct node *right;
}tNode, *treeNode;
typedef struct list{
int data;
struct list *next;
}lNode, *listNode;
``````

First insert random numbers into the linked list
listNode generateList ( listNode head, int size ); (10 points)
Ask user to define the size of the list, like 100, 10000, etc.
In the function use rand() to create numbers from 0 to (size-1), then store the numbers in the linked list.
You can either insert the node from the beginning or the end of the list.

Then sort the linked list using different sorting algorithms:
First…
Tree Sort
The algorithm using a BST to sort the elements of an array is given in the slides.
The basic idea of tree Sort of a linked list is as follows:
1. Insert values in the linked list into a BST.
2. Perform an inorder traversal of the BST and write the values back to the list in sorted order.
Functions needed:
1. treeNode BuildBST(treeNode root, int val); (20 points)

2.listNode flatten(treeNode tree, listNode head);(30 points)

Perform an inorder traversal of the BST and write the values back to the list.

Second
Use merge sort to compare the result.
Merge Sort

Remember to free the allocated memory at the end.

Thanks to anyone willing to help me out.

2
Contributors
1
1 Day
Discussion Span
1 Year Ago
Last Updated
2
Views
jimjones371
Newbie Poster
1 post since Apr 2012
Reputation Points: 0
Skill Endorsements: 0

Have you tried to write any code yet? If you have, please post it and we can pick up where you left off. If not, that's fine too--I'm just trying to find a helpful starting point.

gusano79
Practically a Master Poster
680 posts since May 2004
Reputation Points: 193