Skip to content

Commit f1c02ae

Browse files
authored
𝐅𝐢𝐧𝐚𝐥 𝐏𝐫𝐨𝐣𝐞𝐜𝐭
1 parent cbb660e commit f1c02ae

Some content is hidden

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

53 files changed

+1493
-0
lines changed

OopsBasics

57.5 KB
Binary file not shown.

OopsBasics.cpp

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
class Car{
5+
6+
private:
7+
8+
string name;
9+
float price;
10+
int model;
11+
bool isAbs;
12+
13+
public:
14+
15+
/*
16+
Default Functions or Methods
17+
1.Constructor
18+
2.Destructor
19+
3.Copy Constructor
20+
4.Copy Assignment Operator
21+
22+
*/
23+
24+
25+
// Constructor
26+
27+
// Default Constructor
28+
Car(){
29+
cout<<"Constructer Called!!"<<endl;
30+
}
31+
32+
// Parametarised Constructor
33+
Car(string n,float p,int m){
34+
price=p;
35+
model=m;
36+
name=n;
37+
isAbs=false;
38+
cout<<"Parametarised Constructor Called!!!!"<<endl;
39+
}
40+
41+
Car(float p,int m,string n){
42+
price=p;
43+
model=m;
44+
name=n;
45+
isAbs=true;
46+
cout<<"Second Parametarised Constructor Called"<<endl;
47+
}
48+
49+
// Setter
50+
void make_car(string n,float p,int m,bool ibs){
51+
name=n;
52+
53+
if(p<0){
54+
price=20000;
55+
}
56+
model=m;
57+
isAbs=ibs;
58+
}
59+
60+
// Getter
61+
void showCar(){
62+
cout<<"Name : "<<name<<endl;
63+
cout<<"Price : "<<price<<endl;
64+
cout<<"Model : "<<model<<endl;
65+
isAbs==true?cout<<"ABS"<<endl:cout<<"Non-ABS"<<endl;
66+
67+
}
68+
69+
void updatePrice(int p){
70+
71+
price=p;
72+
73+
return;
74+
}
75+
76+
// Copy Constructor
77+
78+
Car(Car &X){
79+
name=X.name;
80+
price=X.price;
81+
model=X.model;
82+
isAbs=X.isAbs;
83+
84+
cout<<"Copy Constructor Called"<<endl;
85+
}
86+
87+
88+
// Destructor
89+
~Car(){
90+
cout<<"Destructor is Called!!!!"<<endl;
91+
}
92+
93+
94+
// Friend Function in C++
95+
friend int getPrice(Car X);
96+
97+
};
98+
99+
int getPrice(Car X){
100+
101+
102+
return X.price;
103+
}
104+
105+
106+
107+
void fun(){
108+
109+
Car X("Range Rover",40000000,2020);
110+
X.showCar();
111+
X.updatePrice(200);
112+
X.showCar();
113+
114+
115+
}
116+
117+
int main(){
118+
119+
120+
// Car A,B;
121+
// A.make_car("Audi",202.2020,1999,false);
122+
// A.showCar();
123+
124+
// B.make_car("Scorpio",-100,2050,true);
125+
// B.showCar();
126+
127+
// Car D("Maruti",10000,2030);
128+
// D.showCar();
129+
130+
// Car E(100.5,2015,"BMW");
131+
// E.showCar();
132+
133+
// fun();
134+
135+
// Car Y("Audi",100,2014);
136+
137+
Car *ptr=new Car("Bulero",500,2050);
138+
139+
ptr->showCar();
140+
141+
delete ptr;
142+
// Y.showCar();
143+
144+
// Car Z(Y);
145+
// Z.updatePrice(3000);
146+
// Z.showCar();
147+
148+
149+
// int price=getPrice(Z);
150+
// cout<<"Price of Z Car is : "<<price<<endl;
151+
152+
153+
154+
return 0;
155+
}

SelectionSort

55.2 KB
Binary file not shown.

Test

49.9 KB
Binary file not shown.

Trie

104 KB
Binary file not shown.

Trie.cpp

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#include<iostream>
2+
#include<unordered_map>
3+
#include<cstring>
4+
using namespace std;
5+
6+
7+
class node{
8+
public:
9+
10+
bool isTerminal;
11+
char ch;
12+
unordered_map<char,node*>mp;
13+
14+
node(char data){
15+
ch=data;
16+
isTerminal=false;
17+
}
18+
};
19+
20+
class Trie{
21+
22+
node*root;
23+
24+
public:
25+
26+
Trie(){
27+
root=new node('\0');
28+
}
29+
30+
void AddWord(string word){
31+
32+
node*temp=root;
33+
34+
for(int i=0;i<word.size();i++){
35+
char ch=word[i];
36+
if(temp->mp.count(ch)==0){
37+
node*n=new node(ch);
38+
temp->mp[ch]=n;
39+
temp=n;
40+
}else{
41+
temp=temp->mp[ch];
42+
}
43+
44+
}
45+
temp->isTerminal=true;
46+
}
47+
48+
bool searchWord(string word){
49+
50+
node*temp=root;
51+
52+
for(int i=0;i<word.size();i++){
53+
char ch=word[i];
54+
55+
if(temp->mp.count(ch)==0){
56+
return false;
57+
}else{
58+
temp=temp->mp[ch];
59+
}
60+
}
61+
return temp->isTerminal;
62+
}
63+
64+
void solve(char ch,node*temp,vector<char>p){
65+
66+
if(temp->isTerminal==true and mp.count(temp->char)==0){
67+
return;
68+
}
69+
70+
for(auto x:temp->mp[ch]){
71+
72+
}
73+
74+
75+
76+
}
77+
78+
void print(string word){
79+
node*temp=root;
80+
vector<char>p;
81+
82+
for(int i=0;i<word.size();i++){
83+
char ch=word[i];
84+
if(temp->mp.count(ch)==0){
85+
return;
86+
}else{
87+
temp=temp->mp[ch];
88+
p.push_back(ch);
89+
solve(char ch,temp,p);
90+
}
91+
}
92+
93+
}
94+
95+
96+
97+
};
98+
99+
100+
int main(){
101+
102+
103+
Trie T;
104+
105+
T.AddWord("bat");
106+
T.AddWord("batman");
107+
T.AddWord("aabbc");
108+
T.AddWord("abc");
109+
110+
if(T.searchWord("batman")){
111+
cout<<"Present"<<endl;
112+
}else{
113+
cout<<"Not Present"<<endl;
114+
}
115+
116+
117+
return 0;
118+
}

maximumAreaIsland

50.3 KB
Binary file not shown.

maximumAreaIsland.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int solve(int a[][50],int i,int j,int r,int c){
5+
6+
if(i<0||j<0||i>=r||j>=c||a[i][j]!=1){
7+
return 0;
8+
}
9+
10+
a[i][j]=2;
11+
12+
int q1=solve(a,i-1,j,r,c);
13+
int q2=solve(a,i+1,j,r,c);
14+
int q3=solve(a,i,j-1,r,c);
15+
int q4=solve(a,i,j+1,r,c);
16+
17+
return 1+q1+q2+q3+q4;
18+
}
19+
20+
int main(){
21+
22+
int n,m;
23+
cin>>n>>m;
24+
25+
int a[50][50];
26+
27+
for(int i=0;i<n;i++){
28+
for(int j=0;j<m;j++){
29+
cin>>a[i][j];
30+
}
31+
}
32+
33+
int maxArea=INT_MIN;
34+
35+
for(int i=0;i<n;i++){
36+
for(int j=0;j<m;j++){
37+
if(a[i][j]==1){
38+
int area=solve(a,i,j,n,m);
39+
maxArea=max(area,maxArea);
40+
}
41+
}
42+
}
43+
44+
cout<<maxArea<<endl;
45+
46+
return 0;
47+
}

mergeIntervals

57 KB
Binary file not shown.

mergeIntervals.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
bool compare(vector<int>a,vector<int>b){
3+
4+
return a[0]<b[0];
5+
}
6+
7+
class Solution {
8+
public:
9+
vector<vector<int>> merge(vector<vector<int>>& intervals) {
10+
11+
sort(intervals.begin(),intervals.end());
12+
int n=intervals.size();
13+
14+
vector<vector<int>>ans;
15+
16+
vector<int>curr=intervals[0];
17+
int s=intervals[0][0];
18+
int e=intervals[0][1];
19+
20+
21+
for(int i=1;i<n;i++){
22+
23+
if(e>=intervals[i][0]){
24+
s=min(intervals[i][0],s);
25+
e=max(intervals[i][1],e);
26+
}
27+
else{
28+
ans.push_back({s,e});
29+
s=intervals[i][0];
30+
e=intervals[i][1];
31+
32+
}
33+
}
34+
35+
ans.push_back({s,e});
36+
37+
38+
39+
return ans;
40+
}
41+
};

mergeKsortedArray

67.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)