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

Commit 84593ed

Browse files
authored
Merge pull request #619 from MikleC/Лабораторная№23-25
лабораторная№23-25
2 parents 9aaa47e + 4b0731a commit 84593ed

File tree

22 files changed

+509
-0
lines changed

22 files changed

+509
-0
lines changed

students/23K0565/23K0565-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>23K0565</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0565-p23</artifactId>
12+
<description>23 практическая</description>
13+
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
public class ArrQueue {
4+
private final int[] queue;
5+
private int size;
6+
private int front;
7+
private int rear;
8+
9+
public ArrQueue(int capacity) {
10+
queue = new int[capacity];
11+
size = 0;
12+
front = 0;
13+
rear = 0;
14+
}
15+
16+
public void enqueue(int val) {
17+
if (size == queue.length) {
18+
throw new IllegalStateException("Queue full");
19+
}
20+
queue[rear] = val;
21+
rear = (rear + 1) % queue.length;
22+
size++;
23+
}
24+
25+
public int element() {
26+
if (size == 0) {
27+
throw new IllegalStateException("Queue empty");
28+
}
29+
return queue[front];
30+
}
31+
32+
public int dequeue() {
33+
if (size == 0) {
34+
throw new IllegalStateException("Queue empty");
35+
}
36+
int val = queue[front];
37+
front = (front + 1) % queue.length;
38+
size--;
39+
return val;
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+
size = 0;
52+
front = 0;
53+
rear = 0;
54+
}
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
public class ArrQueueADt {
4+
private final int[] queue;
5+
private int size;
6+
private int front;
7+
private int rear;
8+
9+
public ArrQueueADt(int capacity) {
10+
queue = new int[capacity];
11+
size = 0;
12+
front = 0;
13+
rear = 0;
14+
}
15+
16+
public static void enqueue(ArrQueueADt q, int val) {
17+
if (q.size == q.queue.length) {
18+
throw new IllegalStateException("Queue full");
19+
}
20+
q.queue[q.rear] = val;
21+
q.rear = (q.rear + 1) % q.queue.length;
22+
q.size++;
23+
}
24+
25+
public static int element(ArrQueueADt q) {
26+
if (q.size == 0) {
27+
throw new IllegalStateException("Queue empty");
28+
}
29+
return q.queue[q.front];
30+
}
31+
32+
public static int dequeue(ArrQueueADt q) {
33+
if (q.size == 0) {
34+
throw new IllegalStateException("Queue empty");
35+
}
36+
int val = q.queue[q.front];
37+
q.front = (q.front + 1) % q.queue.length;
38+
q.size--;
39+
return val;
40+
}
41+
42+
public static int size(ArrQueueADt q) {
43+
return q.size;
44+
}
45+
46+
public static boolean isEmpty(ArrQueueADt q) {
47+
return q.size == 0;
48+
}
49+
50+
public static void clear(ArrQueueADt q) {
51+
q.size = 0;
52+
q.front = 0;
53+
q.rear = 0;
54+
}
55+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
public final class ArrQueueMod {
4+
private static final int CAPACITY = 10;
5+
private static final int[] queue = new int[CAPACITY];
6+
private static int size = 0;
7+
private static int front = 0;
8+
private static int rear = 0;
9+
10+
private ArrQueueMod() {
11+
throw new UnsupportedOperationException("Utility class");
12+
}
13+
14+
public static void enqueue(int val) {
15+
if (size == CAPACITY) {
16+
throw new IllegalStateException("Queue full");
17+
}
18+
queue[rear] = val;
19+
rear = (rear + 1) % CAPACITY;
20+
size++;
21+
}
22+
23+
public static int element() {
24+
if (size == 0) {
25+
throw new IllegalStateException("Queue empty");
26+
}
27+
return queue[front];
28+
}
29+
30+
public static int dequeue() {
31+
if (size == 0) {
32+
throw new IllegalStateException("Queue empty");
33+
}
34+
int val = queue[front];
35+
front = (front + 1) % CAPACITY;
36+
size--;
37+
return val;
38+
}
39+
40+
public static int size() {
41+
return size;
42+
}
43+
44+
public static boolean isEmpty() {
45+
return size == 0;
46+
}
47+
48+
public static void clear() {
49+
size = 0;
50+
front = 0;
51+
rear = 0;
52+
}
53+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
public abstract class AbsQueue implements Queue {
4+
protected int size = 0;
5+
6+
@Override
7+
public int size() {
8+
return size;
9+
}
10+
11+
@Override
12+
public boolean isEmpty() {
13+
return size == 0;
14+
}
15+
16+
@Override
17+
public void clear() {
18+
size = 0;
19+
}
20+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
public class LinkQueue extends AbsQueue {
4+
private static class Node {
5+
int value;
6+
Node next;
7+
8+
Node(int val, Node next) {
9+
this.value = val;
10+
this.next = next;
11+
}
12+
}
13+
14+
private Node head = null;
15+
private Node tail = null;
16+
17+
@Override
18+
public void enqueue(int val) {
19+
Node newNode = new Node(val, null);
20+
if (tail == null) {
21+
head = newNode;
22+
} else {
23+
tail.next = newNode;
24+
}
25+
tail = newNode;
26+
size++;
27+
}
28+
29+
@Override
30+
public int element() {
31+
if (isEmpty()) {
32+
throw new IllegalStateException("Queue empty");
33+
} else {
34+
return head.value;
35+
}
36+
}
37+
38+
@Override
39+
public int dequeue() {
40+
if (isEmpty()) {
41+
throw new IllegalStateException("Queue empty");
42+
} else {
43+
final int val = head.value;
44+
head = head.next;
45+
if (head == null) {
46+
tail = null;
47+
}
48+
size--;
49+
return val;
50+
}
51+
}
52+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
public interface Queue {
4+
void enqueue(int val);
5+
6+
int element();
7+
8+
int dequeue();
9+
10+
int size();
11+
12+
boolean isEmpty();
13+
14+
void clear();
15+
}

students/23K0565/23K0565-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>23K0565</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0565-p24</artifactId>
12+
<description>24 практическая</description>
13+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
class Comx {
4+
private int r;
5+
private int i;
6+
7+
public Comx() {
8+
this.r = 0;
9+
this.i = 0;
10+
}
11+
12+
public Comx(int r, int i) {
13+
this.r = r;
14+
this.i = i;
15+
}
16+
17+
@Override
18+
public String toString() {
19+
return "Comx{"
20+
+
21+
"r=" + r
22+
+
23+
", i=" + i
24+
+
25+
'}';
26+
}
27+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
interface ComxAbsFactory {
4+
Comx createComx();
5+
6+
Comx createComx(int r, int i);
7+
}

0 commit comments

Comments
 (0)