Skip to content

Commit 96ea01f

Browse files
committed
add new codes
1 parent 864e666 commit 96ea01f

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

a.out

88 Bytes
Binary file not shown.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
int check(string inp){
6+
stack<char> st;
7+
for(int i=0;i<inp.length();i++){
8+
if(inp[i] == '(' || inp[i] == '[' || inp[i] == '{'){
9+
st.push(inp[i]);
10+
}else{
11+
if(inp[i] == ')' && st.top() == '('){
12+
st.pop();
13+
}else if(inp[i] == ']' && st.top() == '['){
14+
st.pop();
15+
}else if(inp[i] == '}' && st.top() == '{'){
16+
st.pop();
17+
}else{
18+
return 0;
19+
}
20+
}
21+
}
22+
if(st.empty()){
23+
return 1;
24+
}
25+
return 0;
26+
}
27+
28+
int main(){
29+
string s;
30+
cin>>s;
31+
if(check(s))
32+
cout << "balanced\n";
33+
else
34+
cout << "not balanced\n";
35+
return 0;
36+
}

find-sub-array-sum-closest-0.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://www.geeksforgeeks.org/find-sub-array-sum-closest-0/
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
pair<int, int> sumClosest(int arr[], int n){
6+
vector<pair<int, int> > v;
7+
v.push_back(make_pair(0,-1));
8+
for(int i=1;i<=n;i++){
9+
v.push_back(make_pair((v[i-1].first+arr[i-1]), i-1));
10+
}
11+
12+
}
13+
14+
int main(){
15+
int arr[] = {-1,3,2,-5,4};
16+
int n = sizeof(arr)/sizeof(arr[0]);
17+
pair<int , int> p = sumClosest(arr,n);
18+
cout << p.first << " " << p.second << endl;
19+
return 0;
20+
}

insertion-sort.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// insertion sort
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
void insertionSort(int arr[], int n){
6+
int i, j,current;
7+
for(i=1;i<n;i++){
8+
current = arr[i];
9+
for(j=i-1;j>=0;j--){
10+
if(arr[j]>current){
11+
arr[j+1] = arr[j];
12+
}else
13+
break;
14+
}
15+
arr[j+1] = current;
16+
}
17+
}
18+
19+
int main(){
20+
int arr[] = {5,1,3,7,10,9};
21+
int n = sizeof(arr)/sizeof(arr[0]);
22+
insertionSort(arr,n);
23+
for(int i=0;i<n;i++)
24+
cout << arr[i] << " ";
25+
cout << endl;
26+
return 0;
27+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy