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

Commit d4f4c76

Browse files
authored
Merge pull request #696 from nimusvlad/labfrom21to32
Лабораторные №21 - №30
2 parents 82fb9e5 + eff2d76 commit d4f4c76

File tree

42 files changed

+914
-0
lines changed

Some content is hidden

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

42 files changed

+914
-0
lines changed

students/23K0089/23K0089-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>23K0089</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0089-p21</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s23k0089;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("первая практическая работа!");
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ru.mirea.practice.s23k0089.task1;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public abstract class Main {
7+
public static <T> List<T> arrToList(T[] array) {
8+
List<T> list = new ArrayList<>(array.length);
9+
for (T element : array) {
10+
list.add(element);
11+
}
12+
return list;
13+
}
14+
15+
public static void main(String[] args) {
16+
Integer[] arr = {1, 2, 3, 4, 5};
17+
List<Integer> list = arrToList(arr);
18+
System.out.println(list);
19+
20+
String[] arr1 = {"one", "two", "three", "banana"};
21+
List<String> list1 = arrToList(arr1);
22+
System.out.println(list1);
23+
}
24+
}
25+

students/23K0089/23K0089-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>23K0089</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0089-p23</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.mirea.practice.s23k0089;
2+
3+
public final class Main {
4+
5+
private Main() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
System.out.println("первая практическая работа!");
11+
}
12+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ru.mirea.practice.s23k0089.task1;
2+
3+
public class ArrayQueue {
4+
private double[] elements;
5+
private int head;
6+
private int tail;
7+
private int size;
8+
9+
public ArrayQueue(int capacity) {
10+
this.elements = new double[capacity];
11+
this.head = 0;
12+
this.tail = 0;
13+
this.size = 0;
14+
}
15+
16+
public void enqueue(double value) {
17+
if (size == elements.length) {
18+
throw new IllegalStateException("Очередь переполнена");
19+
}
20+
elements[tail] = value;
21+
tail = (tail + 1) % elements.length;
22+
size++;
23+
}
24+
25+
public double dequeue() {
26+
if (isEmpty()) {
27+
throw new IllegalStateException("Очередь пуста");
28+
}
29+
double value = elements[head];
30+
head = (head + 1) % elements.length;
31+
size--;
32+
return value;
33+
}
34+
35+
public double element() {
36+
if (isEmpty()) {
37+
throw new IllegalStateException("Очередь пуста");
38+
}
39+
return elements[head];
40+
}
41+
42+
public int size() {
43+
return size;
44+
}
45+
46+
public boolean isEmpty() {
47+
return size == 0;
48+
}
49+
50+
public void clear() {
51+
head = 0;
52+
tail = 0;
53+
size = 0;
54+
}
55+
56+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package ru.mirea.practice.s23k0089.task1;
2+
3+
public class ArrayQueueADt {
4+
private double[] elements;
5+
private int head;
6+
private int tail;
7+
private int size;
8+
9+
public ArrayQueueADt(int capacity) {
10+
elements = new double[capacity];
11+
head = 0;
12+
tail = 0;
13+
size = 0;
14+
}
15+
16+
public void enqueue(double value) {
17+
if (size == elements.length) {
18+
throw new IllegalStateException("Очередь переполнена");
19+
}
20+
elements[tail] = value;
21+
tail = (tail + 1) % elements.length;
22+
size++;
23+
}
24+
25+
public double dequeue() {
26+
if (isEmpty()) {
27+
throw new IllegalStateException("Очередь пуста");
28+
}
29+
double value = elements[head];
30+
head = (head + 1) % elements.length;
31+
size--;
32+
return value;
33+
}
34+
35+
public double element() {
36+
if (isEmpty()) {
37+
throw new IllegalStateException("Очередь пуста");
38+
}
39+
return elements[head];
40+
}
41+
42+
public int size() {
43+
return size;
44+
}
45+
46+
public boolean isEmpty() {
47+
return size == 0;
48+
}
49+
50+
public void clear() {
51+
head = 0;
52+
tail = 0;
53+
size = 0;
54+
}
55+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ru.mirea.practice.s23k0089.task1;
2+
3+
public abstract class ArrayQueueModule {
4+
private static final int capacity = 10;
5+
private static double[] elements;
6+
private static int head;
7+
private static int tail;
8+
private static int size;
9+
10+
static {
11+
elements = new double[capacity];
12+
head = 0;
13+
tail = 0;
14+
size = 0;
15+
}
16+
17+
public static void enqueue(double value) {
18+
if (size == elements.length) {
19+
throw new IllegalStateException("Очередь переполнена");
20+
}
21+
elements[tail] = value;
22+
tail = (tail + 1) % elements.length;
23+
size++;
24+
}
25+
26+
public static double dequeue() {
27+
if (isEmpty()) {
28+
throw new IllegalStateException("Очередь пуста");
29+
}
30+
double value = elements[head];
31+
head = (head + 1) % elements.length;
32+
size--;
33+
return value;
34+
}
35+
36+
public static double element() {
37+
if (isEmpty()) {
38+
throw new IllegalStateException("Очередь пуста");
39+
}
40+
return elements[head];
41+
}
42+
43+
public static int size() {
44+
return size;
45+
}
46+
47+
public static boolean isEmpty() {
48+
return size == 0;
49+
}
50+
51+
public static void clear() {
52+
head = 0;
53+
tail = 0;
54+
size = 0;
55+
}
56+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package ru.mirea.practice.s23k0089.task1;
2+
3+
public abstract class ArrayQueueTest {
4+
public static void main(String[] args) {
5+
ArrayQueue queue = new ArrayQueue(5);
6+
7+
System.out.println("Очередь пустая: " + queue.isEmpty());
8+
9+
queue.enqueue(1);
10+
queue.enqueue(2);
11+
queue.enqueue(3);
12+
13+
System.out.println("Первый элемент: " + queue.element());
14+
System.out.println("Размер очереди: " + queue.size());
15+
System.out.println("Удалённый элемент: " + queue.dequeue());
16+
System.out.println("Элемент после удаления: " + queue.element());
17+
18+
queue.clear();
19+
20+
System.out.println("Очередь пустая после очистки: " + queue.isEmpty());
21+
22+
try {
23+
queue.dequeue();
24+
} catch (IllegalStateException e) {
25+
System.out.println(e.getMessage());
26+
}
27+
}
28+
}

students/23K0089/23K0089-p24/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>23K0089</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0089-p24</artifactId>
12+
<description>Массивы</description>
13+
</project>

0 commit comments

Comments
 (0)