472,993 Members | 2,653 Online

# 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
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
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.

http://www.slack.net/~shiva/welcome.txt

you Thank,
-Mike

Jul 19 '05 #3
Mike Wahler wrote:
"Matt" <jr********@hotmail.com> wrote in message
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.

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.

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
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
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

"Matt" <jr********@hotmail.com> wrote in message
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
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.