Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11926

Re: Best way to print all possible permutations of a string

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Best way to print all possible permutations of a string
Date Tue, 29 Nov 2011 15:01:13 +1300
Lines 41
Message-ID <9jisn9F4d0U29@mid.individual.net> (permalink)
References <be537869-f936-4cce-abe0-9eab53b548fd@gl2g2000vbb.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net GgtQrVc6W+Add4z9G9AQgwWQ1q9U+xz6XHaZSPS5QriPT3dWTl
Cancel-Lock sha1:d6FzfTwYqyjvx5ZwhfemMiPqSIw=
User-Agent Mozilla/5.0 (X11; SunOS i86pc; rv:6.0.2) Gecko/20111003 Thunderbird/6.0.2
In-Reply-To <be537869-f936-4cce-abe0-9eab53b548fd@gl2g2000vbb.googlegroups.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:11926

Show key headers only | View raw


On 11/29/11 02:46 PM, sanket wrote:
> Hi all.
>
> I wrote a program to print all permutations of the letters of a
> string. Here are my two implementations

<snip>

> 2.
>
> #include<iostream>
> #include<algorithm>
> #include<cstdlib>
> using namespace std;
>
> int main(int argc, char ** argv)
> {
>          if(argc<  2) {cout<<  "Usage:\na.out<string>"<<
> endl;abort();}

Calling abort is rather drastic, why not just "return EXIT_FAILURE"?

>          string s(argv[1]);
>          sort(s.begin(), s.end());
>          cout<<  s<<  endl;
>          while(next_permutation(s.begin(), s.end())){cout<<  s<<
> endl;}
>          return 0;
> }
>
> They seem to be working well, but I was wondering if there was a
> better way to implement the same without using the STL function
> next_permutation.

s/STL/standard library/

Why would you want to avoid a library function that does what you want 
to do?

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Best way to print all possible permutations of a string sanket <sanketsharma09@gmail.com> - 2011-11-28 17:46 -0800
  Re: Best way to print all possible permutations of a string Ian Collins <ian-news@hotmail.com> - 2011-11-29 15:01 +1300
    Re: Best way to print all possible permutations of a string sanket <sanketsharma09@gmail.com> - 2011-11-29 00:24 -0800
      Re: Best way to print all possible permutations of a string DDD <1983ddd@gmail.com> - 2011-11-29 20:55 -0800

csiph-web