Harshal's solution can be modified to make it worth with just 1 pass
over the input string.
What we need is an additional "link" pointer for each entry in the
auxillary array.
Additionally, we need "current" and "start" pointers which will be
null to start with.
Now, for every character in the input string, we go to the particular
index location in the array.
If start == null, we make it point to the present array location.
If count in array == 0
Set count = 1
If current == null
Set current = present array location
Else
Set link property of the location pointed to by current =
present array location
Set current = present array location
Else
We increment the count
If current != present array location and present array location's
link != null
Set link property of the location pointed to by current =
present array location
Set current = present array location
Once the input string is parsed, we scan the array, starting at the
location pointed by "start" and following the "link" pointers and
printing the character as many times as the count present in the
array.
On Jun 26, 11:50 am, Ashish Goel <[email protected]> wrote:
> this will need two passes
>
> first pass creates the hash map of char and count
>
> second pass walk over the the string again, refer hash map to print that
> many chars, remove this char from hash once printed and move on untill the
> complete string is covered or hashmap size is 0
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
> On Sun, Jun 26, 2011 at 5:35 PM, Vikash kumar
> <[email protected]>wrote:
>
> > use
> > #include<string.h> instead of #include<strings.h>
>
> > --
> > 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.