Take the input from the user of the min length number he would input i.e
min_length. Then accept the the numbers in the form of strings and calculate
the length of every number. Construct a binary search tree with fields as
follows:
struct node
{
   int number;    // atoi(input)
   int remainder;  // number/pow(10,string_length-min_length) if
string_length > min_length

            else remainder = number
   struct node *left;
   struct node *right;
};

My idea is reduce all the numbers to the smallest digit number and then sort
the remainders and output the respective numbers.
Construct binary tree based on the remainder and perform the inorder
traversal i.e

while ( p!=NULL)
{
   inorder(p->left);
   printf("%d",p->number);
   inorder(p->right);
}

For eg:  635, 12, 9, 76, 4
Every number is reduced to one digit
635=> number=635 remainder=635/100=6
12=> number=12 remainder=12/10=1
9=>number=9 remainder=9
76=>number=76 remainder=76/10=7
4=> number=4 remainder=4

Inorder traversal based on remainder 1-4-6-7-9
But we output the numbers instead of remainders i.e
12-4-635-76-9

Correct me if I'm wrong !!

On Sun, Aug 22, 2010 at 11:08 AM, aravind prasad <raja....@gmail.com> wrote:

> @srinivas reddy
>
> i suppose u took my algo wrongly..
>
> consider ur eg: 2,242
>
> first digits== 2,2(same)
>
> 2nd digits== 2,4(here 2 remains as it is as there is no futher digit for no
> 2)
>
> now arrange==> 2242(output)...
>
> my algo works correctly here too..
>
> correct me if am wrong..
>
>
>
> On Sun, Aug 22, 2010 at 10:41 AM, srinivas reddy
> <srinivaseev...@gmail.com> wrote:
> > @aravind prasad
> >
> > ho can u arrange the numbers
> > 2,202
> >
> > suppose if u arrange 202 2
> > ok u wiil get the least value
> >
> > now 2,242
> > if u arrange in same manner as above u will get 242 2
> > which is not smallest one...
> >
> > so better luck next time.....
> >
> > On Sun, Aug 22, 2010 at 8:41 AM, Aravind Prasad <raja....@gmail.com>
> wrote:
> >>
> >> for the method of comparison in insertion sort,, consider
> >>
> >> 1)compare the first digit of all nos and sort them
> >>
> >> 2)if they are same, go for next digit...
> >>
> >>
> >> correct me if am wrong...
> >>
> >>
> >> On Aug 21, 7:00 pm, Chonku <cho...@gmail.com> wrote:
> >> > Treat each number as string and make a trie out of it. For the first
> >> > input
> >> > [55,31,312,33], it would look like the following
> >> >                                       .
> >> >                                     /    \
> >> >                                  3/     5\
> >> >                                1/  3\    5\
> >> >                             31/ 2\   33\  \55
> >> >                                    312\
> >> > Once we have a trie, just print it out by based on the smallest number
> >> > first. In this case, the print would go as follows.
> >> >
> >> > 313123355
> >> >
> >> > On Sat, Aug 21, 2010 at 12:53 PM, Nikhil Agarwal
> >> > <nikhil.bhoja...@gmail.com>wrote:
> >> >
> >> >
> >> >
> >> > > Suppose the test is like:
> >> >
> >> > > 21 71 217
> >> > > after sorting and msb appending we get: 217 712 217
> >> > > sort: 217 217 712
> >> >
> >> > > here we have 2 same elements 217 and 217 so we remove the 7 from the
> >> > > following logic:
> >> >
> >> > > 1.if msb > lsb we delete from the 2nd 217.else
> >> > > 2.we delete 7 from 1st one.
> >> >
> >> > > so this gives 2121771
> >> >
> >> > > if it wud have been 41 200 412->412 200 412->200 412 412
> >> > > here we will remove 2 from last one.giving 20041241 instead of
> >> > > 20041412 .
> >> >
> >> > > On Sat, Aug 21, 2010 at 12:26 PM, BALARUKESH SIVARAMAN <
> >> > > sbalarukesh1...@gmail.com> wrote:
> >> >
> >> > >> @Nikhil
> >> > >> I am clear with your first 2 algos but not with the change u
> >> > >> introduced
> >> > >> ie., adding a check. please give a working example....
> >> >
> >> > >> --
> >> > >> 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>
> <algogeeks%2bunsubscr...@googlegroups
> >> > >> .com>
> >> > >> .
> >> > >> For more options, visit this group at
> >> > >>http://groups.google.com/group/algogeeks?hl=en.
> >> >
> >> > > --
> >> > > Thanks & Regards
> >> > > Nikhil Agarwal
> >> > > Senior Undergraduate
> >> > > Computer Science & Engineering,
> >> > > National Institute Of Technology, Durgapur,India
> >> > >http://tech-nikk.blogspot.com
> >> > >http://beta.freshersworld.com/communities/nitd
> >> >
> >> > > --
> >> > >  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>
> <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<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<algogeeks%2bunsubscr...@googlegroups.com>
> .
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
>
>
> --
> thanks and regards
>
> aravind prasad
>
> --
> 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.

Reply via email to