Skip to content

Commit 75489a8

Browse files
Merge pull request #26 from Vanshi2504ka/main
Added SpotifyClone static template
2 parents 537c562 + 03199e3 commit 75489a8

203 files changed

Lines changed: 69449 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BinarySearch.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class BinarySearch
2+
{
3+
int binarySearch(int arr[], int l, int r, int x)
4+
{
5+
if (r >= l) {
6+
int mid = l + (r - l) / 2;
7+
if (arr[mid] == x)
8+
return mid;
9+
if (arr[mid] > x)
10+
return binarySearch(arr, l, mid - 1, x);
11+
return binarySearch(arr, mid + 1, r, x);
12+
}
13+
return -1;
14+
}
15+
public static void main(String args[])
16+
{
17+
BinarySearch ob = new BinarySearch();
18+
int arr[] = { 2, 3, 4, 10, 40 };
19+
int n = arr.length;
20+
int x = 10;
21+
int result = ob.binarySearch(arr, 0, n - 1, x);
22+
if (result == -1)
23+
System.out.println("Element not present");
24+
else
25+
System.out.println("Element found at index "
26+
+ result);
27+
}
28+
}

DSA/1TraversalINCLL.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
struct Node
5+
{
6+
int data;
7+
Node *next;
8+
Node(int y)
9+
{
10+
data = y;
11+
next = NULL;
12+
}
13+
};
14+
15+
void print(Node *head)
16+
{
17+
if(head == NULL){
18+
return;
19+
}
20+
Node *value = head;
21+
do{
22+
cout<<value->data<<" ";
23+
value = value->next;
24+
}
25+
while(value != head);
26+
27+
}
28+
int main()
29+
{
30+
Node *head = new Node(10);
31+
head->next = new Node(11);
32+
head->next->next = new Node(12);
33+
head->next->next->next = new Node(13);
34+
head->next->next->next->next = head;
35+
print(head);
36+
return 0;
37+
}

DSA/2InsertATBeginCLL.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Time Complexity = O👎
2+
3+
4+
#include<bits/stdc++.h>
5+
using namespace std;
6+
struct Node
7+
{
8+
int data;
9+
Node *next;
10+
Node(int d){
11+
data = d;
12+
next = NULL;
13+
}
14+
};
15+
16+
void print(Node *head)
17+
{
18+
if(head == NULL){
19+
return;
20+
}
21+
Node *value = head;
22+
do{
23+
cout<<value->data<<" ";
24+
value = value->next;
25+
}
26+
while(value != head);
27+
28+
}
29+
30+
Node *InsertBegin(Node *head, int data)
31+
{
32+
Node *temp = new Node(data);
33+
if(head == NULL){
34+
temp->next = temp;
35+
return temp;
36+
}
37+
else{
38+
temp->next = head->next;
39+
head->next = temp;
40+
int t = head->data;
41+
head->data = temp->data;
42+
temp->data = t;
43+
return head;
44+
}
45+
}
46+
47+
48+
int main()
49+
{
50+
Node *head = new Node(10);
51+
head->next = new Node(11);
52+
head->next->next = new Node(12);
53+
head->next->next->next = new Node(13);
54+
head->next->next->next->next = head;
55+
print(head);
56+
cout<<endl;
57+
head = InsertBegin(head, 9);
58+
print(head);
59+
60+
61+
return 0;
62+
}

DSA/3InsertAtEndCLL.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Time Complexity = O(n)
2+
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
6+
struct Node
7+
{
8+
int data;
9+
Node *next;
10+
Node(int y){
11+
data = y;
12+
next=NULL;
13+
}
14+
};
15+
void print(Node *head)
16+
{
17+
if(head == NULL){
18+
return;
19+
}
20+
Node *value = head;
21+
do{
22+
cout<<value->data<<" ";
23+
value = value->next;
24+
}
25+
while(value != head);
26+
27+
}
28+
29+
Node *InsertEnd(Node *head, int data)
30+
{
31+
Node *temp = new Node(data);
32+
if(head == NULL){
33+
temp->next = temp;
34+
return temp;
35+
}
36+
else{
37+
temp ->next = head->next;
38+
head->next = temp;
39+
int t = temp->data;
40+
temp->data = head->data;
41+
head->data = t;
42+
return temp;
43+
}
44+
}
45+
int main()
46+
{
47+
Node *head = new Node(10);
48+
head->next = new Node(11);
49+
head->next->next = new Node(12);
50+
head->next->next->next = new Node(13);
51+
head->next->next->next->next = head;
52+
print(head);
53+
cout<<endl;
54+
int data;
55+
cin>>data;
56+
head = InsertEnd(head, data);
57+
print(head);
58+
59+
return 0;
60+
}

DSA/4DeleteHeadCLL.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
struct Node
5+
{
6+
int data;
7+
Node *next;
8+
Node(int y){
9+
data = y;
10+
next= NULL;
11+
}
12+
};
13+
14+
void print(Node *head)
15+
{
16+
if(head == NULL){
17+
return ;
18+
}
19+
Node *curr = head;
20+
do{
21+
cout<<curr->data<<" ";
22+
curr = curr->next;
23+
}
24+
while(curr!=head);
25+
}
26+
27+
Node *deleteHead(Node *head)
28+
{
29+
if(head == NULL){
30+
return NULL;
31+
}
32+
if(head->next == head){
33+
delete head;
34+
return NULL;
35+
}
36+
head->data = head->next->data;
37+
Node * temp = head->next;
38+
head->next = head->next->next;
39+
delete temp;
40+
return head;
41+
42+
}
43+
int main()
44+
{
45+
Node *head = new Node(10);
46+
head->next = new Node(11);
47+
head->next->next = new Node(12);
48+
head->next->next->next = new Node(13);
49+
head->next->next->next->next = head;
50+
print(head);
51+
cout<<endl;
52+
head = deleteHead(head);
53+
print(head);
54+
55+
return 0;
56+
}

DSA/5DeleteKthNodeCLL.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
struct Node
5+
{
6+
int data;
7+
Node *next;
8+
Node(int d){
9+
data = d;
10+
next = NULL;
11+
}
12+
};
13+
14+
void print(Node *head)
15+
{
16+
if(head == NULL){
17+
return;
18+
}
19+
Node *value = head;
20+
do{
21+
cout<<value->data<<" ";
22+
value = value->next;
23+
}
24+
while(value != head);
25+
}
26+
27+
Node *deleteHead(Node *head)
28+
{
29+
if(head == NULL){
30+
return NULL;
31+
}
32+
if(head->next == head){
33+
delete head;
34+
return NULL;
35+
}
36+
head->data = head->next->data;
37+
Node * temp = head->next;
38+
head->next = head->next->next;
39+
delete temp;
40+
return head;
41+
42+
}
43+
44+
Node *DeleteKth(Node *head, int k)
45+
{
46+
if(head == NULL){
47+
return head;
48+
}
49+
if(k==1){
50+
return deleteHead(head);
51+
}
52+
Node *curr = head;
53+
for (int i = 0; i < k-2; ++i)
54+
{
55+
curr = curr->next;
56+
}
57+
Node *temp = curr->next;
58+
curr->next = curr->next->next;
59+
delete temp;
60+
return head;
61+
}
62+
63+
64+
int main()
65+
{
66+
Node *head = new Node(10);
67+
head->next = new Node(11);
68+
head->next->next = new Node(12);
69+
head->next->next->next = new Node(13);
70+
head->next->next->next->next = head;
71+
print(head);
72+
cout<<endl;
73+
int k;
74+
cin>>k;
75+
head = DeleteKth(head, k);
76+
print(head);
77+
78+
return 0;
79+
}

DSA/ATM_CARD_VALIDATOR.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//Program to validate any ATM card.
2+
import java.util.Scanner;
3+
4+
class ATM_CARD_VALIDATOR{
5+
public static boolean TwoDigit(int n) {
6+
int i=0;
7+
i+=n/10;
8+
if(i>=1)
9+
return true;
10+
else
11+
return false;
12+
}
13+
public static void main(String args[]){
14+
int[] cnum = new int[16];
15+
int x=0,y=0;
16+
try (Scanner scn = new Scanner(System.in)) {
17+
for(int i=0;i<16;i++)
18+
{
19+
if(i+1==1){
20+
System.out.println("Enter the " + (i+1) +"st digit of the card:");
21+
cnum[i] = scn.nextInt();
22+
}
23+
else if(i+1==2) {
24+
System.out.println("Enter the " + (i+1) +"nd digit of the card:");
25+
cnum[i] = scn.nextInt();
26+
}
27+
else if(i+1==3) {
28+
System.out.println("Enter the " + (i+1) +"3rd digit of the card:");
29+
cnum[i] = scn.nextInt();
30+
}
31+
else{
32+
System.out.println("Enter the " + (i+1) +"th digit of the card:");
33+
cnum[i] = scn.nextInt();
34+
}
35+
36+
}
37+
}
38+
for(int i=cnum.length-2;i>=1;i=i-2)
39+
{
40+
cnum[i+1]+=cnum[i-1]*2;
41+
if(TwoDigit(cnum[i+1])){
42+
cnum[i+1]=cnum[i+1]-9;
43+
}
44+
}
45+
for(int i=0;i<16;i=i+2)
46+
{
47+
y+=cnum[i];
48+
}
49+
if((x+y)%2==0){
50+
System.out.println("The CARD is Valid");
51+
}
52+
else{
53+
System.out.println("The CARD is Not Valid");
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)