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

Changes26-29(1) #688

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions students/23K0565/23K0565-p26/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0565</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0565-p26</artifactId>
<description>26 практическая</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.mirea.practice.s0000001.n1;

import java.util.Stack;

public final class InvertArray {
private InvertArray() {
}

public static int[] invert(int[] arr) {
Stack<Integer> stack = new Stack<>();
for (int num : arr) {
stack.push(num);
}

for (int i = 0; i < arr.length; i++) {
arr[i] = stack.pop();
}

return arr;
}

public static void main(String[] args) {
int[] data = {1, 2, 3, 4, 5};
data = invert(data);
for (int num : data) {
System.out.print(num + " ");
}
}
}
//Upd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.mirea.practice.s0000001.n2;

import java.util.Iterator;
import java.util.List;

public class CusIterator<T> implements Iterator<T> {
private List<T> lst;
private int idx;

public CusIterator(List<T> lst) {
this.lst = lst;
this.idx = 0;
}

@Override
public boolean hasNext() {
return idx < lst.size();
}

@Override
public T next() {
return lst.get(idx++);
}
}
//Upd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.mirea.practice.s0000001.n2;

import java.util.ArrayList;
import java.util.List;

public final class ListD {
private ListD() {
}

public static void main(String[] args) {
List<Integer> nums = new ArrayList<>();
nums.add(10);
nums.add(20);
nums.add(30);

CusIterator<Integer> iter = new CusIterator<>(nums);

while (iter.hasNext()) {
System.out.println(iter.next());
}
}
}
//Upd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ru.mirea.practice.s0000001.n3;

import java.util.Iterator;

public class CusIterator<T> implements Iterator<T> {
private CusList<T> lst;
private int idx;

public CusIterator(CusList<T> lst) {
this.lst = lst;
this.idx = 0;
}

@Override
public boolean hasNext() {
return idx < lst.size();
}

@Override
public T next() {
return lst.get(idx++);
}
}
//Upd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ru.mirea.practice.s0000001.n3;

import java.util.Iterator;

public class CusList<T> implements Iterable<T> {
private Object[] elements;
private int size;

public CusList(int capacity) {
elements = new Object[capacity];
size = 0;
}

public void add(T item) {
if (size < elements.length) {
elements[size++] = item;
} else {
throw new IndexOutOfBoundsException("Список заполнен(");
}
}

public T get(int index) {
if (index >= 0 && index < size) {
return (T) elements[index];
} else {
throw new IndexOutOfBoundsException("Некорректный индекс:(");
}
}

public int size() {
return size;
}

@Override
public Iterator<T> iterator() {
return new CusIterator<>(this);
}
}
//Upd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.mirea.practice.s0000001.n3;

public final class ListDemo {
private ListDemo() {
}

public static void main(String[] args) {
CusList<Integer> nums = new CusList<>(5);
nums.add(10);
nums.add(20);
nums.add(30);

for (int num : nums) {
System.out.println(num);
}
}
}
//Upd
13 changes: 13 additions & 0 deletions students/23K0565/23K0565-p27/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>23K0565</artifactId>
<groupId>ru.mirea.practice</groupId>
<version>2024.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>23K0565-p27</artifactId>
<description>27 практическая</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.mirea.practice.s0000001.n1;

import java.util.HashMap;
import java.util.Map;

public final class Hashtab {
private static final int SIZE = 10;
private static Map<Integer, String> hTable;

private Hashtab() {
}

public static int hashtabHash(String key) {
return Math.abs(key.hashCode() % SIZE);
}

public static void hashtabInit() {
hTable = new HashMap<>();
}

public static void hashtabAdd(String key, String value) {
int idx = hashtabHash(key);
hTable.put(idx, value);
}

public static String hashtabLookup(String key) {
int idx = hashtabHash(key);
return hTable.get(idx);
}

public static void hashtabDelete(String key) {
int idx = hashtabHash(key);
hTable.remove(idx);
}

public static void main(String[] args) {
hashtabInit();

hashtabAdd("ключ1", "значение1");
hashtabAdd("ключ2", "значение2");
hashtabAdd("ключ3", "значение3");
hashtabAdd("ключ4", "значение4");
hashtabAdd("ключ5", "значение5");
hashtabAdd("ключ6", "значение6");
hashtabAdd("ключ7", "значение7");
hashtabAdd("ключ8", "значение8");
hashtabAdd("ключ9", "значение9");
hashtabAdd("ключ10", "значение10");

System.out.println("Поиск ключа 'ключ3'..: " + hashtabLookup("ключ3"));

hashtabDelete("ключ3");
System.out.println("После удаления ключа 'ключ3': " + hashtabLookup("ключ3"));
}
}
//Upd
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package ru.mirea.practice.s0000001.n2;

import java.util.HashMap;
import java.util.Map;

public final class Ttest {
private static final int SIZE = 10;
private static Map<Integer, String> hTable;

private Ttest() {
}

public static int hashtabHash(String key) {
return Math.abs(key.hashCode() % SIZE);
}

public static void hashtabInit() {
hTable = new HashMap<>();
}

public static void hashtabAdd(String key, String value) {
int idx = hashtabHash(key);
hTable.put(idx, value);
}

public static String hashtabLookup(String key) {
int idx = hashtabHash(key);
return hTable.get(idx);
}

public static void hashtabDelete(String key) {
int idx = hashtabHash(key);
hTable.remove(idx);
}

public static void main(String[] args) {
hashtabInit();

hashtabAdd("ключ1", "мангоо");
hashtabAdd("ключ2", "манго");
hashtabAdd("ключ3", "манго13");
hashtabAdd("ключ4", "манго14");
hashtabAdd("ключ5", "манго15");
hashtabAdd("ключ6", "манго16");
hashtabAdd("ключ7", "манго17");
hashtabAdd("ключ8", "манго18");
hashtabAdd("ключ9", "манго19");
hashtabAdd("ключ10", "манго20");

System.out.println("Словарь после добавления элементов:");
for (Map.Entry<Integer, String> entry : hTable.entrySet()) {
System.out.println("Ключ: " + entry.getKey() + ", Значение: " + entry.getValue());
}
}
}
//Upd
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package ru.mirea.practice.s0000001.n3;

import java.util.HashMap;
import java.util.Map;

public final class Dem {
private static final int SIZE = 10;
private static Map<Integer, String> hTable;

private Dem() {
}

public static int hashtabHash(String key) {
return Math.abs(key.hashCode() % SIZE);
}

public static void hashtabInit() {
hTable = new HashMap<>();
}

public static void hashtabAdd(String key, String value) {
int idx = hashtabHash(key);
hTable.put(idx, value);
}

public static String hashtabLookup(String key) {
int idx = hashtabHash(key);
return hTable.get(idx);
}

public static void hashtabDelete(String key) {
int idx = hashtabHash(key);
hTable.remove(idx);
}

public static void main(String[] args) {
hashtabInit();

hashtabAdd("ключ1", "мангоо");
hashtabAdd("ключ2", "манго");
hashtabAdd("ключ3", "манго13");
hashtabAdd("ключ4", "манго14");
hashtabAdd("ключ5", "манго15");
hashtabAdd("ключ6", "манго16");
hashtabAdd("ключ7", "манго17");
hashtabAdd("ключ8", "манго18");
hashtabAdd("ключ9", "манго19");
hashtabAdd("ключ10", "манго20");

System.out.println("Словарь после добавления элементов:");
for (Map.Entry<Integer, String> entry : hTable.entrySet()) {
System.out.println("Ключ: " + entry.getKey() + ", Значение: " + entry.getValue());
}

String searchKey = "ключ5";
System.out.println("\nПоиск значения по ключу '" + searchKey + "': " + hashtabLookup(searchKey));

hashtabDelete(searchKey);
System.out.println("\nСловарь после удаления ключа: '" + searchKey + "':");
for (Map.Entry<Integer, String> entry : hTable.entrySet()) {
System.out.println("Ключ: " + entry.getKey() + ", Значение: " + entry.getValue());
}
}
}
//Upd
Loading
Loading