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

Commit cb9f817

Browse files
authored
Merge pull request #656 from SpooderWeld/Lab21-32
Practics 21-32
2 parents c25511f + 58d91b9 commit cb9f817

File tree

51 files changed

+1237
-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.

51 files changed

+1237
-0
lines changed

students/23K0563/23K0563-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>23K0563</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0563-p21</artifactId>
12+
<description>21</description>
13+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package mirea.lab21.p1;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
public class ArrayConvert {
8+
public <T> List<T> convert(T[] a) {
9+
List<T> l = new ArrayList<>();
10+
l.addAll(Arrays.asList(a));
11+
return l;
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package mirea.lab21.p1;
2+
3+
/* 1 Написать метод для конвертации массива строк/чисел в список. */
4+
5+
import java.util.List;
6+
7+
public abstract class Prac21p1 {
8+
public static void main(String[] args) {
9+
ArrayConvert ar = new ArrayConvert();
10+
String[] s = {"abc", "def", "aaaaaa", "cbcbcb"};
11+
List list = ar.convert(s);
12+
System.out.println(list.toString());
13+
}
14+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package mirea.lab21.p2;
2+
3+
import java.util.Arrays;
4+
5+
public class Anyarr<T> {
6+
private T[] array;
7+
8+
public Anyarr(T[] array) {
9+
this.array = array;
10+
}
11+
12+
public T[] getArray() {
13+
return array;
14+
}
15+
16+
public void setElement(int i, T e) {
17+
if (i >= 0 && i < array.length) {
18+
array[i] = e;
19+
}
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return Arrays.toString(array);
25+
}
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package mirea.lab21.p2;
2+
3+
import java.util.Arrays;
4+
5+
public abstract class Prac21p2 {
6+
public static void main(String[] args) {
7+
String[] s = {"abc","def","aaaaaaa"};
8+
System.out.println(Arrays.toString(s));
9+
Anyarr<String> arr = new Anyarr<String>(s);
10+
arr.setElement(1,"changed");
11+
System.out.println(arr.toString());
12+
}
13+
}

students/23K0563/23K0563-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>23K0563</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0563-p22</artifactId>
12+
<description>22</description>
13+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package mirea.lab22;
2+
3+
import java.util.Scanner;
4+
import java.util.Stack;
5+
6+
public abstract class Prac22p1p2 {
7+
public static void main(String[] args) {
8+
try (Scanner sc = new Scanner(System.in)) {
9+
System.out.println("Введите выражение в польской нотации: ");
10+
String[] exp = null;
11+
try {
12+
exp = sc.nextLine().split(" ");
13+
} catch (Exception e) {
14+
System.out.println("Ошибка ввода!");
15+
}
16+
Stack<Double> s = new Stack<Double>();
17+
if (exp != null) {
18+
try {
19+
for (String i : exp) {
20+
switch (i) {
21+
case "+":
22+
s.push(s.pop() + s.pop());
23+
break;
24+
case "-":
25+
s.push(-(s.pop() - s.pop()));
26+
break;
27+
case "*":
28+
s.push(s.pop() * s.pop());
29+
break;
30+
case "/":
31+
double delit = s.pop();
32+
double delim = s.pop();
33+
s.push(delim / delit);
34+
break;
35+
default:
36+
double n = Double.parseDouble(i);
37+
s.push(n);
38+
break;
39+
}
40+
}
41+
} catch (Exception e) {
42+
System.out.println("Ошибка счета: " + e.getMessage());
43+
}
44+
}
45+
System.out.println(s.pop());
46+
}
47+
48+
}
49+
}

students/23K0563/23K0563-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>23K0563</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0563-p23</artifactId>
12+
<description>23</description>
13+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package mirea.lab23.p1;
2+
3+
public class ArrayQueue<T> {
4+
private T[] q;
5+
private int front;
6+
private int back;
7+
private int am;
8+
private int size;
9+
10+
public ArrayQueue(int size) {
11+
front = 0;
12+
back = 0;
13+
am = 0;
14+
this.size = size;
15+
}
16+
17+
public void enqueue(T t) {
18+
if (am < size) {
19+
q[back] = t;
20+
am++;
21+
back = (back + 1) % size;
22+
}
23+
}
24+
25+
public T dequeue() {
26+
T t = q[front];
27+
front = (front + 1) % size;
28+
am--;
29+
return t;
30+
}
31+
32+
public T peek() {
33+
if (am >= 0) {
34+
return q[front];
35+
}
36+
return null;
37+
}
38+
39+
public boolean isFull() {
40+
return am == size;
41+
}
42+
43+
public boolean isEmpty() {
44+
return am == 0;
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package mirea.lab23.p1;
2+
3+
public class ArrayQueueModule<T> {
4+
private T[] q;
5+
private int front;
6+
private int back;
7+
private int am;
8+
private int size;
9+
10+
public ArrayQueueModule(int size) {
11+
front = 0;
12+
back = 0;
13+
am = 0;
14+
this.size = size;
15+
}
16+
17+
public void enqueue(T t) {
18+
if (am < size) {
19+
q[back] = t;
20+
am++;
21+
back = (back + 1) % size;
22+
}
23+
}
24+
25+
public T dequeue() {
26+
T t = q[front];
27+
front = (front + 1) % size;
28+
am--;
29+
return t;
30+
}
31+
32+
public boolean isFull() {
33+
return am == size;
34+
}
35+
36+
public T peek() {
37+
if (am >= 0) {
38+
return q[front];
39+
}
40+
return null;
41+
}
42+
43+
public boolean isEmpty() {
44+
return am == 0;
45+
}
46+
}

0 commit comments

Comments
 (0)