Every node can also have an index field. Keep a global variable index=0 After insertion of every new node do node->index=++index, and during the output compare the index values, the one which has a smaller value will come first. Modify the BST based on the count value obtained i.e
insert the first node with node->index=1 and node->count=1 For the subsequent numbers void insert(NODE *p) { NODE *q; q=p; while(q!=NULL) { p=q; if (number==q->info) { q->count++; if (q->count > q->father->count) swap q and q->father if (q->count == q->father->count && q->index < q->father->index) swap q and q->father } else if(number < q->info) q=q->left; else q=q->right; } if (number>p->info) insert a new node at the right, node->index=++index, node->count=1 else insert a new node at the left, node->index=++index, node->count=1 } After all the insertion is done now the tree is a BST based on count value. Perform the inorder traversal and depending on the count value print node->info count no. of times. The order of occurrence is also preserved. Please correct me if I'm wrong On Sat, Jul 3, 2010 at 5:49 PM, jalaj jaiswal <jalaj.jaiswa...@gmail.com>wrote: > how would we keep account of first in first out then...i mean first index > should be printed first in case of a tie > > On Fri, Jul 2, 2010 at 11:48 PM, Amir hossein Shahriari < > amir.hossein.shahri...@gmail.com> wrote: > >> i think that the best method would be a balanced binary search tree which >> counts the number of appearances for each element >> O(nlogn) >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > With Regards, > Jalaj Jaiswal > +919026283397 > B.TECH IT > IIIT ALLAHABAD > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.