Thread: can you read it now

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    can you read it now

    [code]
    #include<iostream>
    #include<string>

    using namespace std;


    void permute( const string & str);
    void permute( const string & str, int low, int high);
    int main()
    {
    int number;
    string str;

    cin >> str;

    cout << endl;
    permute(str);
    return 0;
    }

    void permute( const string & str)
    {
    permute(str,0,str.length());
    }

    void permute( const string & str, int low, int high)
    {
    // base case of the recursion
    if(low==high || low>high) {
    cout << str << endl;
    return;
    }

    // fix the first character in its place, and permute the rest
    string copy_str = str;
    permute(copy_str, low+1, high);

    for(int i=low+1 ; i<high ; i++) { // fix the (low+1)th char, permute rest
    // if ith and lowth char are the same, no need to swap them and no need to call permute
    if(str[low]!=str[i]) {
    string copy_str = str;
    char temp=copy_str[low];

    copy_str[low]=copy_str[i];
    copy_str[i] =temp;

    permute(copy_str, low+1, high);
    }
    }
    }

    //What are these lines of code doing in this function?
    string copy_str = str;
    char temp=copy_str[low];

    copy_str[low]=copy_str[i];
    copy_str[i] =temp;
    [CODE]

  2. #2
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    You are kidding, right?

    The format for code is....


    [code]

    your code....

    [/code]


    which would look like...

    Code:
    your code....
    and would respect your identination - given you used identination.
    Last edited by darksaidin; 08-25-2003 at 06:25 AM.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read Causes Freezing?
    By Masna in forum C Programming
    Replies: 5
    Last Post: 07-18-2008, 04:31 PM
  2. Read() problems
    By yay4rei in forum C Programming
    Replies: 2
    Last Post: 07-21-2005, 10:47 AM
  3. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 04:23 PM
  4. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 03:32 PM
  5. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 03:49 PM