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

Commit 44c31f5

Browse files
authored
Merge pull request #609 from ImSpaceLover/features/lab26
Лабораторная №26
2 parents d13dab3 + 5287b49 commit 44c31f5

File tree

7 files changed

+144
-0
lines changed

7 files changed

+144
-0
lines changed

students/23K0120/23K0120-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: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>23K0120</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0120-p26</artifactId>
12+
<description>Collections</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.s23k0120;
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ru.mirea.practice.s23k0120.task1;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Stack;
6+
7+
public abstract class Main {
8+
public static <E> List<E> reverse(List<E> list) {
9+
Stack<E> stack = new Stack<>();
10+
int i = 0;
11+
while (i < list.size() / 2) {
12+
stack.push(list.get(i));
13+
stack.push(list.get(list.size() - i - 1));
14+
list.set(i, stack.pop());
15+
list.set(list.size() - i - 1, stack.pop());
16+
i++;
17+
}
18+
return list;
19+
}
20+
21+
public static void main(String[] args) {
22+
ArrayList<Integer> integers = new ArrayList<>(List.of(new Integer[]{1, 2, 3, 4, 5, 6}));
23+
System.out.println(integers);
24+
reverse(integers);
25+
System.out.println(integers);
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ru.mirea.practice.s23k0120.task2and3;
2+
3+
import java.util.Iterator;
4+
5+
public class CustomIterator<T> implements Iterator<T> {
6+
Node<T> cursor;
7+
8+
CustomIterator(CustomList<T> list) {
9+
cursor = list.getFirst();
10+
}
11+
12+
public boolean hasNext() {
13+
return cursor.getNext() != null;
14+
}
15+
16+
public T next() {
17+
cursor = cursor.getNext();
18+
return cursor.getData();
19+
}
20+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package ru.mirea.practice.s23k0120.task2and3;
2+
3+
import java.util.Iterator;
4+
5+
public class CustomList<T> implements Iterable<T> {
6+
private Node<T> first;
7+
private final int size;
8+
9+
public CustomList() {
10+
first = null;
11+
size = 0;
12+
}
13+
14+
public int getSize() {
15+
return size;
16+
}
17+
18+
public Node<T> getFirst() {
19+
return first;
20+
}
21+
22+
public void add(T elem) {
23+
Node<T> node = new Node<>(elem);
24+
if (first == null) {
25+
first = node;
26+
} else {
27+
Node<T> curr = first;
28+
while (curr.getNext() != null) {
29+
curr = curr.getNext();
30+
}
31+
curr.setNext(node);
32+
}
33+
}
34+
35+
@Override
36+
public Iterator<T> iterator() {
37+
return new CustomIterator<>(this);
38+
}
39+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ru.mirea.practice.s23k0120.task2and3;
2+
3+
public class Node<T> {
4+
private T data;
5+
private Node<T> next;
6+
7+
public Node(T data) {
8+
this.data = data;
9+
next = null;
10+
}
11+
12+
public T getData() {
13+
return data;
14+
}
15+
16+
public void setData(T data) {
17+
this.data = data;
18+
}
19+
20+
public Node<T> getNext() {
21+
return next;
22+
}
23+
24+
public void setNext(Node<T> next) {
25+
this.next = next;
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return data.toString();
31+
}
32+
}

students/23K0120/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@
3939
<module>23K0120-p23</module>
4040
<module>23K0120-p24</module>
4141
<module>23K0120-p25</module>
42+
<module>23K0120-p26</module>
4243
</modules>
4344
</project>

0 commit comments

Comments
 (0)