max[0])
- swap(max[x1-1],max[0]);
- }
- else
- {
- //int p=x2-1;
- // cout<1||(x2-x1)>1)
-{
- long long int p,q,r,s;
-
- if(x1>x2)
- {
- swap(max[x1-1],max[0]);
- q=--x1;
- p=x2++;
- min[p]=max[q];
- swap(min[0],min[x2-1]);
- MaxH(max,x1);
- }
- else
- {
- swap(min[x2-1],min[0]);
- s=--x2;
- r=x1++;
- max[r]=min[s];
- swap(max[0],max[x1-1]);
- MinH(min,x2);
- }
- //for(long long int i=0;ix2)
-{
- mid=double(max[0]);
- //cout<
-
-using namespace std;
-
-#define N 9
-
-
-/*
-0 0 5 0 0 0 0 0 0
-0 0 0 0 0 7 0 3 1
-0 0 8 6 0 0 0 4 0
-
-0 9 4 8 0 0 0 0 0
-0 5 0 0 0 6 0 0 0
-8 1 0 0 0 5 0 0 0
-
-0 0 0 3 7 0 4 0 5
-0 0 1 4 0 0 0 6 0
-0 7 0 0 0 0 0 0 0
-*/
-/*
-8 0 1 7 0 2 0 4 0
-0 0 6 4 0 0 0 3 0
-3 0 0 5 0 0 0 0 0
-
-0 0 7 3 9 0 0 0 0
-0 6 8 1 0 5 4 9 0
-0 0 0 0 2 8 7 0 0
-
-0 0 0 0 0 6 0 0 2
-0 3 0 0 0 7 9 0 0
-0 4 0 2 0 3 5 0 7
-
-*/
-
-
-/*
-0 0 0 2 6 0 7 0 1
-6 8 0 0 7 0 0 9 0
-1 9 0 0 0 4 5 0 0
-8 2 0 1 0 0 0 4 0
-0 0 4 6 0 2 9 0 0
-0 5 0 0 0 3 0 2 8
-0 0 9 3 0 0 0 7 4
-0 4 0 0 5 0 0 3 6
-7 0 3 0 1 8 0 0 0
-
-*/
-
-void print(std::vector > grid)
-{
- cout<<"\n";
- for(int i=0;i > grid)
-{
- //cout<<"Checking violation...";
- //print(grid);
- for(int i=0;i > grid)
-{
- //print(grid);
- for(int i=0;i > solve(std::vector > grid,int curr_i=0,int curr_j=0)
-{
- std::vector > temp(N,std::vector (N,0));
- if(curr_i*N+curr_j>=N*N)
- {
- return grid;
- }
- if(grid[curr_i][curr_j])
- {
- return solve(grid,curr_i+(curr_j+1)/N,(curr_j+1)%N);
- }
- for(int i=1;i<=N;i++)
- {
- grid[curr_i][curr_j]=i;
- //cout< > grid(N,std::vector (N,0));
-
- for(int i=0;i>grid[i][j];
- }
-
- grid=solve(grid);
- if(!complete(grid))
- {
- cout<<"Unsolvable\n";
- return 0;
- }
- print(grid);
- return 0;
-}
-//
diff --git a/C++/8puzzle.cpp b/C++/8puzzle.cpp
deleted file mode 100644
index 9581b4121..000000000
--- a/C++/8puzzle.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-#include
-#include
-using namespace std;
-
-map > , bool> visited;
-map > , vector > > parent;
-vector > goal(3,vector (3));
-
-bool visit(vector > a)
-{
- if(visited[a]==true)
- return true;
- else
- return false;
-}
-
-int manhattan(vector > a , int moves)
-{
- int dist=moves;
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- if(a[i][j]!=0)
- {
- for(int k=0;k<3;k++)
- {
- for(int l=0;l<3;l++)
- {
- if(a[i][j]==goal[k][l])
- dist+=abs(i-k)+abs(j-l);
- }
- }
- }
- }
- }
-
- return dist;
-}
-
-bool isGoal(vector > a)
-{
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- if(a[i][j]!=goal[i][j])
- return false;
- }
- }
-
-return true;
-}
-
-bool safe(int i,int j)
-{
- if(i>=0 && i<=2 && j>=0 && j<=2)
- return true;
- else
- return false;
-}
-int dx[]={-1,+1,0,0};
-int dy[]={0,0,-1,+1};
-vector > > neighbours(vector > a)
-{
- pair pos;
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- if(a[i][j]==0)
- {
- pos.first=i;
- pos.second=j;
- break;
- }
- }
- }
- vector > > ans;
- for(int k=0;k<4;k++)
- {
- int cx = pos.first;
- int cy = pos.second;
- vector > n = a;
- if(safe(cx+dx[k],cy+dy[k]))
- {
- swap(n[cx+dx[k]][cy+dy[k]],n[cx][cy]);
- ans.push_back(n);
- }
- }
-
-return ans;
-}
-
-typedef pair > , int> state;
-
-struct cmp
-{
- bool operator() (state &a, state &b)
- {
- int am = manhattan(a.first,a.second);
- int bm = manhattan(b.first,b.second);
- return am > s)
-{
- if(parent.count(s))
- print_path(parent[s]);
-
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- printf("%d ",s[i][j]);
- }
- cout< > s)
-{
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- printf("%d ",s[i][j]);
- }
- cout< > a, int moves)
- {
-
- priority_queue,cmp > Q;
- Q.push(state(a,moves));
- while(!Q.empty())
- {
- vector > s = Q.top().first;
- Q.pop();
-
- visited[s]=true;
- //print(s);
- if(s==goal)
- {
- // printf("yeah\n");
- print_path(s);
- break;
- }
- vector > > ns = neighbours(s);
- vector > >::iterator it;
- //printf("1..\n");
- for(it=ns.begin();it!=ns.end();it++)
- {
- //print(*it);
- //cout< > temp = *it;
- if(!visit(temp))
- {
- parent.insert(pair > , vector > >(temp,s));
- Q.push(state(temp,moves+1));
- }
- }
- }
- return;
- }
-
-int main()
-{
- vector > a(3,vector (3));
- //vector > goal(3,vector (3));
-
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- cin>>a[i][j];
- }
- }
- cout<<"Solution...\n\n";
- goal[0][0] = 1;
- goal[0][1] = 2;
- goal[0][2] = 3;
- goal[1][0] = 4;
- goal[1][1] = 5;
- goal[1][2] = 6;
- goal[2][0] = 7;
- goal[2][1] = 8;
- goal[2][2] = 0;
-
- solve(a,0);
-}
\ No newline at end of file
diff --git a/C++/A-small-step-towards-calculators.cpp b/C++/A-small-step-towards-calculators.cpp
deleted file mode 100644
index 3cac2110a..000000000
--- a/C++/A-small-step-towards-calculators.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-#include
-
-using namespace std;
-
-int solve(char* opr) {
- int x=((int)*opr-48);
- int y=((int)*(opr+2)-48);
- int z=(int)*(opr+1);
- return z=='+'? x+y:x-y;
-}
-int main() {
- char* opr = (char *)malloc(512000 * sizeof(char));
- cin >> opr;
- int result = solve(opr);
- cout << result << endl;
- return 0;
-}
diff --git a/C++/A-smallstep toward calculators.h b/C++/A-smallstep toward calculators.h
deleted file mode 100644
index 827a8e91a..000000000
--- a/C++/A-smallstep toward calculators.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#include
-
-using namespace std;
-
-int solve(char* opr) {
- int x=((int)*opr-48);
-int y=((int)*(opr+2)-48);
-int z=(int)*(opr+1);
-if(z=='+')
-{ return x+y;
-}
-else
-{ return x-y;
-}
-}
-int main() {
- char* opr = (char *)malloc(512000 * sizeof(char));
- cin >> opr;
- int result = solve(opr);
- cout << result << endl;
- return 0;
-}
diff --git a/C++/Add Operator Overloading.cpp b/C++/Add Operator Overloading.cpp
deleted file mode 100644
index 25093f340..000000000
--- a/C++/Add Operator Overloading.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-#include
-#include
-#include
-
-using namespace std;
-
-class time{
-
- public:
- int hrs,min,secs;
-
- time(){
- hrs=0;
- min=0;
- secs=0;
- }
-
- public:
- void set(){
- cout<<"\nEnter time in hrs";
- cin>>hrs;
- cout<<"\nEnter time in min";
- cin>>min;
- cout<<"\nEnter time in sec";
- cin>>secs;
-
- }
-
- void show()
- {
- cout<<"\nHours"<=60){
-
- temp.secs=temp.secs%60;}
-
- if(temp.min>=60){
- temp.min=temp.min%60;}
- return temp;
-
-}
-time time::operator-(time t2){
- if(t2.hrs
-using namespace std;
-
-int main()
-{
-//declare variable a,b,c as of type Integer
- int a , b , c;
-// input value of variable a and b
- cin >> a;
- cin >> b;
-//sum values of a and b and assign in c
- c = a + b;
-//show the value of c on the console.
- cout << c;
-
-
-}
diff --git a/C++/AllVowels.cpp b/C++/AllVowels.cpp
deleted file mode 100644
index 8fab026b4..000000000
--- a/C++/AllVowels.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include
-
-using namespace std;
-
-int main()
-{
- int n;
- cin >> n;
- string st;
- cin >> st;
- vector vec(5,0);
- for(int i=0;i
-#define ll long long
-
-using namespace std;
-
-int main(){
- // #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- // #endif
- int t;
- cin>>t;
- while(t--){
- string s1,s2;
- cin>>s1>>s2;
- int h1[26],h2[26];
- memset(h1,0,sizeof h1);
- memset(h2,0,sizeof h2);
- int len1=s1.length(),len2=s2.length();
- if(len1==len2){
- for(int i=0;i
-
-using namespace std;
-
-int main()
-{
- int n;
- cin >> n;
- cout << "I'll not print your n" << endl;
-}
diff --git a/C++/Armstrong.cpp b/C++/Armstrong.cpp
deleted file mode 100644
index 5461da839..000000000
--- a/C++/Armstrong.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include
-using namespace std;
-int main()
-{
-int arm=0,a,b,c,d,no;
-cout << "Enter any number" << endl;
-cin >> no;
-d = no;
-while( no!= 0){
- a=no%10;
- arm+=a*a*a;
- no=no/10;
-}
-if(arm==d)
- cout<<"Yes "<
-using namespace std;
-int main(){
- int array[] = {1,2,3,4,5,6,7,8,9,0}
- for(int i = 9;i>=0;i--){
- cout<
-#include
-
-void main()
-{
- clrscr();
- int n,a[100]][100], temp;
- cout<<"\nenter the size of array";
- cin>>n;
- cout<<"\nenter the array";
- for(i=0;i>a[i][j];
- }
-
- for(i=0;ia[j])
- {
- a[i]=a[i]^a[j];
- a[j]=a[i]^a[j];
- a[i]=a[i]^a[j];
- flag = 1;
- }
- }
- // Break out of loop if no swaps are made in a particular outer iteration
- if(!flag)
- break;
- }
- cout<<"\nSORTED ARRAY";
- for(i=0;i>a[i][j];
- }
- getch();
-}
diff --git a/C++/Ashutosh.cpp b/C++/Ashutosh.cpp
deleted file mode 100644
index 55b5e68a8..000000000
--- a/C++/Ashutosh.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#include
-using namespace std;
-int main()
-{
- cout<<"Hello world" ;
-}
diff --git a/C++/AvlTree.cpp b/C++/AvlTree.cpp
deleted file mode 100644
index 0637677d5..000000000
--- a/C++/AvlTree.cpp
+++ /dev/null
@@ -1,247 +0,0 @@
-#include
-#define type int
-using namespace std;
- int test=1;
-class node
-
-{//begin node class
-private:
-
-public:
-type data;
- node *left;
- node *right;
- int height;
- friend class AVL;
-
-};//end of node class
-
-class AVL
-{//begin AVL
-private:
-
-
-public:
- node* rotate_right(node* n);
- node* rotate_left(node* n);
-node *root=NULL;
-node* get_root();//def
-node* ins(node* n,type x);//def
-node* del(node* n,type x);
-node* LL(node *n);
-node* RR(node *n);
-node* LR(node *n);
-node* RL(node *n);
-node* balance(node *temp);
-void preorder(node *n);
-void inorder(node *n);
-int get_height(node* n);
-int Balance_factor(node* n);//def
-};//end AVL
-//begin AVL functions
-void AVL::preorder(node *n)
-{
-if(n!=NULL)
-{
-cout<<" "<data;
-preorder(n->left);
-preorder(n->right);
-}
-
-}
-node* AVL::balance(node* temp)
-{
- int bal_factor = Balance_factor(temp);
- if (bal_factor > 1)
- {
- if (Balance_factor(temp->left) > 0)
- temp = LL(temp);
- else
- temp = LR(temp);
- }
- else if (bal_factor < -1)
- {
- if (Balance_factor(temp->right) > 0)
- temp = RL(temp);
- else
- temp = RR(temp);
- }
- return temp;
-}
-
-
-
-
-
-node* AVL::get_root()
-{//begin get root
-return root;
-}//end get_root
-node* AVL::ins(node* n,type x)
-{//begin ins
-//cout<<"here in ins"<data=x;
- y->left=NULL;
- y->right=NULL;
- n=y;
- if(test==1)cout<<"Root added "<data<n->data)
- {//begin if
-
- n->right=ins(n->right,x);
-
- cout<data<left=ins(n->left,x);
- cout<data<left;
-n->left=temp->right;
-temp->right=n;
-n->height=get_height(n);
-temp->height=get_height(temp);
-return temp;
-}//end rotate right
-node* AVL::rotate_left(node* n)
-{//begin rotate left
-node* temp=new node();
-temp=n->right;
-n->right=temp->left;
-temp->left=n;
-n->height=get_height(n);
-temp->height=get_height(temp);
-cout<<"Rotating left\n";
-return temp;
-
-}//end rotate left
-int AVL::Balance_factor(node* n)
-{//begin balance factor
-int l_height = get_height(n->left);
- int r_height = get_height (n->right);
- int b_factor= l_height - r_height;
- return b_factor;
-
-
-}//end balance factor
-
-int AVL::get_height(node* n)
-{//begin get_height
-int h=0;
- if (n!= NULL)
- {
- int l_height = get_height (n->left);
- int r_height = get_height (n->right);
- int max_height = max (l_height, r_height);
- h = max_height + 1;
- }
-
- return h;
-
-}//end get_height
-
-node* AVL::LL(node* n)
-{//begin LL
-n=rotate_right(n);
-cout<<"LL DONE\n";
-return n;
-}//end LL
-
-node* AVL::RR(node* n)
-{//begin RR
-n=rotate_left(n);
-cout<<"RR DONE\n";
-return n;
-}//end RR
-
-node* AVL::RL(node* n)
-{//begin RL
-n->right=rotate_right(n->right);
-n=rotate_left(n);
-cout<<"RL DONE\n";
-return n;
-}//end RL
-
-node* AVL::LR(node* n)
-{//begin LR
-n->left=rotate_left(n->left);
-n=rotate_right(n);
-cout<<"LR DONE\n";
-return n;
-}//end LR
-void AVL::inorder(node* n)
-{
-if(n!=NULL)
-{
-inorder(n->left);
-cout<<" "<data;
-inorder(n->right);
-
-
-}
-
-
-}
-//end AVL functions
-
-int main()
-{//begin main
- AVL tree;
- int choice;
- cout<<"Enter option\n1.create\n2.add\n3.inorder dispaly\n4.preorder display\n0.exit\n";
- cin>>choice;
- type s;
- while(choice!=0)
- {
- switch(choice)
-
- {
- case 1:cin>>s;
- tree.root=tree.ins(tree.get_root(),s);
- break;
- case 2:cin>>s;
- tree.root=tree.ins(tree.get_root(),s);
- break;
- case 3:tree.inorder(tree.get_root());
- cout<>choice;
- }
- return 0;
-}//end main
diff --git a/C++/Beautiful-Days-at-the-Movies b/C++/Beautiful-Days-at-the-Movies
deleted file mode 100644
index 43c322bb6..000000000
--- a/C++/Beautiful-Days-at-the-Movies
+++ /dev/null
@@ -1,27 +0,0 @@
-#include
-#include
-#include
-#include
-
-static int do_reverse(const int& x) {
- std::string s = std::to_string(x);
- for (size_t i = 0; i < s.length()/2; ++i)
- std::swap(s[i], s[s.length()-i-1]);
-
- return std::stoi(s);
-}
-
-int main(void) {
-
- int i,j,k;
- std::cin >> i >> j >> k;
-
- unsigned long long count = 0;
- for (int x = i ; x <= j; ++x)
- if (std::abs(x-do_reverse(x)) % k == 0)
- count++;
-
- std::cout << count << '\n';
-
- return 0;
-}
diff --git a/C++/Best_Buying_and_Selling_days_for _stock b/C++/Best_Buying_and_Selling_days_for _stock
deleted file mode 100644
index 47d3f3780..000000000
--- a/C++/Best_Buying_and_Selling_days_for _stock
+++ /dev/null
@@ -1,74 +0,0 @@
-// Program to find best buying and selling days
-#include
-
-// solution structure
-struct Interval
-{
- int buy;
- int sell;
-};
-
-// This function finds the buy sell schedule for maximum profit
-void stockBuySell(int price[], int n)
-{
- // Prices must be given for at least two days
- if (n == 1)
- return;
-
- int count = 0; // count of solution pairs
-
- // solution vector
- Interval sol[n/2 + 1];
-
- // Traverse through given price array
- int i = 0;
- while (i < n-1)
- {
- // Find Local Minima. Note that the limit is (n-2) as we are
- // comparing present element to the next element.
- while ((i < n-1) && (price[i+1] <= price[i]))
- i++;
-
- // If we reached the end, break as no further solution possible
- if (i == n-1)
- break;
-
- // Store the index of minima
- sol[count].buy = i++;
-
- // Find Local Maxima. Note that the limit is (n-1) as we are
- // comparing to previous element
- while ((i < n) && (price[i] >= price[i-1]))
- i++;
-
- // Store the index of maxima
- sol[count].sell = i-1;
-
- // Increment count of buy/sell pairs
- count++;
- }
-
- // print solution
- if (count == 0)
- printf("There is no day when buying the stock will make profitn");
- else
- {
- for (int i = 0; i < count; i++)
- printf("Buy on day: %dt Sell on day: %dn", sol[i].buy, sol[i].sell);
- }
-
- return;
-}
-
-// Driver program to test above functions
-int main()
-{
- // stock prices on consecutive days
- int price[] = {100, 180, 260, 310, 40, 535, 695};
- int n = sizeof(price)/sizeof(price[0]);
-
- // fucntion call
- stockBuySell(price, n);
-
- return 0;
-}
diff --git a/C++/Binary Index Tree (Fenwick Tree).cpp b/C++/Binary Index Tree (Fenwick Tree).cpp
deleted file mode 100644
index c1a2a3346..000000000
--- a/C++/Binary Index Tree (Fenwick Tree).cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include
-#include
- using namespace std;
-
-template
-class fenwick {
- public:
- vector fenw;
- int n;
-
- // Constructor for initialization of size
- fenwick(int _n) : n(_n + 1) {
- fenw.resize(n);
- }
-
- // to modify , add or replace value at index x
- void modify(int x, T v) {
- while (x <= n) {
- fenw[x] += v;
- x += (x & -x);
- }
- }
-
- // To get sum of prefix ending at x
- T get(int x) {
- T v{};
- while (x > 0) {
- v += fenw[x];
- x -= (x & -x);
- }
- return v;
- }
-};
-
-
-int main(){
- vector ar = {1 , 2 , 3 , 4 , 5};
- fenwick F(5);
- for(int i = 0 ; i < (int) ar.size() ; ++i){
- F.modify(i + 1 ,ar[i]);
- }
- for(int i = 0 ; i < (int) ar.size() ; ++i){
- cout << F.get(i + 1) << ' ';
- }
- cout << '\n';
- return 0;
-}
diff --git a/C++/Binary Search Without Recursion b/C++/Binary Search Without Recursion
deleted file mode 100644
index 30a1284ad..000000000
--- a/C++/Binary Search Without Recursion
+++ /dev/null
@@ -1,52 +0,0 @@
-#include
-using namespace std;
-
-void input(int arr[] , int N)
-{
- for(int i = 0 ; i < N ; i++)
- {
- cin >> arr[i];
- }
-}
-
-int BinarySearch(int arr[] , int N , int x)
-{
- int be = 0;
- int end = N-1;
-
- while(be <= end)
- {
- int mid = (be + end + 1)/2;
- if(arr[mid] == x) return mid;
-
- else if(arr[mid] < x)
- {
- be = mid+1;
- continue;
- }
-
- else
- {
- end = mid - 1;
- continue;
- }
- }
-
- return -1;
-
-}
-
-int main()
-{
- int N , x;
- cin >> N;
-
- int arr[N];
-
- input(arr , N);
-
- cin >> x;
-
- cout << "Position = " << BinarySearch(arr , N , x);
-
-}
diff --git a/C++/Binary Search!! b/C++/Binary Search!!
deleted file mode 100644
index 259a00046..000000000
--- a/C++/Binary Search!!
+++ /dev/null
@@ -1,41 +0,0 @@
-#include
-using namespace std;
-
-//This will take the input array from the user
-void input(int arr[] , int N)
-{
- for(int i = 0 ; i < N ; i++)
- {
- cin >> arr[i];
- }
-}
-
-//This function will search for the given key element in the array
-int binarySearch(int arr[] , int start , int end , int x)
-{
- if(start > end)
- return -1;
-
- int mid = (start+end+1)/2;
-
- if(arr[mid] == x)
- return mid;
- else if(arr[mid] < x)
- return binarySearch(arr , mid + 1, end , x);
- else if(arr[mid] > x)
- return binarySearch(arr , 0 , mid - 1 , x);
-}
-
-int main()
-{
- int N , x;
- cin >> N;
-
- int arr[N];
-
- input(arr , N);
-
- cin >> x;
-
- cout << "Position = " << binarySearch(arr , 0 , N-1 , x);
-}
diff --git a/C++/BinarySearch.cpp b/C++/BinarySearch.cpp
deleted file mode 100644
index ae8602fe4..000000000
--- a/C++/BinarySearch.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-#include
-using namespace std;
-bool BinarySearch(int arr[], int n, int k){
- int s=0;int e=n-1;
- while (s<=e){
- int mid=(s+e)/2;
- if (arr[mid]==k) return true;
- if (arr[mid]>arr[i];
- cout<<"enter the number you want to search";
- cin>>target;
- if(BinarySearch(arr,n,target) cout<<"The number exists"<
-
-int current[5][5], maximum_claim[5][5], available[5];
-int allocation[5] = {0, 0, 0, 0, 0};
-int maxres[5], running[5], safe = 0;
-int counter = 0, i, j, exec, resources, processes, k = 1;
-
-int main()
-{
- printf("\nEnter number of processes: ");
- scanf("%d", &processes);
-
- for (i = 0; i < processes; i++)
- {
- running[i] = 1;
- counter++;
- }
-
- printf("\nEnter number of resources: ");
- scanf("%d", &resources);
-
- printf("\nEnter Claim Vector:");
- for (i = 0; i < resources; i++)
- {
- scanf("%d", &maxres[i]);
- }
-
- printf("\nEnter Allocated Resource Table:\n");
- for (i = 0; i < processes; i++)
- {
- for(j = 0; j < resources; j++)
- {
- scanf("%d", ¤t[i][j]);
- }
- }
-
- printf("\nEnter Maximum Claim Table:\n");
- for (i = 0; i < processes; i++)
- {
- for(j = 0; j < resources; j++)
- {
- scanf("%d", &maximum_claim[i][j]);
- }
- }
-
- printf("\nThe Claim Vector is: ");
- for (i = 0; i < resources; i++)
- {
- printf("\t%d", maxres[i]);
- }
-
- printf("\nThe Allocated Resource Table:\n");
- for (i = 0; i < processes; i++)
- {
- for (j = 0; j < resources; j++)
- {
- printf("\t%d", current[i][j]);
- }
- printf("\n");
- }
-
- printf("\nThe Maximum Claim Table:\n");
- for (i = 0; i < processes; i++)
- {
- for (j = 0; j < resources; j++)
- {
- printf("\t%d", maximum_claim[i][j]);
- }
- printf("\n");
- }
-
- for (i = 0; i < processes; i++)
- {
- for (j = 0; j < resources; j++)
- {
- allocation[j] += current[i][j];
- }
- }
-
- printf("\nAllocated resources:");
- for (i = 0; i < resources; i++)
- {
- printf("\t%d", allocation[i]);
- }
-
- for (i = 0; i < resources; i++)
- {
- available[i] = maxres[i] - allocation[i];
- }
-
- printf("\nAvailable resources:");
- for (i = 0; i < resources; i++)
- {
- printf("\t%d", available[i]);
- }
- printf("\n");
-
- while (counter != 0)
- {
- safe = 0;
- for (i = 0; i < processes; i++)
- {
- if (running[i])
- {
- exec = 1;
- for (j = 0; j < resources; j++)
- {
- if (maximum_claim[i][j] - current[i][j] > available[j])
- {
- exec = 0;
- break;
- }
- }
- if (exec)
- {
- printf("\nProcess%d is executing\n", i + 1);
- running[i] = 0;
- counter--;
- safe = 1;
-
- for (j = 0; j < resources; j++)
- {
- available[j] += current[i][j];
- }
- break;
- }
- }
- }
- if (!safe)
- {
- printf("\nThe processes are in unsafe state.\n");
- break;
- }
- else
- {
- printf("\nThe process is in safe state");
- printf("\nAvailable vector:");
-
- for (i = 0; i < resources; i++)
- {
- printf("\t%d", available[i]);
- }
-
- printf("\n");
- }
- }
- return 0;
-}
\ No newline at end of file
diff --git a/C++/Bubble Sort!! b/C++/Bubble Sort!!
deleted file mode 100644
index 5f39034b0..000000000
--- a/C++/Bubble Sort!!
+++ /dev/null
@@ -1,43 +0,0 @@
-#include
-using namespace std;
-
-void input(int arr[], int N)
-{
- for(int i = 0 ; i < N ; i++)
- {
- cin >> arr[i];
- }
-}
-
-void bubbleSort(int arr[] , int N)
-{
- for(int curIteration = 1 ; curIteration < N ; curIteration++)
- {
- for(int curElement = 0 ; curElement < N - curIteration ; curElement++)
- {
- if(arr[curElement] > arr[curElement+1]) swap(arr[curElement] , arr[curElement+1]);
- }
- }
-}
-
-void output(int arr[], int N)
-{
- for(int i = 0 ; i < N ; i++)
- {
- cout << arr[i] << " ";
- }
-}
-
-int main()
-{
- int N;
- cin >> N;
-
- int arr[N];
-
- input(arr , N);
-
- bubbleSort(arr , N);
-
- output(arr , N);
-}
diff --git a/C++/BuyingATVSet.cpp b/C++/BuyingATVSet.cpp
deleted file mode 100644
index 7d6e41522..000000000
--- a/C++/BuyingATVSet.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include
-#include
-using namespace std;
-
-typedef unsigned long long int ulli;
-
-
-int main() {
- ulli a, b, x, y, gcdiv;
- cin>>a>>b>>x>>y;
-
- gcdiv = __gcd(x, y);
-
- x /= gcdiv;
- y /= gcdiv;
-
- cout<
-#include
-using namespace std;
-
-int main(void)
-{
- int b, h, A, a, c, d, e, f, s;
- cout<<"calculating an area of a triangle"<>a;
- if(a==1)
- {
- cout<<"enter the base value: ";
- cin>>b;
- cout<>h;
- cout<>c;
- cout<<"/nLength of 2nd side: ";
- cin>>d;
- cout<<"/nLength of 3rd side: ";
- cin>>e;
- cout<
-int main()
-{
- cout<<"Hello World";
- return 0;
-}
diff --git a/C++/Chandu_and_his_Interns.cpp b/C++/Chandu_and_his_Interns.cpp
deleted file mode 100644
index a5008ba93..000000000
--- a/C++/Chandu_and_his_Interns.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include
-using namespace std;
-typedef long long int lli;
-int main(){
- lli input;
- lli x;
- lli count=0;
- lli temp=0;
- cin>>input;
- lli m=input;
- while(m--){
- cin>>x;
- temp=count=0;
- for(int i=1;i*i<=x;i++){
- if(x%i==0)
- if(i*i==x)
- count++;
- else
- count+=2;
- if(count>=4){
- temp=1;
- break;
- }
- }
- if(temp==1)
- cout<<"YES"<
-#define SIZE 5 /* Size of Circular Queue */
-
-using namespace std;
-
-class Queue {
-private:
- int items[SIZE], front, rear;
-
-public:
- Queue(){
- front = -1;
- rear = -1;
- }
-
- bool isFull(){
- if(front == 0 && rear == SIZE - 1){
- return true;
- }
- if(front == rear + 1) {
- return true;
- }
- return false;
- }
-
- bool isEmpty(){
- if(front == -1) return true;
- else return false;
- }
-
- void enQueue(int element){
- if(isFull()){
- cout << "Queue is full";
- } else {
- if(front == -1) front = 0;
- rear = (rear + 1) % SIZE;
- items[rear] = element;
- cout << endl << "Inserted " << element << endl;
- }
- }
-
- int deQueue(){
- int element;
- if(isEmpty()){
- cout << "Queue is empty" << endl;
- return(-1);
- } else {
- element = items[front];
- if(front == rear){
- front = -1;
- rear = -1;
- } /* Q has only one element, so we reset the queue after deleting it. */
- else {
- front=(front+1) % SIZE;
- }
- return(element);
- }
- }
-
- void display()
- {
- /* Function to display status of Circular Queue */
- int i;
- if(isEmpty()) {
- cout << endl << "Empty Queue" << endl;
- }
- else
- {
- cout << "Front -> " << front;
- cout << endl << "Items -> ";
- for(i=front; i!=rear;i=(i+1)%SIZE)
- cout << items[i];
- cout << items[i];
- cout << endl << "Rear -> " << rear;
- }
- }
-
-};
-
-
-int main()
-{
- Queue q;
-
- // Fails because front = -1
- q.deQueue();
-
- q.enQueue(1);
- q.enQueue(2);
- q.enQueue(3);
- q.enQueue(4);
- q.enQueue(5);
-
- // Fails to enqueue because front == 0 && rear == SIZE - 1
- q.enQueue(6);
-
-
- q.display();
-
- int elem = q.deQueue();
-
- if( elem != -1)
- cout << endl << "Deleted Element is " << elem;
-
- q.display();
-
- q.enQueue(7);
-
- q.display();
-
- // Fails to enqueue because front == rear + 1
- q.enQueue(8);
-
- return 0;
-}
diff --git a/C++/Conditionalopeator b/C++/Conditionalopeator
deleted file mode 100644
index 261f74ce9..000000000
--- a/C++/Conditionalopeator
+++ /dev/null
@@ -1,9 +0,0 @@
-#include
-using namespace std;
-int main()
-{
- bool inBigClassroom = 0; //
- const int classSize = inBigClassroom ? 30 : 20; //using conditional operator
- std::cout << "The class size is: " << classSize;
- return 0;
-}
diff --git a/C++/DDA.cpp b/C++/DDA.cpp
deleted file mode 100644
index a716ef688..000000000
--- a/C++/DDA.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include
-#include
-#include
-#include
-#include
-
-int sign(float a);
-void main()
-{
- int gd=DETECT,gm;
- int x1,x2,y1,y2,length,i;
- float dx,dy,x[100],y[100];
-
-
-
- cout<<"\n Enter x1 and y1:";
- cin>>x1>>y1;
- cout<<"\n Enter x2 and y2:";
- cin>>x2>>y2;
-
- dx=fabs(x2-x1);
- dy=fabs(y2-y1);
-
- if(dx>=dy)
- {
- length=dx;
- }
- else
- {
- length=dy;
- }
-
- dx=(float)(x2-x1)/length;
- dy=(float)(y2-y1)/length;
-
- x[0]=x1+0.5*sign(dx);
- y[0]=y1+0.5*sign(dy);
- i=1;
-
- while(i<=length)
- {
- // cout<0)
- return 1;
- else if(a==0)
- return 0;
- else
- return -1;
-}
diff --git a/C++/DELETE.cpp b/C++/DELETE.cpp
deleted file mode 100644
index 31752e56f..000000000
--- a/C++/DELETE.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include
-#include
-#include
-void main()
-{
- clrscr();
- int a[20],n,i,ele,b;
- cout<<"Enter the number of elements\n";
- cin>>n;
- cout<<"Enter the elements\n";
- for(i=0;i>a[i];
- cout<<"Enter the element to be deleted\n";
- cin>>ele;
- for(i=0;i
-#include
-#include
-using namespace std;
-typedef pair pii;
-
-class comp{ /// comparission in priority queue
-public:
- bool operator()(pii a, pii b){
- return a.second>b.second;
- }
-};
-
-class Graphs{
-private:
- list *adjList;
- int V;
-public:
- Graphs(int n){
- V=n;
- adjList=new list[V];
- }
- void addEdge(int s, int d, int wt){
- adjList[s].push_back(make_pair(d,wt));
- }
- int dijikstra(int s, int d){ ///algorigthm to find shortest distance
- priority_queue,comp> pq;
- int * distance=new int[V];
- for (int i=0;isecond+curDist;
- if (childDistfirst]){ ///check the distance shortest ahi tabhi update krna
- pq.push(make_pair(it->first,childDist));
- distance[it->first]=childDist;
- }
- }
- }
- for (int i=0;i> low >> high;
-
- cout << "Prime numbers between " << low << " and " << high << " are: ";
-
- while (low < high)
- {
- flag = 0;
-
- for(i = 2; i <= low/2; ++i)
- {
- if(low % i == 0)
- {
- flag = 1;
- break;
- }
- }
-
- if (flag == 0)
- cout << low << " ";
-
- ++low;
- }
-
- return 0;
-}
diff --git a/C++/DynamicProgramming/longest_common_subsequence.cpp b/C++/DynamicProgramming/longest_common_subsequence.cpp
deleted file mode 100644
index 5fda53270..000000000
--- a/C++/DynamicProgramming/longest_common_subsequence.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
-DYNAMIC PROGRAMMING
-
-The program finds the longest common subsequence between two strings,
-i.e. given two strings the program will find the longest common subsequence
-between them.
-
-eg. abcdaf(string 1)
- acbcf (string 2)
-
- lcs - abcf
-
-Wiki - https://en.wikipedia.org/wiki/Longest_common_subsequence_problem
-
-*/
-#include
-#include
-
-using namespace std;
-
-int main()
-{
- char arr[100], arr1[100];
- cout<<"\nEnter the first string: ";
- cin>>arr;
- cout<<"\nEnter the second string: ";
- cin>>arr1;
- int len_first,len_second;
- len_first = strlen(arr);
- len_second = strlen(arr1);
- int final_matrix[len_second + 1][len_first + 1];
- int i=0,j=0;
- for(i=0;i<=len_second;i++)
- {
- final_matrix[i][0] = 0;
- }
- for(i=0;i<=len_first;i++)
- {
- final_matrix[0][i] = 0;
- }
- for(i=1;i<=len_second; i++)
- {
- for(j=1;j<=len_first;j++)
- {
- if(arr1[i-1] == arr[j-1])
- {
- //cout<<"\nValue match is(i:j:val): "<
-#include
-using namespace std;
-int main()
-{
-clrscr();
-int n;
-cout << "Enter an integer: ";
- cin >> n;
- if ( n % 2 == 0)
-cout << n << " is even.";
- else
-cout << n << " is odd.";
-
-return 0;
-}
diff --git a/C++/FFT.hpp b/C++/FFT.hpp
deleted file mode 100644
index 0f72af28f..000000000
--- a/C++/FFT.hpp
+++ /dev/null
@@ -1,96 +0,0 @@
-#include // std::vector
-#include // std::complex
-
-#define _USE_MATH_DEFINES // M_PI
-#include // std::sin, std::cos
-
-using base_t = std::complex;
-using vCoef_t = std::vector;
-
-//====================================================================================================================================
-//!
-//! \brief Realization of FFT(Fast Fourier transform) - a method that allows calculating the DFT(discrete Fourier transform),
-//! which is used to convolve polynomials
-//!
-//! \param[out] A Array of polynomial coefficients; result will be here also
-//!
-//! T(N) = O(NlogN)
-//! M(N) = O(N)
-//!
-//====================================================================================================================================
-
-void FFT(vCoef_t &A)
-{
- auto N{ A.size() };
- if (N == 1)
- return;
-
- vCoef_t A0(N >> 1),
- A1(N >> 1);
- for (auto i{ 0ull }, j{ 0ull }; i < N; i += 2, ++j)
- {
- A0[j] = A[i];
- A1[j] = A[i + 1];
- }
-
- FFT(A0);
- FFT(A1);
-
- double alf = 2 * M_PI / static_cast(N);
-
- N >>= 1;
-
- base_t w{ 1 },
- wn{ std::cos(alf), std::sin(alf) };
- for (auto i{ 0ull }; i < N; ++i)
- {
- A[i] = A0[i] + w * A1[i];
- A[i + N] = A0[i] - w * A1[i];
-
- w *= wn;
- }
-}
-
-//====================================================================================================================================
-//!
-//! \brief Realization of IFFT(Inverse fast Fourier transform) algorithm, which is used to reconstruct
-//! the coefficients of the polynomial from the values at the points, the interpolation analog
-//!
-//! \param[out] A Array of polynomial coefficients; result will be here also
-//!
-//! T(N) = O(NlogN)
-//! M(N) = O(N)
-//!
-//====================================================================================================================================
-
-void IFFT(vCoef_t &A)
-{
- auto N = A.size();
- if (N == 1)
- return;
-
- vCoef_t A0(N >> 1),
- A1(N >> 1);
- for (auto i{ 0ull }, j{ 0ull }; i < N; i += 2, ++j)
- {
- A0[j] = A[i];
- A1[j] = A[i + 1];
- }
-
- IFFT(A0);
- IFFT(A1);
-
- double alf = -2 * M_PI / static_cast(N);
-
- N >>= 1;
-
- base_t w{ 1 },
- wn{ std::cos(alf), std::sin(alf) };
- for (auto i{ 0ull }; i < N; ++i)
- {
- A[i] = (A0[i] + w * A1[i]) / 2.;
- A[i + N] = (A0[i] - w * A1[i]) / 2.;
-
- w *= wn;
- }
-}
diff --git a/C++/Factorial b/C++/Factorial
deleted file mode 100644
index 290905bf5..000000000
--- a/C++/Factorial
+++ /dev/null
@@ -1,21 +0,0 @@
-# include
-using namespace std;
-
-long long factorial(int a); // 'long' for big integer value
-long long fct=1;
-int main(){
-int n;
-cout<<"Enter number for factorial"<>n;
-factorial(n);
-cout<<"Factorial = "<1)
- {fct=a*factorial(a-1);
- return fct;}
- else
- return 1;
- }
diff --git a/C++/Factorial.cpp b/C++/Factorial.cpp
deleted file mode 100644
index 66a9c07e7..000000000
--- a/C++/Factorial.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include
-using namespace std;
-int factorial(int n) //Factorial function
-{
- if(n==1 || n==0)
- return 1;
- else
- return n*factorial(n-1);
-}
-int main() //main function
-{
- int n;
- cout << "\nEnter a positive integer : ";
- cin >> n;
- cout << "\nThe Factorial of Number " << n << " is = " << factorial(n)<
-using namespace std;
-
-int main()
-{
- unsigned int n;
- unsigned long long factorial = 1;
-
- cout << "Enter a positive integer: ";
- cin >> n;
-
- for(int i = 1; i <=n; ++i)
- {
- factorial *= i;
- }
-
- cout << "Factorial of " << n << " = " << factorial;
- return 0;
-}
diff --git a/C++/Fibo.cpp b/C++/Fibo.cpp
deleted file mode 100644
index 7c4f36b9d..000000000
--- a/C++/Fibo.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include
-using namespace std;
-
-main ()
-{
- long long a=0,b=1,c,n;
- cout<<"Enter total number of Fibonacci= ";cin>>n;
-
- for(int i=1;i<=n;i++)
- {
- if(i==1)
- {
- c=1;
- }
- else
- {
- c=a+b;
- a=b;
- b=c;
- }
- if(i!=n) cout<
-using namespace std;
-int main(void)
-{
- int n,a=0,b=1,c=0;
- cout<<"Enter the number of term you want in fibonnaci series : ";
- cin>>n;
- for(int i =0; i
-using namespace std;
-
-struct Node
-{
- int data;
- struct Node* next;
-};
-
-void Print(struct Node *n,int search)
-{
- while (n!=NULL)
- {
- n->data;
-
- if (n->data==search)
- cout<<"Find \n";
- else
- cout<<"Not Find \n";
- n = n->next;
- }
-
-}
-
-int main()
-{
-
- int search = 2;
-
- struct Node* head =NULL;
- struct Node* second =NULL;
- struct Node* third =NULL;
-
- head = (struct Node*)malloc (sizeof(struct Node));
- second = (struct Node*)malloc (sizeof(struct Node));
- third = (struct Node*)malloc (sizeof(struct Node));
-
-
- head->data = 1;
- head->next = second;
-
- second->data = 2;
- second->next = third;
-
- third->data = 3;
- third->next = NULL;
-
- Print(head,search);
-
- return 0;
-}
diff --git a/C++/GCD2.cpp b/C++/GCD2.cpp
deleted file mode 100644
index 6013416d6..000000000
--- a/C++/GCD2.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include
-#include
-using namespace std;
-int main()
-{
- long long t,a,b=0;
- int len;
- string str;
- cin>>t;
- while(t--){
- b=0;
- cin>>a;
- cin>>str;
- if(a==0){
- cout<
-using namespace std;
-
-int main()
-{
- int n1, n2, n3, n4, c, max;
- cout<<"1. HCF\n";
- cout<<"2. LCM\n";
- cout<<"choice: ";
- cin>>c;
- if(c==1)
- {
- cout << "Enter two numbers: ";
- cin >> n1 >> n2;
-
- while(n1 != n2)
- {
- if(n1 > n2)
- n1 -= n2;
- else
- n2 -= n1;
- }
-
- cout << "HCF = " << n1;
- }
- else
- {
-
- cout << "Enter two numbers: ";
- cin >> n3 >> n4;
-
- // maximum value between n1 and n2 is stored in max
- max = (n1 > n2) ? n1 : n2;
-
- do
- {
- if (max % n1 == 0 && max % n2 == 0)
- {
- cout << "LCM = " << max;
- break;
- }
- else
- ++max;
- }while (true);
- }
- return 0;
-
-}
diff --git a/C++/GivenLengthAndSumofDigits.cpp b/C++/GivenLengthAndSumofDigits.cpp
deleted file mode 100644
index c6b28e815..000000000
--- a/C++/GivenLengthAndSumofDigits.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-#include
-#include
-using namespace std;
-
-int main() {
- int m, s, sum = 0;
- cin>>m>>s;
-
- int dig[m];
- fill_n(dig, m, 0);
-
- if(s == 0){
- if(m > 1){
- cout<<-1<<" "<<-1;
- }
- else{
- cout<<0<<" "<<0;
- }
- return 0;
- }
- else{
- if(m == 1){
- cout<<1<<" "<=0; --i){
- cout<
-using namespace std;
-
-int countCycles(int **edges,int c,int n)
-{
- int count=0;
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++)
- {
- if(edges[i][j]==1 && j!=i)
- {
-
-
- for(int k=1;k<=n;k++)
- {
- if(edges[j][k]==1 && (k!=j )&& (k!=i))
- {
- if(edges[k][i]==1 && k!=i && k!=j)
- count++;
- }
- }
- }
- }
- }
- return count/6;//because 3! ways of arranging same i,j,k.we are detecting one cycle 6 times.
-}
-int main()
-{
- int n,m;
- cin>>n>>m;
- int **edges=new int*[n];
- for(int i=1;i<=n;i++)
- {
- edges[i]=new int[n];
- for(int j=1;j<=n;j++)
- edges[i][j]=0;
- }
- int u[m],v[m];
- for(int i=0;i>u[i];
-
-
- }
-
- for(int i=0;i>v[i];
- for(int i=0;i
-using namespace std;
-int main()
-{
- int T;
- cin >> T;
- while (T--)
- {
- int num;
- cin >> num;
- char c;
- c = getchar();
- char a[num] = {};
- int j=0; //Length of HTHT
- for(int i=0;i
-using namespace std;
-int count = 0;
-
-void hanoi(int n, int source, int dest, int helper){
-
- if(n==0){
- return;
- }
- hanoi(n-1,source,helper,dest);
- cout<<"Move "<>n;
- hanoi(n,1,2,3);
- cout<
-#include
-#include
-#include
-
-#define size 10 //This is the size of heap created.Increase, if required
-int heapsize=0;
-using namespace std;
-
-void Max_heapify(int A[],int i)
-{
- int left=(2*i)+1,right=(2*i)+2,largest,temp;
-
- if(leftA[i])
- largest=left;
- else
- largest=i;
- if(rightA[largest])
- largest=right;
- if(largest!=i)
- {
- temp=A[i];
- A[i]=A[largest];
- A[largest]=temp;
- Max_heapify(A,largest);
- }
-}
-void Build_maxheap(int A[])
-{
- heapsize=size;
- int i=(size-2)/2;
- while(i>=0)
- {
- Max_heapify(A,i);
- i--;
- }
-}
-
-int heapmax(int A[])
-{
- return A[0];
-}
-int extractmax(int A[])
-{
- if(heapsize<=0)
- {
- printf("Heap Underflow\n");
- //return ;
- }
- else
- {
- int max=A[0];
- A[0]=A[heapsize-1];
- heapsize--;
- Max_heapify(A,0);
- return max;
- }
-}
-void heapinsert(int A[],int key)
-{
- int temp;
- heapsize++;
- int i=heapsize-1;
- A[i]=key;
- while(A[(i-1)/2]0)
- {
- temp=A[(i-1)/2];
- A[(i-1)/2]=A[i];
- A[i]=temp;
- i=(i-1)/2 ;
- }
-}
-void display(int A[])
-{
- if(heapsize==0)
- cout<<"Priority Queue Empty\n";
- else
- {
- cout<<"Priority Queue:\n";
- for(int i=0;i0;i--)
- {
- temp=A[0];
- A[0]=A[i];
- A[i]=temp;
- heapsize--;
- Max_heapify(A,0);
- }
- }
-}
-
-/*
-int main()
-{
- //Uncomment this main() & comment the later one to run the heapsort program.
-
- srand(time(NULL));
- int A[size];
- for(int i=0;i>ch;
-
- if(ch>3 || ch<=0)
- break;
-
- switch(ch)
- {
- case 1:
- cout<<"Enter the priority value of the element\n";
- cin>>x;
- heapinsert(Q,x);
- break;
- case 2:
- x=extractmax(Q);
- cout<<"Max Priority element="<