diff --git a/strings/README.md b/strings/README.md index d4f59a56..2724a0ad 100644 --- a/strings/README.md +++ b/strings/README.md @@ -3,6 +3,7 @@ ### C or C++ 1. [Palindrome Check](c-or-cpp/palindrome.c) +2. [All subsequences](c-or-cpp/sequence.cpp) ### C# You could use any online IDE (for an example [.net Finddle](https://dotnetfiddle.net/)) to test them. @@ -16,3 +17,4 @@ You could use any online IDE (for an example [.net Finddle](https://dotnetfiddle ### Java 1. [Palindrome Check](java/palindrome.java) +2. [All subsequences](java/sequence.java) diff --git a/strings/c-or-cpp/sequence.cpp b/strings/c-or-cpp/sequence.cpp new file mode 100644 index 00000000..290f8b91 --- /dev/null +++ b/strings/c-or-cpp/sequence.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +//pick and don't pick algorithm +//recrsion to print all subsequence + +void permute(string t, int i, int n, string s){ + if(i==n) + { + cout< al = new ArrayList<>(); + + + public static void main(String[] args) + { + String s = "abc"; + findsubsequences(s, ""); + System.out.println(al); + } + + private static void findsubsequences(String s, + String ans) + { + if (s.length() == 0) { + al.add(ans); + return; + } + + + findsubsequences(s.substring(1), ans + s.charAt(0)); + + findsubsequences(s.substring(1), ans); + } +} \ No newline at end of file