473,408 Members | 1,702 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,408 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 7602
"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?
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: 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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.