By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

Reversing string without using indexing..

P: 34
Hello all,
I encountered a programming problem while going through interview questions asked by companies. But I stuck at this:

Given an array of characters. How would you reverse it? How would you reverse it without using indexing in the array?

Please Help..

Suyash..
Jun 10 '07 #1
Share this Question
Share on Google+
7 Replies


Expert 10K+
P: 11,448
Hello all,
I encountered a programming problem while going through interview questions asked by companies. But I stuck at this:

Given an array of characters. How would you reverse it? How would you reverse it without using indexing in the array?

Please Help..

Suyash..
Are you allowed to use pointers to the array elements instead? If so, the
problem is easy.

kind regards,

Jos
Jun 10 '07 #2

P: 34
Are you allowed to use pointers to the array elements instead? If so, the
problem is easy.

kind regards,

Jos
It is not explicitly mentioned whether we can use pointers or not. I was also thinking to use pointers. Is there any other method possible?

Suyash
Jun 10 '07 #3

Expert 10K+
P: 11,448
It is not explicitly mentioned whether we can use pointers or not. I was also thinking to use pointers. Is there any other method possible?

Suyash
Use qsort and consider an element wih a larger pointer to be lesser than the
other element?

kind regards,

Jos

ps. that would be cheating because we don't know the implementation of qsort ;-)
Jun 10 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
You could try using the deprecated memmove() function. The source is the address of the last element and the destination is the address of the first element.

I think this funciton handles overlapping regions and insures overlapped bytes are copied before being overwritten.
Jun 10 '07 #5

Expert 10K+
P: 11,448
You could try using the deprecated memmove() function. The source is the address of the last element and the destination is the address of the first element.

I think this funciton handles overlapping regions and insures overlapped bytes are copied before being overwritten.
That'd be cheating too for similar reasons why using the qsort() method would be
considered cheating ;-)

IMHO the question is ill defined and cannot be answered the way it is now.

kind regards,

Jos

ps. I didn't know memmove() was considered obsolete/deprecated?
Jun 10 '07 #6

weaknessforcats
Expert Mod 5K+
P: 9,197
ps. I didn't know memmove() was considered obsolete/deprecated?
I think I phrased that wrong. What I meant to say was that you should not be using memmove (or any of the mem... functions) in C++ due to these functions being unaware of copy constructors, reference counting, etc.
Jun 11 '07 #7

Expert 10K+
P: 11,448
I think I phrased that wrong. What I meant to say was that you should not be using memmove (or any of the mem... functions) in C++ due to these functions being unaware of copy constructors, reference counting, etc.
Ah, ok; we agree then.

kind regards,

Jos
Jun 11 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.