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

Features/lab26 #632

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions students/23K1302/23K1302-p21/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K1302</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K1302-p21</artifactId>
<description>Задание 21</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ru.mirea.practice.s0000001;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public final class Ex1 {

private Ex1() {
// 123
}

public static <T> List<T> convertArrayToList(T[] array) {
return new ArrayList<>(Arrays.asList(array));
}

public static void main(String[] args) {

String[] stringArray = {"Один", "Два", "Три"};
Integer[] intArray = {1, 2, 3};

List<String> stringList = convertArrayToList(stringArray);
List<Integer> intList = convertArrayToList(intArray);

System.out.println("String List: " + stringList);
System.out.println("Integer List: " + intList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ru.mirea.practice.s0000001;

public class Ex2<T> {
private final T[] array;

@SuppressWarnings("unchecked")
public Ex2(int size) {
array = (T[]) new Object[size];
}

public void set(int index, T value) {
array[index] = value;
}

public T get(int index) {
return array[index];
}

public int size() {
return array.length;
}

public static void main(String[] args) {
Ex2<Integer> intArray = new Ex2<>(5);
intArray.set(0, 42);
intArray.set(1, 100);

System.out.println("Value at index 0: " + intArray.get(0));
System.out.println("Value at index 1: " + intArray.get(1));

Ex2<String> stringArray = new Ex2<>(3);
stringArray.set(0, "Hello");
stringArray.set(1, "World");

System.out.println("Value at index 0: " + stringArray.get(0));
System.out.println("Value at index 1: " + stringArray.get(1));
}
}
13 changes: 13 additions & 0 deletions students/23K1302/23K1302-p22/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K1302</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K1302-p22</artifactId>
<description>Задание 22</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package ru.mirea.practice.s0000001;

import java.util.Stack;
import java.util.Scanner;

public final class Rpnalculator {

private Rpnalculator() {
// 456
}

public static double evaluaterpn(String expression) {
Stack<Double> stack = new Stack<>();
String[] tokens = expression.split(" ");

for (String token : tokens) {
switch (token) {
case "+":
stack.push(stack.pop() + stack.pop());
break;
case "-":
double b = stack.pop();
double a = stack.pop();
stack.push(a - b);
break;
case "*":
stack.push(stack.pop() * stack.pop());
break;
case "/":
double divisor = stack.pop();
double dividend = stack.pop();
if (divisor == 0) {
throw new ArithmeticException("Деление на ноль");
}
stack.push(dividend / divisor);
break;
default:
stack.push(Double.parseDouble(token));
break;
}
}

if (stack.size() != 1) {
throw new IllegalArgumentException("Выражение некорректно");
}

return stack.pop();
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

try {
while (true) {
System.out.println("Введите выражение:");
String input = scanner.nextLine();

try {
double result = evaluaterpn(input);
System.out.println("Результат: " + result);
} catch (Exception e) {
System.err.println("Ошибка: " + e.getMessage());
}
}
} finally {
scanner.close();
}
}
}
13 changes: 13 additions & 0 deletions students/23K1302/23K1302-p23/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K1302</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K1302-p23</artifactId>
<description>Задание 23</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ru.mirea.practice.s0000001;

public final class Arrayqueue {

private Object[] queue = new Object[16];
private int head = 0;
private int tail = 0;
private int size = 0;

public static Arrayqueue createQueue() {
return new Arrayqueue();
}

public void enqueue(Object element) {
ensureCapacity(size + 1);
queue[tail] = element;
tail = (tail + 1) % queue.length;
size++;
}

public Object element() {
return queue[head];
}

public Object dequeue() {
Object result;
result = queue[head];
queue[head] = null;
head = (head + 1) % queue.length;
size--;
return result;
}

public int size() {
return size;
}

public boolean isEmpty() {
return size == 0;
}

public void clear() {
queue = new Object[16];
head = tail = size = 0;
}

private void ensureCapacity(int capacity) {
if (capacity > queue.length) {
Object[] newQueue = new Object[queue.length * 2];
for (int i = 0; i < size; i++) {
newQueue[i] = queue[(head + i) % queue.length];
}
queue = newQueue;
head = 0;
tail = size;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ru.mirea.practice.s0000001;

public final class Arrayqueueadt {

private Object[] queue = new Object[16];
private int head = 0;
private int tail = 0;
private int size = 0;

public static void enqueue(Arrayqueueadt queueadt, Object element) {
ensureCapacity(queueadt, queueadt.size + 1);
queueadt.queue[queueadt.tail] = element;
queueadt.tail = (queueadt.tail + 1) % queueadt.queue.length;
queueadt.size++;
}

public static Object element(Arrayqueueadt queueadt) {
return queueadt.queue[queueadt.head];
}

public static Object dequeue(Arrayqueueadt queueadt) {

Object result;
result = queueadt.queue[queueadt.head];
queueadt.queue[queueadt.head] = null;
queueadt.head = (queueadt.head + 1) % queueadt.queue.length;
queueadt.size--;
return result;
}

public static int size(Arrayqueueadt queueadt) {
return queueadt.size;
}

public static boolean isEmpty(Arrayqueueadt queueadt) {
return queueadt.size == 0;
}

public static void clear(Arrayqueueadt queueadt) {
queueadt.queue = new Object[16];
queueadt.head = queueadt.tail = queueadt.size = 0;
}

private static void ensureCapacity(Arrayqueueadt queueadt, int capacity) {
if (capacity > queueadt.queue.length) {
Object[] newQueue = new Object[queueadt.queue.length * 2];
for (int i = 0; i < queueadt.size; i++) {
newQueue[i] = queueadt.queue[(queueadt.head + i) % queueadt.queue.length];
}
queueadt.queue = newQueue;
queueadt.head = 0;
queueadt.tail = queueadt.size;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package ru.mirea.practice.s0000001;

public final class Arrayqueuemodule {

private Arrayqueuemodule() {
// тут пусто(
}

private static final int INITIAL_CAPACITY = 16;
private static Object[] queue = new Object[INITIAL_CAPACITY];
private static int head = 0;
private static int tail = 0;
private static int size = 0;

public static void enqueue(Object element) {
ensureCapacity(size + 1);
queue[tail] = element;
tail = (tail + 1) % queue.length;
size++;
}

public static Object element() {
return queue[head];
}

public static Object dequeue() {

Object result;
result = queue[head];
queue[head] = null;
head = (head + 1) % queue.length;
size--;
return result;
}

public static int size() {
return size;
}

public static boolean isEmpty() {
return size == 0;
}

public static void clear() {
queue = new Object[INITIAL_CAPACITY];
head = tail = size = 0;
}

private static void ensureCapacity(int capacity) {
if (capacity > queue.length) {
Object[] newQueue = new Object[queue.length * 2];
for (int i = 0; i < size; i++) {
newQueue[i] = queue[(head + i) % queue.length];
}
queue = newQueue;
head = 0;
tail = size;
}
}
}

Loading
Loading