Skip to content

Commit 382c069

Browse files
committed
Merge branch 'master' of github.com:CodeToExpress/dailycodebase
2 parents b1a0cef + 954fb3f commit 382c069

File tree

4 files changed

+323
-0
lines changed

4 files changed

+323
-0
lines changed

day25/C++/rotateTile.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @author : Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com>
3+
* @handle : razdeep
4+
* @date : Feb 17, 2019
5+
*/
6+
#include <bits/stdc++.h>
7+
std::vector<std::vector<int>> rotate(std::vector<std::vector<int>> &two_D_array)
8+
{
9+
std::vector<std::vector<int>> result(two_D_array.size());
10+
for(int i=0; i<two_D_array.size();i++)
11+
{
12+
std::vector<int> this_array(two_D_array.size(), 0);
13+
result[i] = this_array;
14+
}
15+
int rj = two_D_array.size() - 1, ri = 0;
16+
for (int i = 0; i < two_D_array.size(); i++)
17+
{
18+
for (int j = 0; j < two_D_array[i].size(); j++)
19+
{
20+
result[ri++][rj] = two_D_array[i][j];
21+
}
22+
rj--;
23+
ri = 0;
24+
}
25+
return result;
26+
}
27+
int main(int argc, char **argv)
28+
{
29+
int n;
30+
std::cout << "Enter the value of n ";
31+
std::cin >> n;
32+
std::vector<std::vector<int>> two_D_array(n);
33+
for (int i = 0; i < n; i++)
34+
{
35+
std::vector<int> this_array(n, 0);
36+
// std::vector<int> this_array = new std::vector<int>(n);
37+
for (int j = 0; j < n; j++)
38+
{
39+
std::cin >> this_array[j];
40+
}
41+
two_D_array[i] = this_array;
42+
}
43+
std::cout << "Original Matrix is..." << std::endl;
44+
for (int i = 0; i < two_D_array.size(); i++)
45+
{
46+
for (int j = 0; j < two_D_array[i].size(); j++)
47+
{
48+
std::cout << two_D_array[i][j] << " ";
49+
}
50+
std::cout << std::endl;
51+
}
52+
std::vector<std::vector<int>> rotated_2d_array = rotate(two_D_array);
53+
std::cout << "Rotated matrix is" << std::endl;
54+
for (int i = 0; i < two_D_array.size(); i++)
55+
{
56+
for (int j = 0; j < two_D_array[i].size(); j++)
57+
{
58+
std::cout << rotated_2d_array[i][j] << " ";
59+
}
60+
std::cout << std::endl;
61+
}
62+
return 0;
63+
}

day25/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,72 @@ public class rotateTile {
158158
}
159159
}
160160
}
161+
```
162+
## C++ Implementation
163+
164+
### [Solution](./C++/rotateTile.cpp)
165+
```cpp
166+
/**
167+
* @author : Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com>
168+
* @handle : razdeep
169+
* @date : Feb 17, 2019
170+
*/
171+
#include <bits/stdc++.h>
172+
std::vector<std::vector<int>> rotate(std::vector<std::vector<int>> &two_D_array)
173+
{
174+
std::vector<std::vector<int>> result(two_D_array.size());
175+
for(int i=0; i<two_D_array.size();i++)
176+
{
177+
std::vector<int> this_array(two_D_array.size(), 0);
178+
result[i] = this_array;
179+
}
180+
int rj = two_D_array.size() - 1, ri = 0;
181+
for (int i = 0; i < two_D_array.size(); i++)
182+
{
183+
for (int j = 0; j < two_D_array[i].size(); j++)
184+
{
185+
result[ri++][rj] = two_D_array[i][j];
186+
}
187+
rj--;
188+
ri = 0;
189+
}
190+
return result;
191+
}
192+
int main(int argc, char **argv)
193+
{
194+
int n;
195+
std::cout << "Enter the value of n ";
196+
std::cin >> n;
197+
std::vector<std::vector<int>> two_D_array(n);
198+
for (int i = 0; i < n; i++)
199+
{
200+
std::vector<int> this_array(n, 0);
201+
// std::vector<int> this_array = new std::vector<int>(n);
202+
for (int j = 0; j < n; j++)
203+
{
204+
std::cin >> this_array[j];
205+
}
206+
two_D_array[i] = this_array;
207+
}
208+
std::cout << "Original Matrix is..." << std::endl;
209+
for (int i = 0; i < two_D_array.size(); i++)
210+
{
211+
for (int j = 0; j < two_D_array[i].size(); j++)
212+
{
213+
std::cout << two_D_array[i][j] << " ";
214+
}
215+
std::cout << std::endl;
216+
}
217+
std::vector<std::vector<int>> rotated_2d_array = rotate(two_D_array);
218+
std::cout << "Rotated matrix is" << std::endl;
219+
for (int i = 0; i < two_D_array.size(); i++)
220+
{
221+
for (int j = 0; j < two_D_array[i].size(); j++)
222+
{
223+
std::cout << rotated_2d_array[i][j] << " ";
224+
}
225+
std::cout << std::endl;
226+
}
227+
return 0;
228+
}
161229
```

day38/Java/Stack.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package javaapplication3;
7+
8+
/**
9+
* @date 11/02/19
10+
* @author SPREEHA DUTTA
11+
*/
12+
import java.util.*;
13+
public class Stack {
14+
static int st[]=new int[5];
15+
static int top=0;
16+
public static void push(int n)
17+
{
18+
if(top<5)
19+
{
20+
st[top]=n;
21+
top++;
22+
}
23+
else
24+
isFull();
25+
}
26+
public static void pop()
27+
{
28+
if(top<=5 && top>0)
29+
{
30+
top--;
31+
System.out.println("Popped element is "+st[top]);
32+
}
33+
else
34+
isEmpty();
35+
}
36+
public static void isEmpty()
37+
{
38+
if(top<=0)
39+
System.out.println("Stack is empty");
40+
}
41+
public static void isFull()
42+
{
43+
if(top>=5)
44+
System.out.println("Stack is full");
45+
}
46+
public static void peek()
47+
{
48+
if(top-1>=0 && top-1<5)
49+
System.out.println("The topmost element of the stack is "+st[top-1]);
50+
else
51+
System.out.println("Stack is empty");
52+
}
53+
public static void display()
54+
{
55+
System.out.println("All the elements present in the stack are:");
56+
for(int i=0;i<top;i++)
57+
System.out.print(st[i]+" ");
58+
System.out.println();
59+
}
60+
public static void main(String []args)
61+
{
62+
Scanner sc=new Scanner(System.in);
63+
int ch;int c=0;
64+
do
65+
{
66+
c=0;
67+
System.out.println("Enter choice ");
68+
System.out.println("1. Add new element"
69+
+ "\n"+"2. Remove topmost eleemnt"
70+
+"\n3. To view the topmost element"+"\n4. To view all the elements");
71+
ch=sc.nextInt();
72+
switch(ch)
73+
{
74+
case 1:
75+
System.out.println("Enter element to be added to stack ");
76+
int n=sc.nextInt();
77+
push(n);
78+
break;
79+
case 2:
80+
pop();
81+
break;
82+
case 3:
83+
peek();
84+
break;
85+
case 4:
86+
display();
87+
break;
88+
default:
89+
System.out.println("Invalid choice :");
90+
}
91+
System.out.println("Enter 1 if you wish to continue");
92+
c=sc.nextInt();
93+
}
94+
while(c==1);
95+
}
96+
}

day38/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,100 @@ stk.push (1);
182182
stk.push (2);
183183
stk.pop ();
184184
stk.peek ();
185+
```
186+
187+
## Java Implementation
188+
189+
### [Solution](./Java/Stack.java)
190+
191+
```java
192+
/**
193+
* @date 11/02/19
194+
* @author SPREEHA DUTTA
195+
*/
196+
import java.util.*;
197+
public class Stack {
198+
static int st[]=new int[5];
199+
static int top=0;
200+
public static void push(int n)
201+
{
202+
if(top<5)
203+
{
204+
st[top]=n;
205+
top++;
206+
}
207+
else
208+
isFull();
209+
}
210+
public static void pop()
211+
{
212+
if(top<=5 && top>0)
213+
{
214+
top--;
215+
System.out.println("Popped element is "+st[top]);
216+
}
217+
else
218+
isEmpty();
219+
}
220+
public static void isEmpty()
221+
{
222+
if(top<=0)
223+
System.out.println("Stack is empty");
224+
}
225+
public static void isFull()
226+
{
227+
if(top>=5)
228+
System.out.println("Stack is full");
229+
}
230+
public static void peek()
231+
{
232+
if(top-1>=0 && top-1<5)
233+
System.out.println("The topmost element of the stack is "+st[top-1]);
234+
else
235+
System.out.println("Stack is empty");
236+
}
237+
public static void display()
238+
{
239+
System.out.println("All the elements present in the stack are:");
240+
for(int i=0;i<top;i++)
241+
System.out.print(st[i]+" ");
242+
System.out.println();
243+
}
244+
public static void main(String []args)
245+
{
246+
Scanner sc=new Scanner(System.in);
247+
int ch;int c=0;
248+
do
249+
{
250+
c=0;
251+
System.out.println("Enter choice ");
252+
System.out.println("1. Add new element"
253+
+ "\n"+"2. Remove topmost eleemnt"
254+
+"\n3. To view the topmost element"+"\n4. To view all the elements");
255+
ch=sc.nextInt();
256+
switch(ch)
257+
{
258+
case 1:
259+
System.out.println("Enter element to be added to stack ");
260+
int n=sc.nextInt();
261+
push(n);
262+
break;
263+
case 2:
264+
pop();
265+
break;
266+
case 3:
267+
peek();
268+
break;
269+
case 4:
270+
display();
271+
break;
272+
default:
273+
System.out.println("Invalid choice :");
274+
}
275+
System.out.println("Enter 1 if you wish to continue");
276+
c=sc.nextInt();
277+
}
278+
while(c==1);
279+
}
280+
}
185281
```

0 commit comments

Comments
 (0)