Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi, I want to find the "n"th non-repeating character in the string(Ex: 3rd non-repeating character in the string) without using any predefined methods.

What I have tried:

I tried with character array but I can't able to increment the value of the character present. Give me some solutions
Posted
Updated 15-Jul-18 2:41am
Comments
Patrice T 15-Jul-18 11:42am    
Show your code, explain problem.

Quote:
I tried with character array but I can't able to increment the value of the character present.

Show your code.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
 
Share this answer
 
v2
Comments
KarstenK 16-Jul-18 2:20am    
"HomeWork is not set to test your skills at begging other people to do your work". Good explanation ;-)
Patrice T 16-Jul-18 2:36am    
Thank you
THis is your homework, so you'll get no code!

But, this is how I'd do it: Start by counting the characters, and storing the counts in an array which has space for each possible character. That's trivial, and takes a single pass through the input. Each time you find a new value (i.e. it has a zero count) store the location in a separate array.
You now have two arrays, and the input data: it's simple to find the "n"th singleton - the count array holds a one for it. And it's location is in the other array.

How I'd actually do it is to set up a struct to hold the char, the location, and the count, and have a single array of those instead of the two arrays above.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900