473,804 Members | 3,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7622
"Matt" <jr********@hot mail.com> wrote in message
news:ba******** *************** **@posting.goog le.com...
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********@hot mail.com> wrote in message
news:ba******** *************** **@posting.goog le.com...
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********@hot mail.com> wrote in message
news:ba******** *************** **@posting.goog le.com...
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******@mkwah ler.net> wrote in message news:X7******** *********@newsr ead3.news.pas.e arthlink.net...
"Matt" <jr********@hot mail.com> wrote in message
news:ba******** *************** **@posting.goog le.com...
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******@mkwah ler.net> wrote in message news:X7******** *********@newsr ead3.news.pas.e arthlink.net...
"Matt" <jr********@hot mail.com> wrote in message
news:ba******** *************** **@posting.goog le.com...
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.newshosti ng.com...

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

news:X7******** *********@newsr ead3.news.pas.e arthlink.net...
"Matt" <jr********@hot mail.com> wrote in message
news:ba******** *************** **@posting.goog le.com...
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******@mkwah ler.net> wrote in message news:q1******** *********@newsr ead4.news.pas.e arthlink.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
3758
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 ------------------------------------------------------------- PEP: 323
59
4356
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 HTML version is much more readable than the ReST version. See: http://www.python.org/peps/pep-0322.html
3
3408
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 please help me? TIA. -- <?php echo 'Just another PHP saint'; ?> Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
14
14819
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
7607
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
5398
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 string as an input and print it in reverse order.(don't use bulit-in/library function). Sample Output Enter any string: i m Kashif
20
19801
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
2055
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--) printf("%s",str; } how can i print in above order
40
36498
by: KG | last post by:
Could any one tell me how to reverse the bits in an interger?
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10076
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7616
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.