0% found this document useful (0 votes)
12 views5 pages

123

Uploaded by

bscs23149
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

123

Uploaded by

bscs23149
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

void PowerSet(const string& s, string curr, int index, vector<string>& pset)

{
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;
}

int FastPower(int a, int k)


{
if (k == 0)
{
return 1;
}
if (k % 2 == 0)
{
int hpower = FastPower(a, k / 2);
return hpower * hpower;
}
else
{
double hpower = FastPower(a, (k - 1) / 2);
return a * hpower * hpower;
}
}
#pragma once
#pragma once
#include <iostream>
using namespace std;
template<typename T>
class Queue
{
private:
T* arr;
int front;
int back;
int size;
int capacity;
public:
Queue(int cap)
{
capacity = cap;
front = -1;
back = -1;
size = 0;
arr = new T[capacity];
}
~Queue()
{
delete[]arr;
}
bool isFull() const
{
return size == capacity;
}
bool empty() const
{
return size == 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];

if (ch == '(' || ch == '{' || ch == '[')


{
A.push(ch) ;
}

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 ;
}
};*/

You might also like