123
123
{
if (index == s.size())
{
pset.push_back(curr);
return;
}
PowerSet(s, curr, index + 1, pset);
PowerSet(s, curr + s[index], index + 1, pset);
}
vector<string> pSet(string s)
{
vector<string> result;
PowerSet(s, "", 0, result);
return result;
}
int main1()
{
string S;
cout << "Enter a string: ";
cin >> S;
vector<string> result = pSet(S);
cout << "Power Set: ";
for (const auto& subset : result)
{
cout << "\"" << subset << "\" ";
}
cout << endl;
return 0;
}
}
void push(const T& value)
{
if (isFull())
{
cout << "Queue is full";
return;
}
if (empty()) {
front = 0;
}
back = (back + 1) % capacity;
arr[back] = value;
size++;
}
void pop()
{
if (empty())
{
cout << "Queue is empty" << endl;
return;
}
if (size == 1)
{
front = -1;
back = -1;
}
else
{
front = (front + 1) % capacity;
}
size--;
}
int FRONT() const
{
if (empty())
{
cout << "Queue is empty" << endl;
return T();
}
return arr[front];
}
T BACK() const
{
if (empty())
{
cout << "Queue is empty" << endl;
return T();
}
return arr[back];
}
int Size() const
{
return size;
}
};
#pragma once
#include <iostream>
using namespace std;
template<typename T>
class Stack
{
private:
T* arr;
int capacity;
int top;
public:
Stack(int cap) {
capacity = cap;
arr = new T[capacity];
top = -1;
}
~Stack()
{
delete[]arr;
}
void push(const T& value)
{
if (top==capacity-1)
{
cout << "stack is full" << endl;
return;
}
top++;
arr[top] = value;
}
void pop()
{
if (top == - 1)
{
cout << "stack empty" << endl;
return;
}
top--;
}
void Top()
{
if (top == -1) {
cout << "Stack empty" << endl;
return T();
}
return arr[top];
}
bool empty()
{
return top == -1;
}
int size()
{
return top+1;
}
bool isFull()
{
return top == capacity - 1;
}
friend ostream& operator<<(ostream& os, const Stack<T>& stack)
{
if (stack.top == -1)
{
os << "Stack is empty.";
}
else {
for (int i = stack.top; i >= 0; i--)
{
os << stack.arr[i] << " ";
}
}
return os;
}
};
*class Solution {
public:
bool isValid(string s)
{
stack<char> A ;
for (int i = 0 ; i< s.length() ; i++)
{
char ch = s[i];
else {
if (!A.empty())
{
char top = A.top() ;
if ((ch == ')' && top == '(') ||
(ch == '}' && top == '{') ||
(ch == ']' && top == '['))
{
A.pop() ;
}
else
{
return false ;
}
}
else
{
return false ;
}
}
}
if (A.empty())
{
return true ;
}
return false ;
}
};*/