reverse the order of the words

M

Matt

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

Ivan Vecerina

Matt said:
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,
 
M

Mike Wahler

Ron Natalie said:
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
 
R

Ron Natalie

Mike Wahler said:
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.
 
W

WW

Mike said:
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. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,244
Members
46,838
Latest member
KandiceChi

Latest Threads

Top