473,385 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reversing string without using indexing..

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
7 3362
JosAH
11,448 Expert 8TB
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
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
JosAH
11,448 Expert 8TB
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
9,208 Expert Mod 8TB
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
JosAH
11,448 Expert 8TB
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
9,208 Expert Mod 8TB
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
JosAH
11,448 Expert 8TB
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

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

Similar topics

108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
16
by: zohaibbaloch | last post by:
how to manipulate string without using arrays.manipulation example i have to print dog or any string i want to cut d from dog and paste it a end and add a at the last dog becoms ogda. please...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
6
by: Dan V. | last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to pass in a table or query as a parameter and have both columns transform into a 2D ArrayList. When I sort the one...
46
by: Albert | last post by:
Why doesn't: #include <stdio.h> void reverse(char, int); main() { char s;
8
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. ...
53
by: yinglcs | last post by:
Hi, In java, there is an 'indexOf' function in String which does this: indexOf(String str) Returns the index within this string of the first occurrence of the specified substring. is there...
3
by: steezli | last post by:
Hi, Brand new to VB.NET and I'm having a problem figuring out this program. I'll try and be descritive as possible. I have to create a Windows application that contains a single top-level...
1
by: rajkumarbathula | last post by:
Hi Could any one help me out in reversing rows/elements of DataTable or String or DataList by using any simple statement? Thanks
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.