GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-Jan-2005, 14:26
yevi yevi is offline
New Member
 
Join Date: Nov 2004
Posts: 25
yevi is on a distinguished road

String Combination Algorithm


What is the algorithm to display al possible combinations of a string?
There are N^N combinations

If the string is "ab"
the output should be: ab,ba,aa,bb 2^2=4 combinations

if the string is "abc"
the output should be: abc, acb, aab,aac,aaa,aba, ..... 3^3=27 combinations
  #2  
Old 13-Jan-2005, 01:39
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
well I can give some tips, not the full code..

this is example for str with 2 char,

CPP / C++ / C Code:
char str[N];

for int i=0;i<2;i++
  for j=0;j<2;j++
   {
       cout<<str[i]<<str[j]<<endl;
   }

for more than 2 char, 3 or 4 may need 3 or 4 for loops, so obviously you need to use recursion tecniques for this, just try out for two chr first, then implement using recursion...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
Last edited by LuciWiz : 26-Mar-2006 at 08:48. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #3  
Old 13-Jan-2005, 09:02
yevi yevi is offline
New Member
 
Join Date: Nov 2004
Posts: 25
yevi is on a distinguished road
Thanks,
but I know, obviously, how to use loops for finite number of chars.
I need to know how to recurs it.
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read a .html file, check that file for links salemite C Programming Language 10 17-Jan-2008 08:56
Re: Conversion: Binary, Decimal, Hexadecimal WaltP C Programming Language 1 10-May-2006 07:49
C++ string from file small_ticket C++ Forum 3 05-Jan-2005 08:29
Including Maps and strings?? maddie C++ Forum 17 05-Jul-2004 07:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.