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

Commit c5828d7

Browse files
authored
Merge pull request #682 from zula4z/lab21-30
Лабораторные №№21-30
2 parents f72e743 + dc56ea0 commit c5828d7

File tree

36 files changed

+917
-0
lines changed

36 files changed

+917
-0
lines changed

students/23K0340/23K0340-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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23K0340</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0340-p21</artifactId>
12+
<description>Массивы</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.LinkedList;
5+
import java.util.List;
6+
7+
public abstract class First {
8+
public static void main(String[] args) {
9+
String[] s = new String[5];
10+
s[0] = "a";
11+
s[1] = "b";
12+
s[2] = "c";
13+
s[3] = "d";
14+
s[4] = "e";
15+
List<String> s1 = new LinkedList<>();
16+
s1 = arraytolst(s);
17+
System.out.println(s1.get(0));
18+
}
19+
20+
public static <T> List<T> arraytolst(T[] arr) {
21+
int len = arr.length;
22+
ArrayList<T> lst = new ArrayList<>();
23+
for (int i = 0;i < len;i++) {
24+
lst.add(arr[i]);
25+
}
26+
return (List<T>) lst;
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public abstract class Second {
4+
public static class Mass<T> {
5+
private Object[] arr;
6+
private int size;
7+
8+
public Mass(int size) {
9+
this.size = size;
10+
this.arr = new Object[size];
11+
}
12+
13+
public void add(T t, int i) {
14+
arr[i] = t;
15+
}
16+
17+
public <T> T get(int i) {
18+
return (T) arr[i];
19+
}
20+
}
21+
22+
public static void main(String[] args) {
23+
Mass<String> mas = new Mass<>(5);
24+
Mass<Double> mass = new Mass<Double>(5);
25+
for (int i = 0; i < 5; i++) {
26+
mas.add("a", i);
27+
mass.add(Math.pow(2, i), i);
28+
}
29+
System.out.println((String)mas.get(3));
30+
System.out.println((Double)mass.get(2));
31+
}
32+
}

students/23K0340/23K0340-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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23K0340</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0340-p22</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class Calc {
4+
private Stack stack;
5+
private int size;
6+
7+
public Calc(int size) {
8+
this.size = size;
9+
this.stack = new Stack(size);
10+
}
11+
12+
public int getSize() {
13+
return size;
14+
}
15+
16+
public void iter(String data) {
17+
if (isStringDouble(data)) {
18+
this.stack.push(Double.parseDouble(data));
19+
} else {
20+
if ("*".equals(data)) {
21+
this.stack.push(this.stack.pop() * this.stack.pop());
22+
} else if ("/".equals(data)) {
23+
this.stack.push(Math.pow(this.stack.pop(), -1) * this.stack.pop());
24+
} else if ("+".equals(data)) {
25+
this.stack.push(this.stack.pop() + this.stack.pop());
26+
} else if ("-".equals(data)) {
27+
this.stack.push(this.stack.pop() * (-1) + this.stack.pop());
28+
} else {
29+
System.out.println("Incorrect input");
30+
}
31+
}
32+
}
33+
34+
public boolean isStringDouble(String s) {
35+
try {
36+
Double.parseDouble(s);
37+
return true;
38+
} catch (NumberFormatException ex) {
39+
return false;
40+
}
41+
}
42+
43+
public double end() {
44+
return this.stack.pop();
45+
}
46+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
import java.util.Scanner;
4+
5+
public abstract class Main {
6+
public static void main(String[] args) {
7+
try (Scanner sc = new Scanner(System.in)) {
8+
Calc calc = new Calc(10);
9+
boolean end = true;
10+
String s = "";
11+
while (end) {
12+
s = sc.nextLine();
13+
if ("".equals(s)) {
14+
System.out.println(calc.end());
15+
break;
16+
}
17+
calc.iter(s);
18+
}
19+
20+
}
21+
}
22+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class Stack {
4+
private double[] arr;
5+
private int top;
6+
private int capacity;
7+
8+
public Stack(int capacity) {
9+
this.arr = new double[capacity];
10+
this.top = -1;
11+
this.capacity = capacity;
12+
}
13+
14+
public void push(double data) {
15+
if (isFull()) {
16+
System.out.println("The stack is full");
17+
System.exit(1);
18+
}
19+
this.arr[++top] = data;
20+
}
21+
22+
public double pop() {
23+
if (isEmpty()) {
24+
System.out.println("The stack is empty");
25+
System.exit(1);
26+
}
27+
return arr[top--];
28+
}
29+
30+
public boolean isFull() {
31+
return top == capacity - 1;
32+
}
33+
34+
public boolean isEmpty() {
35+
return top == -1;
36+
}
37+
38+
public int getTop() {
39+
return top;
40+
}
41+
}

students/23K0340/23K0340-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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>23K0340</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0340-p23</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class ArrayQueueModule {
4+
private int size;
5+
private int[] queue;
6+
private int front;
7+
private int rear;
8+
private int n;
9+
10+
public ArrayQueueModule(int size) {
11+
this.size = size;
12+
this.queue = new int[size];
13+
this.front = 0;
14+
this.rear = -1;
15+
this.n = 0;
16+
}
17+
18+
public void clear() {
19+
while (n != rear) {
20+
front = (front + 1) % size;
21+
n--;
22+
}
23+
}
24+
25+
public int element() {
26+
if (rear == -1) {
27+
System.out.println("The queue is empty");
28+
}
29+
return queue[rear];
30+
}
31+
32+
public void enqueue(int value) {
33+
if (n == size) {
34+
System.out.println("The queue is full");
35+
return;
36+
}
37+
rear = (rear + 1) % size;
38+
queue[rear] = value;
39+
n++;
40+
}
41+
42+
public int dequeue() {
43+
if (n == 0) {
44+
System.out.println("The queue if empty");
45+
return -1;
46+
}
47+
int value = queue[front];
48+
front = (front + 1) % size;
49+
n--;
50+
return value;
51+
}
52+
53+
public boolean isEmpty() {
54+
return n == 0;
55+
}
56+
57+
public boolean isFull() {
58+
return n == size;
59+
}
60+
61+
public int size() {
62+
return n;
63+
}
64+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package ru.mirea.practice.s0000001;
2+
3+
public class ArrayQueueadt {
4+
private Node front;
5+
private Node rear;
6+
7+
public ArrayQueueadt() {
8+
this.front = null;
9+
this.rear = null;
10+
}
11+
12+
public int element() {
13+
return rear.data;
14+
}
15+
16+
public void enqueue(int data) {
17+
Node node = new Node(data);
18+
if (rear != null) {
19+
rear.next = node;
20+
}
21+
rear = node;
22+
if (front == null) {
23+
front = node;
24+
}
25+
}
26+
27+
public void clear() {
28+
this.rear = null;
29+
this.front = null;
30+
}
31+
32+
public int dequeue() {
33+
if (front == null) {
34+
return 0;
35+
}
36+
int data = front.data;
37+
front = front.next;
38+
if (front == null) {
39+
rear = null;
40+
}
41+
return data;
42+
}
43+
44+
public boolean isEmpty() {
45+
return front == null;
46+
}
47+
}

0 commit comments

Comments
 (0)