# Recursive Algorithms for strings

Page 1 of 1

## 3 Replies - 576 Views - Last Post: 06 November 2012 - 10:01 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=298858&amp;s=b5ba0b94c6a4e7afa7093ab1a66f00a3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 andre1011

Reputation: 1
• Posts: 87
• Joined: 12-January 11

# Recursive Algorithms for strings

Posted 05 November 2012 - 05:21 PM

Hello everyone, I am looking for an algorithm to find recurcive permutations of a string. Could someone point me

in the right direction? For example I have a link list of strings:

C A T

the number of permutations is 6 (3! = 3x2x1) so the different arrangements of letters would go like this

C A T

A C T

A T C

T A C

T C A

C T A

If I have the algorithm I can do the rest myself. This is what I have tried so far

```void permute::permutation(int n)
{
node *rightNeighbor;
node *nextRightNeighbor;
node *previousNeighbor;

//cout<<" numberOfNodes "<<numberOfNodes<<" n = "<<n<<endl<<endl;
if( n == numberOfNodes )
{
return;
}
else
{
if(n == 1)
{
anchor = firstNode; /* first letter = first node (c) is the anchor */
}

if( nextRightNeighbor != NULL)
{
}
else
{
nextRightNeighbor = NULL;
}

previousNeighbor = rightNeighbor;
firstNode = rightNeighbor;
{
nextRightNeighbor = NULL;
}
permutation(n + 1);
}
printList();

}/* end permutation */

```

Is This A Good Question/Topic? 0

## Replies To: Recursive Algorithms for strings

### #2 KYA

• Wubba lubba dub dub!

Reputation: 3186
• Posts: 19,211
• Joined: 14-September 07

## Re: Recursive Algorithms for strings

Posted 05 November 2012 - 05:29 PM

Here's a snippet of mine that does recursive string permutation.

### #3 andre1011

Reputation: 1
• Posts: 87
• Joined: 12-January 11

## Re: Recursive Algorithms for strings

Posted 06 November 2012 - 08:47 AM

I understand what you did but I need to do the same thing with a link list of strings

### #4 Skydiver

• Code herder

Reputation: 4818
• Posts: 15,931
• Joined: 05-May 12

## Re: Recursive Algorithms for strings

Posted 06 November 2012 - 10:01 AM

If you understand the code snippet, then you should know that the same concepts apply with a linked list. The swapping was easier to do with an array, but the same thing can be done with a linked list.

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}