472,993 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

reverse the order of the words

Given an array of characters which form a sentence of words, give an
efficient algorithm to reverse the order of the words (not characters)
in it.
Jul 19 '05 #1
8 7588
"Matt" <jr********@hotmail.com> wrote in message
news:ba*************************@posting.google.co m...
Given an array of characters which form a sentence of words, give an
efficient algorithm to reverse the order of the words (not characters)
in it.


Matt,
You really are posting a series of classic interview/quizz questions
in comp.lang.c* groups. Some kind of homework ?

For this problem, a classic approach is to reverse the whole sentence,
then reverse the characters of each word. This has the advantage of
being easy to apply in-place.
Cheers,
--
http://ivan.vecerina.com

Jul 19 '05 #2
"Matt" <jr********@hotmail.com> wrote in message
news:ba*************************@posting.google.co m...
Given an array of characters which form a sentence of words, give an
efficient algorithm to reverse the order of the words (not characters)
in it.


here homework do not do We.

this read Please:
http://www.slack.net/~shiva/welcome.txt

you Thank,
-Mike

Jul 19 '05 #3
Mike Wahler wrote:
"Matt" <jr********@hotmail.com> wrote in message
news:ba*************************@posting.google.co m...
Given an array of characters which form a sentence of words, give an
efficient algorithm to reverse the order of the words (not characters)
in it.

here homework do not do We.

this read Please:
http://www.slack.net/~shiva/welcome.txt


Or even this:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #4

"Mike Wahler" <mk******@mkwahler.net> wrote in message news:X7*****************@newsread3.news.pas.earthl ink.net...
"Matt" <jr********@hotmail.com> wrote in message
news:ba*************************@posting.google.co m...
Given an array of characters which form a sentence of words, give an
efficient algorithm to reverse the order of the words (not characters)
in it.


here homework do not do We.

You sound like Master Yoda when you talk like that :-)
Jul 19 '05 #5
Ron Natalie wrote:

"Mike Wahler" <mk******@mkwahler.net> wrote in message news:X7*****************@newsread3.news.pas.earthl ink.net...
"Matt" <jr********@hotmail.com> wrote in message
news:ba*************************@posting.google.co m...
Given an array of characters which form a sentence of words, give an
efficient algorithm to reverse the order of the words (not characters)
in it.


here homework do not do We.

You sound like Master Yoda when you talk like that :-)


Or a Boy Scout :-)

/david

--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
Jul 19 '05 #6

"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

"Mike Wahler" <mk******@mkwahler.net> wrote in message

news:X7*****************@newsread3.news.pas.earthl ink.net...
"Matt" <jr********@hotmail.com> wrote in message
news:ba*************************@posting.google.co m...
Given an array of characters which form a sentence of words, give an
efficient algorithm to reverse the order of the words (not characters)
in it.


here homework do not do We.

You sound like Master Yoda when you talk like that :-)


It may come as a surprise to many, but I've only seen
the first Star Wars movie, but none of the sequels.
Did this character speak backwards?

-Mike
Jul 19 '05 #7

"Mike Wahler" <mk******@mkwahler.net> wrote in message news:q1*****************@newsread4.news.pas.earthl ink.net...
here homework do not do We.

You sound like Master Yoda when you talk like that :-)


It may come as a surprise to many, but I've only seen
the first Star Wars movie, but none of the sequels.
Did this character speak backwards?


Not necessarily backwards, but many of his phrasing is reordered
to make him seem more alien.
Jul 19 '05 #8
WW
Mike Wahler wrote:
here homework do not do We.

You sound like Master Yoda when you talk like that :-)


It may come as a surprise to many, but I've only seen
the first Star Wars movie, but none of the sequels.
Did this character speak backwards?


I backwards did not talk, my apprentice. ;-)

--
WW aka Attila
Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Raymond Hettinger | last post by:
Here is a discussion draft of a potential PEP. The ideas grew out of the discussion on pep-284. Comments are invited. Dart throwing is optional. Raymond Hettinger ...
59
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
3
by: R. Rajesh Jeba Anbiah | last post by:
Unfortunately, I couldn't find any way to traverse the object array in reverse order. I'd thought there must be a way to do it with for..in loop, but couldn't find anything yet. Could someone...
14
by: ford_desperado | last post by:
Why isn't ALLOW REVERSE SCANS the default? Why do we have to - drop PK - create an index - recreate PK What are the advantages of indexes that do not allow reverse scans?
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
10
by: aatish19 | last post by:
1: Write a program that asks the user to input an integer value and print it in a reverse order Sample Output Enter any number 65564 Reverse of 65564 is 46556 2: Write a program that takes a...
20
by: mike7411 | last post by:
Is there any easy way to reverse the order of the bits in a byte in C++? (i.e. 00000001 becomes 10000000)
1
by: pavani2006 | last post by:
suppose a string is there"pavani is very good" i want to print in reverse like"good very is pavani" i am able to reverse like this "doog si yrev inavap" for(int i=strlen(str); i>0i--)...
40
by: KG | last post by:
Could any one tell me how to reverse the bits in an interger?
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.