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

Commit 4b8c2cb

Browse files
authored
Merge pull request #688 from MikleC/Лабораторная№26-29-1
Changes26-29(1)
2 parents 5157b19 + 3009b51 commit 4b8c2cb

File tree

17 files changed

+611
-0
lines changed

17 files changed

+611
-0
lines changed

students/23K0565/23K0565-p26/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-p26</artifactId>
12+
<description>26 практическая</description>
13+
</project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
import java.util.Stack;
4+
5+
public final class InvertArray {
6+
private InvertArray() {
7+
}
8+
9+
public static int[] invert(int[] arr) {
10+
Stack<Integer> stack = new Stack<>();
11+
for (int num : arr) {
12+
stack.push(num);
13+
}
14+
15+
for (int i = 0; i < arr.length; i++) {
16+
arr[i] = stack.pop();
17+
}
18+
19+
return arr;
20+
}
21+
22+
public static void main(String[] args) {
23+
int[] data = {1, 2, 3, 4, 5};
24+
data = invert(data);
25+
for (int num : data) {
26+
System.out.print(num + " ");
27+
}
28+
}
29+
}
30+
//Upd
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
import java.util.Iterator;
4+
import java.util.List;
5+
6+
public class CusIterator<T> implements Iterator<T> {
7+
private List<T> lst;
8+
private int idx;
9+
10+
public CusIterator(List<T> lst) {
11+
this.lst = lst;
12+
this.idx = 0;
13+
}
14+
15+
@Override
16+
public boolean hasNext() {
17+
return idx < lst.size();
18+
}
19+
20+
@Override
21+
public T next() {
22+
return lst.get(idx++);
23+
}
24+
}
25+
//Upd
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public final class ListD {
7+
private ListD() {
8+
}
9+
10+
public static void main(String[] args) {
11+
List<Integer> nums = new ArrayList<>();
12+
nums.add(10);
13+
nums.add(20);
14+
nums.add(30);
15+
16+
CusIterator<Integer> iter = new CusIterator<>(nums);
17+
18+
while (iter.hasNext()) {
19+
System.out.println(iter.next());
20+
}
21+
}
22+
}
23+
//Upd
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.mirea.practice.s0000001.n3;
2+
3+
import java.util.Iterator;
4+
5+
public class CusIterator<T> implements Iterator<T> {
6+
private CusList<T> lst;
7+
private int idx;
8+
9+
public CusIterator(CusList<T> lst) {
10+
this.lst = lst;
11+
this.idx = 0;
12+
}
13+
14+
@Override
15+
public boolean hasNext() {
16+
return idx < lst.size();
17+
}
18+
19+
@Override
20+
public T next() {
21+
return lst.get(idx++);
22+
}
23+
}
24+
//Upd
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package ru.mirea.practice.s0000001.n3;
2+
3+
import java.util.Iterator;
4+
5+
public class CusList<T> implements Iterable<T> {
6+
private Object[] elements;
7+
private int size;
8+
9+
public CusList(int capacity) {
10+
elements = new Object[capacity];
11+
size = 0;
12+
}
13+
14+
public void add(T item) {
15+
if (size < elements.length) {
16+
elements[size++] = item;
17+
} else {
18+
throw new IndexOutOfBoundsException("Список заполнен(");
19+
}
20+
}
21+
22+
public T get(int index) {
23+
if (index >= 0 && index < size) {
24+
return (T) elements[index];
25+
} else {
26+
throw new IndexOutOfBoundsException("Некорректный индекс:(");
27+
}
28+
}
29+
30+
public int size() {
31+
return size;
32+
}
33+
34+
@Override
35+
public Iterator<T> iterator() {
36+
return new CusIterator<>(this);
37+
}
38+
}
39+
//Upd
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ru.mirea.practice.s0000001.n3;
2+
3+
public final class ListDemo {
4+
private ListDemo() {
5+
}
6+
7+
public static void main(String[] args) {
8+
CusList<Integer> nums = new CusList<>(5);
9+
nums.add(10);
10+
nums.add(20);
11+
nums.add(30);
12+
13+
for (int num : nums) {
14+
System.out.println(num);
15+
}
16+
}
17+
}
18+
//Upd

students/23K0565/23K0565-p27/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-p27</artifactId>
12+
<description>27 практическая</description>
13+
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ru.mirea.practice.s0000001.n1;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public final class Hashtab {
7+
private static final int SIZE = 10;
8+
private static Map<Integer, String> hTable;
9+
10+
private Hashtab() {
11+
}
12+
13+
public static int hashtabHash(String key) {
14+
return Math.abs(key.hashCode() % SIZE);
15+
}
16+
17+
public static void hashtabInit() {
18+
hTable = new HashMap<>();
19+
}
20+
21+
public static void hashtabAdd(String key, String value) {
22+
int idx = hashtabHash(key);
23+
hTable.put(idx, value);
24+
}
25+
26+
public static String hashtabLookup(String key) {
27+
int idx = hashtabHash(key);
28+
return hTable.get(idx);
29+
}
30+
31+
public static void hashtabDelete(String key) {
32+
int idx = hashtabHash(key);
33+
hTable.remove(idx);
34+
}
35+
36+
public static void main(String[] args) {
37+
hashtabInit();
38+
39+
hashtabAdd("ключ1", "значение1");
40+
hashtabAdd("ключ2", "значение2");
41+
hashtabAdd("ключ3", "значение3");
42+
hashtabAdd("ключ4", "значение4");
43+
hashtabAdd("ключ5", "значение5");
44+
hashtabAdd("ключ6", "значение6");
45+
hashtabAdd("ключ7", "значение7");
46+
hashtabAdd("ключ8", "значение8");
47+
hashtabAdd("ключ9", "значение9");
48+
hashtabAdd("ключ10", "значение10");
49+
50+
System.out.println("Поиск ключа 'ключ3'..: " + hashtabLookup("ключ3"));
51+
52+
hashtabDelete("ключ3");
53+
System.out.println("После удаления ключа 'ключ3': " + hashtabLookup("ключ3"));
54+
}
55+
}
56+
//Upd
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ru.mirea.practice.s0000001.n2;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public final class Ttest {
7+
private static final int SIZE = 10;
8+
private static Map<Integer, String> hTable;
9+
10+
private Ttest() {
11+
}
12+
13+
public static int hashtabHash(String key) {
14+
return Math.abs(key.hashCode() % SIZE);
15+
}
16+
17+
public static void hashtabInit() {
18+
hTable = new HashMap<>();
19+
}
20+
21+
public static void hashtabAdd(String key, String value) {
22+
int idx = hashtabHash(key);
23+
hTable.put(idx, value);
24+
}
25+
26+
public static String hashtabLookup(String key) {
27+
int idx = hashtabHash(key);
28+
return hTable.get(idx);
29+
}
30+
31+
public static void hashtabDelete(String key) {
32+
int idx = hashtabHash(key);
33+
hTable.remove(idx);
34+
}
35+
36+
public static void main(String[] args) {
37+
hashtabInit();
38+
39+
hashtabAdd("ключ1", "мангоо");
40+
hashtabAdd("ключ2", "манго");
41+
hashtabAdd("ключ3", "манго13");
42+
hashtabAdd("ключ4", "манго14");
43+
hashtabAdd("ключ5", "манго15");
44+
hashtabAdd("ключ6", "манго16");
45+
hashtabAdd("ключ7", "манго17");
46+
hashtabAdd("ключ8", "манго18");
47+
hashtabAdd("ключ9", "манго19");
48+
hashtabAdd("ключ10", "манго20");
49+
50+
System.out.println("Словарь после добавления элементов:");
51+
for (Map.Entry<Integer, String> entry : hTable.entrySet()) {
52+
System.out.println("Ключ: " + entry.getKey() + ", Значение: " + entry.getValue());
53+
}
54+
}
55+
}
56+
//Upd

0 commit comments

Comments
 (0)