My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
Treesort [string array]
Posted Date: 12 Jun 2008 Resource Type: Articles/Knowledge Sharing Category: Computer & Technology
|
Posted By: Lenin Member Level: Diamond Rating: Points: 1
|
Treesort [string array]
#include #include #include
struct tnode { char *str; struct tnode *left; struct tnode *right; };
void insert(struct tnode **p, char *value); void print(struct tnode *root);
int main(void) { char line[1024]; struct tnode *root;
root = NULL; while((fgets(line, 1024, stdin)) != NULL) insert(&root, line);
print(root); return 0; }
/* call by reference .. ! */ void insert(struct tnode **p, char *value) { if(!*p) { *p = (struct tnode *)malloc(sizeof(struct tnode)); (*p)->left = (*p)->right = NULL; (*p)->str = strdup(value); return; }
if(strcmp(value, (*p)->str) < 0) insert(&(*p)->left, value); else insert(&(*p)->right, value); } /* inorder binary tree print ... */ void print(struct tnode *root) { if(root != NULL) { print(root->left); printf("%s", root->str); print(root->right); } }
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|
Watch TV Channels
|