In context of C++

   1. Populate the digits of the given number in a vector V
   2. call next_permutation() on V
   3. print the vector [?]


Thanks,
Anurag Sharma
+91-8712218874



On Tue, Dec 6, 2011 at 2:23 AM, sourabh <[email protected]> wrote:

> This problem is a direct implication of "next_permutation" defined in C
> ++ STL algorithms.
>
> 1) From the end, keep decrementing till A[i] < A[i+1]..
> 2) Now, find the closest element , greater than equal, to A[i] in A[i
> +1 ... n]. Say, the index of the found element is "j".
> 3) Swap (A[i], A[j])
> 4) Reverse array A[i+1 .. n]
>
>
>
> On Dec 6, 12:37 am, Anup Ghatage <[email protected]> wrote:
> > Hmm here is a thought.
> >
> > In the given number, check the second digit from the left.
> >
> > if it is the maximum, find the digit that is the next greater digit from
> > the left most digit.
> > append it to the start and append all the other numbers in sorted order.
> >
> > if the second from left isn't the largest, find the next digit that is
> > greater than the last digit and swap places with it.
> >
> > On Mon, Dec 5, 2011 at 11:05 PM, raushan kumar <
> [email protected]>wrote:
> >
> > > Given a number,find the next higher number using the same digits in the
> > > number.
> > > eg: 15432  :: 21345
> > >        14532
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > --
> > Anup Ghatage
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

<<330.gif>>

Reply via email to