Skip to content

Commit f1dc219

Browse files
committed
Merge remote-tracking branch 'codeprob/master'
2 parents 7c3956b + b346fce commit f1dc219

File tree

6 files changed

+213
-8
lines changed

6 files changed

+213
-8
lines changed

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at larissalages7@gmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

classical_algorithms/python/Heap Sort.py renamed to classical_algorithms/python/heapsort.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,30 @@ def heapify(arr, n, i):
2323
def heapSort(arr):
2424
n = len(arr)
2525

26+
# empty list returns sorted empty list
27+
if n == 0:
28+
return []
29+
30+
# list of size one, returns same list
31+
if n == 1:
32+
return arr
33+
2634
# Build a maxheap.
2735
for i in range(n//2 - 1, -1, -1):
2836
heapify(arr, n, i)
2937

3038
# One by one extract elements
3139
for i in range(n-1, 0, -1):
3240
arr[i], arr[0] = arr[0], arr[i] # swap
33-
heapify(arr, i, 0)
34-
35-
print('Enter a list of numbers')
36-
arr = list(map(int,input().split()))
37-
heapSort(arr)
38-
print('After performing heap sort')
39-
for i in arr:
40-
print(i,end =' ')
41+
heapify(arr, i, 0)
42+
return arr
43+
44+
45+
# not execute the code when imported
46+
if __name__ == "__main__":
47+
print('Enter a list of numbers')
48+
arr = list(map(int,input().split()))
49+
heapSort(arr)
50+
print('After performing heap sort')
51+
for i in arr:
52+
print(i,end =' ')
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import unittest
2+
from classical_algorithms.python.heapsort import heapSort
3+
4+
class TestHeapSort(unittest.TestCase):
5+
def test_heap_sort(self):
6+
7+
print('None Input')
8+
self.assertRaises(TypeError, heapSort, None)
9+
10+
print('Empty Input')
11+
self.assertEqual(heapSort([]), [])
12+
13+
print('One Element')
14+
self.assertEqual(heapSort([13]), [13])
15+
16+
print('Multipe nElements')
17+
test_array = [-23,-1,0,1,10,-10,1000, 2]
18+
solution_array = [-23,-10,-1,0,1,2,10,1000]
19+
20+
self.assertEqual(heapSort(test_array), solution_array)
21+
22+
print('Successful test_heap_sort\n')
23+
24+
25+
if __name__=='__main__':
26+
unittest.main()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
using namespace std;
3+
int ternarySearch(int l, int r, int key, int ar[])
4+
5+
{
6+
while (r >= l) {
7+
8+
int mid1 = l + (r - l) / 3;
9+
int mid2 = r - (r - l) / 3;
10+
11+
if (ar[mid1] == key) {
12+
return mid1;
13+
}
14+
if (ar[mid2] == key) {
15+
return mid2;
16+
}
17+
18+
19+
if (key < ar[mid1]) {
20+
21+
// The key lies in between l and mid1
22+
r = mid1 - 1;
23+
}
24+
else if (key > ar[mid2]) {
25+
26+
// The key lies in between mid2 and r
27+
l = mid2 + 1;
28+
}
29+
else {
30+
31+
// The key lies in between mid1 and mid2
32+
l = mid1 + 1;
33+
r = mid2 - 1;
34+
}
35+
}
36+
return -1;
37+
}
38+
int main()
39+
{
40+
int len;
41+
cin>>len;
42+
int ar[len];
43+
for(int i=0;i<len;i++){
44+
cin>>ar[i];
45+
}
46+
int key;
47+
cin>>key;
48+
int l=0;
49+
int r=len-1;
50+
int p=0;
51+
p = ternarySearch(l, r, key, ar);
52+
53+
cout << "Index of "<<key<<" is " << p << endl;
54+
}
55+

leetcode/cpp/Stacks/20.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
bool checkingOpen(char ch) {
3+
return ch == '(' || ch == '[' || ch == '{';
4+
}
5+
char checkBracket(char ch){
6+
if(ch == ']') return '[';
7+
else if(ch == '}') return '{';
8+
else return '(';
9+
}
10+
public:
11+
bool isValid(string s) {
12+
stack <char> st;
13+
for(int i = 0 ; i < s.length() ; i++){
14+
if(checkingOpen(s[i])) st.push(s[i]);
15+
else{
16+
if(st.empty()) return false;
17+
if(checkBracket(s[i]) == st.top()) st.pop();
18+
else return false;
19+
}
20+
}
21+
if(st.empty()) return true;
22+
else return false;
23+
}
24+
};

pull_request_template.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### Your checklist for this pull request
2+
🚨Please review the [guidelines for contributing](https://github.com/larissalages/code_problems/blob/master/CONTRIBUTING.md) to this repository.
3+
4+
- [ ] Make sure your files are in the right folder!
5+
- [ ] Make sure you add the extension of the file (.cpp, .python, .java, etc).
6+
- [ ] If your code is a solution for a code problem, please tell which one.
7+
- [ ] Make sure your code is working, test for a lot of cases.
8+
9+
### Description
10+
Please describe your pull request.
11+
12+
:heart: Thank you!

0 commit comments

Comments
 (0)