hello experts i am new to this programming field

plz tell me how can i reverse a string without using any extra space .

if someone could provide code it ll be great help for me

thankx

Recommended Answers

All 10 Replies

You didn't mentioned..u r learning C or C++.....u can take a look at code snippet section...u'll find one by dave_sinkula

You didn't mentioned..u r learning C or C++.....u can take a look at code snippet section...u'll find one by dave_sinkula

i am learning c++

i am learning c++

You can see the logic of that program..it's in C...try to convert in C++....and post if you have any problems

I think he said "without using extra space".

I think he said "without using extra space".

No one is gonna write code for him...he need to show some efforts.....i just gave a direction...he can work upon it and post his problem where he is stuck....

No one is gonna write code for him...he need to show some efforts.....

I agree. Dave's method uses a char* for the reversing. All I wanted to know was will that count as a method using extra space or not.

All I wanted to know was will that count as a method using extra space or not.

Well, if by extra space he meant, not using another array for storing reverse of the string then dave's method is perfect.....

No one is gonna write code for him...he need to show some efforts.....i just gave a direction...he can work upon it and post his problem where he is stuck....

hey guys u r guessing something more

i just say that if u have written code thn give me

i was asking only for direction , tell me only logic ok i can do it

and keep in mind that sometimes one need something very instantly and this question was asked to my colleagues in interview and that time instantly he had no logic for it so i post u for help not for (underestimating things that i am giving u a order to write code on behalf me )

(underestimating things that i am giving u a order to write code on behalf me )

No one under-estimated u...i just highlighted the basic rules of forum...u should read that before posting....and i hope u got ur solution

johnray31: I believe you are looking for the XOR swap.

So I guess you are being taught by a teacher that is still stuck in decades-old issues. This "save memory" thing was a problem before the 1970's and has been solved by hardware for decades.

Unfortunately these old hacks are still spread about as gleeming gems for programmers. Except that today, yesterday's optimization acutally is less optimal. And I doubt that your teacher will mention that this only works for integer types (that you cannot do this floating point values or pointers), and as the code in the link suggests you cannot use it on pointers to the same data. And let's hope you don't see the "supercompressed" version demonstrating undefined behavior proudly displayed in class as a wonderful solution.

So all-in-all, you're trying to learn something that you should try to forget after you've learned it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.