'Print all the subsequences of a string using recursion

I have tried a approach of print all the subsequences of a stirng using recursion but not able to implement this how can i print all the subsequences of a string in lexicographical order. INPUT:- abc OUTPUT: a b c ab ac bc abc

I have tried this approach to print all the subsequences of a string:

void print(string s,string temp)
{
    if(s.empty()){
        cout<<temp<<endl;
        return;
    }
    print(s.substr(1),temp + s[0]);
    print(s.substr(1),temp);
}


Solution 1:[1]

What you want to have is a so called power set. Please read here about that.

There are som many examples for recursive approaches, that I will not show my onw solution. Maybe best for you would be:

this

And, if you want to have a little bit more background information then please look here

Solution 2:[2]

A solution to this problem might be using props:

// SomeComponent.js class
class SomeComponent {
    // Uncomment if you need to set a state
    //constructor(props) {
    //    super(props);
    //
    //    this.state = {};
    //}

    render() {
        let width = Math.min(Math.max(this.props.width, SOME_MAX_WIDTH), SOME_MIN_WIDTH); // clamp (optional)

        return ( // replace with your component
            <div style={{width: width, backgroundColor: "#23a4f6"}}>
                Width set from parent (and clamped)
            </div>
        );
    }
}
SomeComponent.defaultProps = {
    width: 200
};

// SomeComponent.js in functional
function SomeComponent({width}) {
    let width = Math.min(Math.max(this.props.width, SOME_MAX_WIDTH), SOME_MIN_WIDTH); // clamp (optional)

    return ( // replace with your component
        <div style={{width: width, backgroundColor: "#23a4f6"}}>
            Width set from parent (and clamped)
        </div>
    );
}
SomeComponent.defaultProps = {
    width: 200
};

// main.js
ReactDOM.render(<SomeComponent />, document.querySelector(".myelement"));

Solution 3:[3]

You can take width variable like let width = '100px' and then apply this variable to your code like this. here width you can pass as a prop which could be any value

let width = '100px';
<div className="white-box v-align ht-100" style={{ width: width, marginRight: '10px' }}>
                        <div className="flex-one"></div>
                        <div className="wd-80">
                            <div className="fs-xl fw-bold" style={{ color: '#142654' }}>{pct}%</div>
                            <div className="small-text">{text}</div>
                        </div>
                        </div>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ahmed Shaqanbi
Solution 3 Riyaz Panarwala