Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit be21fb3

Browse files
authored
Merge pull request #642 from Timmmmofey/features/lab30
Features/lab30
2 parents a06bc95 + b3b4a63 commit be21fb3

File tree

30 files changed

+1025
-0
lines changed

30 files changed

+1025
-0
lines changed

students/23K1302/23K1302-p21/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K1302</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K1302-p21</artifactId>
12+
<description>Задание 21</description>
13+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
public final class Ex1 {
8+
9+
private Ex1() {
10+
// 123
11+
}
12+
13+
public static <T> List<T> convertArrayToList(T[] array) {
14+
return new ArrayList<>(Arrays.asList(array));
15+
}
16+
17+
public static void main(String[] args) {
18+
19+
String[] stringArray = {"Один", "Два", "Три"};
20+
Integer[] intArray = {1, 2, 3};
21+
22+
List<String> stringList = convertArrayToList(stringArray);
23+
List<Integer> intList = convertArrayToList(intArray);
24+
25+
System.out.println("String List: " + stringList);
26+
System.out.println("Integer List: " + intList);
27+
}
28+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class Ex2<T> {
4+
private final T[] array;
5+
6+
@SuppressWarnings("unchecked")
7+
public Ex2(int size) {
8+
array = (T[]) new Object[size];
9+
}
10+
11+
public void set(int index, T value) {
12+
array[index] = value;
13+
}
14+
15+
public T get(int index) {
16+
return array[index];
17+
}
18+
19+
public int size() {
20+
return array.length;
21+
}
22+
23+
public static void main(String[] args) {
24+
Ex2<Integer> intArray = new Ex2<>(5);
25+
intArray.set(0, 42);
26+
intArray.set(1, 100);
27+
28+
System.out.println("Value at index 0: " + intArray.get(0));
29+
System.out.println("Value at index 1: " + intArray.get(1));
30+
31+
Ex2<String> stringArray = new Ex2<>(3);
32+
stringArray.set(0, "Hello");
33+
stringArray.set(1, "World");
34+
35+
System.out.println("Value at index 0: " + stringArray.get(0));
36+
System.out.println("Value at index 1: " + stringArray.get(1));
37+
}
38+
}

students/23K1302/23K1302-p22/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K1302</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K1302-p22</artifactId>
12+
<description>Задание 22</description>
13+
</project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Stack;
4+
import java.util.Scanner;
5+
6+
public final class Rpnalculator {
7+
8+
private Rpnalculator() {
9+
// 456
10+
}
11+
12+
public static double evaluaterpn(String expression) {
13+
Stack<Double> stack = new Stack<>();
14+
String[] tokens = expression.split(" ");
15+
16+
for (String token : tokens) {
17+
switch (token) {
18+
case "+":
19+
stack.push(stack.pop() + stack.pop());
20+
break;
21+
case "-":
22+
double b = stack.pop();
23+
double a = stack.pop();
24+
stack.push(a - b);
25+
break;
26+
case "*":
27+
stack.push(stack.pop() * stack.pop());
28+
break;
29+
case "/":
30+
double divisor = stack.pop();
31+
double dividend = stack.pop();
32+
if (divisor == 0) {
33+
throw new ArithmeticException("Деление на ноль");
34+
}
35+
stack.push(dividend / divisor);
36+
break;
37+
default:
38+
stack.push(Double.parseDouble(token));
39+
break;
40+
}
41+
}
42+
43+
if (stack.size() != 1) {
44+
throw new IllegalArgumentException("Выражение некорректно");
45+
}
46+
47+
return stack.pop();
48+
}
49+
50+
public static void main(String[] args) {
51+
Scanner scanner = new Scanner(System.in);
52+
53+
try {
54+
while (true) {
55+
System.out.println("Введите выражение:");
56+
String input = scanner.nextLine();
57+
58+
try {
59+
double result = evaluaterpn(input);
60+
System.out.println("Результат: " + result);
61+
} catch (Exception e) {
62+
System.err.println("Ошибка: " + e.getMessage());
63+
}
64+
}
65+
} finally {
66+
scanner.close();
67+
}
68+
}
69+
}

students/23K1302/23K1302-p23/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<artifactId>23K1302</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K1302-p23</artifactId>
12+
<description>Задание 23</description>
13+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public final class Arrayqueue {
4+
5+
private Object[] queue = new Object[16];
6+
private int head = 0;
7+
private int tail = 0;
8+
private int size = 0;
9+
10+
public static Arrayqueue createQueue() {
11+
return new Arrayqueue();
12+
}
13+
14+
public void enqueue(Object element) {
15+
ensureCapacity(size + 1);
16+
queue[tail] = element;
17+
tail = (tail + 1) % queue.length;
18+
size++;
19+
}
20+
21+
public Object element() {
22+
return queue[head];
23+
}
24+
25+
public Object dequeue() {
26+
Object result;
27+
result = queue[head];
28+
queue[head] = null;
29+
head = (head + 1) % queue.length;
30+
size--;
31+
return result;
32+
}
33+
34+
public int size() {
35+
return size;
36+
}
37+
38+
public boolean isEmpty() {
39+
return size == 0;
40+
}
41+
42+
public void clear() {
43+
queue = new Object[16];
44+
head = tail = size = 0;
45+
}
46+
47+
private void ensureCapacity(int capacity) {
48+
if (capacity > queue.length) {
49+
Object[] newQueue = new Object[queue.length * 2];
50+
for (int i = 0; i < size; i++) {
51+
newQueue[i] = queue[(head + i) % queue.length];
52+
}
53+
queue = newQueue;
54+
head = 0;
55+
tail = size;
56+
}
57+
}
58+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public final class Arrayqueueadt {
4+
5+
private Object[] queue = new Object[16];
6+
private int head = 0;
7+
private int tail = 0;
8+
private int size = 0;
9+
10+
public static void enqueue(Arrayqueueadt queueadt, Object element) {
11+
ensureCapacity(queueadt, queueadt.size + 1);
12+
queueadt.queue[queueadt.tail] = element;
13+
queueadt.tail = (queueadt.tail + 1) % queueadt.queue.length;
14+
queueadt.size++;
15+
}
16+
17+
public static Object element(Arrayqueueadt queueadt) {
18+
return queueadt.queue[queueadt.head];
19+
}
20+
21+
public static Object dequeue(Arrayqueueadt queueadt) {
22+
23+
Object result;
24+
result = queueadt.queue[queueadt.head];
25+
queueadt.queue[queueadt.head] = null;
26+
queueadt.head = (queueadt.head + 1) % queueadt.queue.length;
27+
queueadt.size--;
28+
return result;
29+
}
30+
31+
public static int size(Arrayqueueadt queueadt) {
32+
return queueadt.size;
33+
}
34+
35+
public static boolean isEmpty(Arrayqueueadt queueadt) {
36+
return queueadt.size == 0;
37+
}
38+
39+
public static void clear(Arrayqueueadt queueadt) {
40+
queueadt.queue = new Object[16];
41+
queueadt.head = queueadt.tail = queueadt.size = 0;
42+
}
43+
44+
private static void ensureCapacity(Arrayqueueadt queueadt, int capacity) {
45+
if (capacity > queueadt.queue.length) {
46+
Object[] newQueue = new Object[queueadt.queue.length * 2];
47+
for (int i = 0; i < queueadt.size; i++) {
48+
newQueue[i] = queueadt.queue[(queueadt.head + i) % queueadt.queue.length];
49+
}
50+
queueadt.queue = newQueue;
51+
queueadt.head = 0;
52+
queueadt.tail = queueadt.size;
53+
}
54+
}
55+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public final class Arrayqueuemodule {
4+
5+
private Arrayqueuemodule() {
6+
// тут пусто(
7+
}
8+
9+
private static final int INITIAL_CAPACITY = 16;
10+
private static Object[] queue = new Object[INITIAL_CAPACITY];
11+
private static int head = 0;
12+
private static int tail = 0;
13+
private static int size = 0;
14+
15+
public static void enqueue(Object element) {
16+
ensureCapacity(size + 1);
17+
queue[tail] = element;
18+
tail = (tail + 1) % queue.length;
19+
size++;
20+
}
21+
22+
public static Object element() {
23+
return queue[head];
24+
}
25+
26+
public static Object dequeue() {
27+
28+
Object result;
29+
result = queue[head];
30+
queue[head] = null;
31+
head = (head + 1) % queue.length;
32+
size--;
33+
return result;
34+
}
35+
36+
public static int size() {
37+
return size;
38+
}
39+
40+
public static boolean isEmpty() {
41+
return size == 0;
42+
}
43+
44+
public static void clear() {
45+
queue = new Object[INITIAL_CAPACITY];
46+
head = tail = size = 0;
47+
}
48+
49+
private static void ensureCapacity(int capacity) {
50+
if (capacity > queue.length) {
51+
Object[] newQueue = new Object[queue.length * 2];
52+
for (int i = 0; i < size; i++) {
53+
newQueue[i] = queue[(head + i) % queue.length];
54+
}
55+
queue = newQueue;
56+
head = 0;
57+
tail = size;
58+
}
59+
}
60+
}
61+

0 commit comments

Comments
 (0)