Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit 7494845

Browse files
Merge branch 'master' into my-branch
2 parents b5b2745 + 6f967b6 commit 7494845

13 files changed

+495
-2
lines changed

.github/workflows/greet-contributors.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ jobs:
77
GreetCommitter:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: "Greet contributor"
10+
- name: "Contributors!!!"
1111
uses: ibakshay/greet-contributors-action@v3
1212
env:
1313
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1414
with:
15-
content: "Thank you for taking your time and effort for your contribution..."
15+
content: "Thank you for taking your time and effort for your contribution. If you are a new contributor to this repo, kindly add your username in [CONTRIBUTORS.md](https://github.com/SanjayDevTech/Code-with-love/blob/master/CONTRIBUTORS.md)"

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ If you have contributed to this repository, kindly add your username here
1313
- [afaditya](https://github.com/afaditya)
1414
- [aaishikasb](https://github.com/aaishikasb)
1515
- [sam0hack](https://github.com/sam0hack)
16+
- [shivajipotnuru](https://github.com/shivajipotnuru)
1617
- [albysabu9](https://github.com/albysabu9)
1718
- [Jayant-saksham](https://github.com/Jayant-saksham)
1819
- [Harshit564](https://github.com/Harshit564)

cpp/Unique_Number_III.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*Unique_Number_III
2+
Given an array that contains all elements occurring 3 times, but one occurs only once. Find that unique element.*/
3+
#include <iostream>
4+
using namespace std;
5+
int main()
6+
{
7+
int cnt[64] = {0};
8+
int n, no;
9+
cin >> n;
10+
for (int i = 0; i < n; i++)
11+
{
12+
cin >> no;
13+
14+
int j = 0;
15+
while (no > 0)
16+
{
17+
int last_bit = (no & 1);
18+
cnt[j] += last_bit;
19+
j++;
20+
no = no >> 1;
21+
}
22+
}
23+
int p = 1;
24+
int ans = 0;
25+
for (int i = 0; i < 64; i++)
26+
{
27+
cnt[i] %= 3;
28+
ans += (cnt[i] * p);
29+
p = p << 1;
30+
}
31+
cout << ans << endl;
32+
return 0;
33+
}
34+
/*
35+
Input : arr[] = {6, 2, 5, 2, 2, 6, 6}
36+
Output : 5
37+
Time Complexity:O(n)
38+
*/

cpp/russian_peasant.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*Russian Reasant Algorithm
2+
In this algorithm, two numbers are multiplied without using multiplication operator.
3+
We double the first number and halve the second number repeatedly till the second number doesn’t become 1.
4+
In the process, whenever the second number becomes odd, we add the first number to result.
5+
In the 1800s, Peasants in a remote area of Russia were discovered multiplying numbers using this remarkably unusual process.
6+
*/
7+
8+
#include <iostream>
9+
using namespace std;
10+
int main()
11+
{
12+
int a, b, result = 0;
13+
14+
cout << "Enter two numbers to multiply: \n";
15+
cin >> a >> b;
16+
while (b > 0)
17+
{
18+
if (b % 2 != 0)
19+
{
20+
result += a;
21+
}
22+
a = a << 1;
23+
b = b >> 1;
24+
}
25+
cout << "Product: " << result;
26+
return 0;
27+
}
28+
29+
/*Input:
30+
Enter two numbers to multiply:
31+
4 20
32+
Output:
33+
Product: 80
34+
Time complexity: O(1)
35+
*/

cpp/siddhantmittal02_MergeSort.cpp

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//ALGO FOR MERGE SORT
2+
/*
3+
Declare an array Arr of length N
4+
If N=1, Arr is already sorted
5+
If N>1,
6+
Left = 0, right = N-1
7+
Find middle = (left + right)/2
8+
Call merge_sort(Arr,left,middle) =>sort first half recursively
9+
Call merge_sort(Arr,middle+1,right) => sort second half recursively
10+
Call merge(Arr, left, middle, right) to merge sorted arrays in above steps.
11+
Exit
12+
*/
13+
14+
//CODE
15+
#include <iostream>
16+
using namespace std;
17+
void merge(int *, int, int, int);
18+
void merge_sort(int *arr, int low, int high)
19+
{
20+
int mid;
21+
if (low < high)
22+
{
23+
//divide the array at mid and sort independently using merge sort
24+
mid = (low + high) / 2;
25+
merge_sort(arr, low, mid);
26+
merge_sort(arr, mid + 1, high);
27+
//merge or conquer sorted arrays
28+
merge(arr, low, high, mid);
29+
}
30+
}
31+
// Merge sort
32+
void merge(int *arr, int low, int high, int mid)
33+
{
34+
int i, j, k, c[50];
35+
i = low;
36+
k = low;
37+
j = mid + 1;
38+
while (i <= mid && j <= high)
39+
{
40+
if (arr[i] < arr[j])
41+
{
42+
c[k] = arr[i];
43+
k++;
44+
i++;
45+
}
46+
else
47+
{
48+
c[k] = arr[j];
49+
k++;
50+
j++;
51+
}
52+
}
53+
while (i <= mid)
54+
{
55+
c[k] = arr[i];
56+
k++;
57+
i++;
58+
}
59+
while (j <= high)
60+
{
61+
c[k] = arr[j];
62+
k++;
63+
j++;
64+
}
65+
for (i = low; i < k; i++)
66+
{
67+
arr[i] = c[i];
68+
}
69+
}
70+
// read input array and call mergesort
71+
int main()
72+
{
73+
int myarray[30], num;
74+
cout << "Enter number of elements to be sorted:";
75+
cin >> num;
76+
cout << "Enter " << num << " elements to be sorted:";
77+
for (int i = 0; i < num; i++)
78+
{
79+
cin >> myarray[i];
80+
}
81+
merge_sort(myarray, 0, num - 1);
82+
cout << "Sorted array\n";
83+
for (int i = 0; i < num; i++)
84+
{
85+
cout << myarray[i] << "\t";
86+
}
87+
}

html/Kshitij9896_HelloWorld.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Hello World</title>
5+
</head>
6+
<body>
7+
<h1>Simple HTML Program</h1>
8+
<h1>Hello World</h1>
9+
10+
</body>
11+
</html>
+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import java.io.*;
2+
/***************
3+
public static void main(String[] args) {
4+
Scanner s = new Scanner(System.in);
5+
6+
Queue<Integer> st = new Queue<Integer>();
7+
8+
int choice = s.nextInt();
9+
int input;
10+
11+
while (choice !=-1) {
12+
if(choice == 1) {
13+
input = s.nextInt();
14+
st.enqueue(input);
15+
}
16+
else if(choice == 2) {
17+
try {
18+
System.out.println(st.dequeue());
19+
} catch (QueueEmptyException e) {
20+
System.out.println(-1);
21+
}
22+
}
23+
else if(choice == 3) {
24+
try {
25+
System.out.println(st.front());
26+
} catch (QueueEmptyException e) {
27+
System.out.println(-1);
28+
}
29+
}
30+
else if(choice == 4) {
31+
System.out.println(st.size());
32+
}
33+
else if(choice == 5) {
34+
System.out.println(st.isEmpty());
35+
}
36+
choice = s.nextInt();
37+
}
38+
}
39+
}
40+
41+
class Node<T> {
42+
T data;
43+
Node<T> next;
44+
45+
public Node(T data) {
46+
this.data = data;
47+
48+
}
49+
}
50+
51+
52+
***********/
53+
54+
55+
56+
class QueueEmptyException extends Exception {
57+
58+
/**
59+
*
60+
*/
61+
private static final long serialVersionUID = 1L;
62+
63+
64+
}
65+
66+
67+
68+
public class Queue<T> {
69+
private Node<T> rear;
70+
private Node <T> front;
71+
int size;
72+
73+
public Queue() {
74+
rear=null;
75+
front =null;
76+
size=0;
77+
78+
}
79+
80+
public void enqueue(T data) {
81+
82+
Node<T> curr = new Node<> (data);
83+
size++;
84+
if(rear==null){
85+
front=curr;
86+
rear=curr;
87+
88+
}
89+
90+
else{
91+
rear.next=curr;
92+
rear=curr;
93+
}
94+
// size++;
95+
96+
}
97+
98+
public int size() {
99+
return size;
100+
101+
}
102+
103+
public boolean isEmpty() {
104+
return size==0;
105+
}
106+
107+
public T dequeue() throws QueueEmptyException {
108+
if(front==null){
109+
throw new QueueEmptyException();
110+
}
111+
T temp= front.data;
112+
front=front.next;
113+
if(front ==null){
114+
rear=null;
115+
}
116+
size--;
117+
return temp;
118+
119+
120+
}
121+
122+
public T front() throws QueueEmptyException {
123+
if(front==null){
124+
throw new QueueEmptyException();
125+
}
126+
return front.data;
127+
128+
}
129+
130+
}

0 commit comments

Comments
 (0)