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

Commit 5760c99

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents d97b03a + 8eb34dd commit 5760c99

File tree

100 files changed

+2139
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2139
-36
lines changed

.egitorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# http://editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 4
12+
13+
# We recommend you to keep these unchanged
14+
end_of_line = lf
15+
charset = utf-8
16+
trim_trailing_whitespace = true
17+
insert_final_newline = true
18+
19+
[*.md]
20+
trim_trailing_whitespace = false

.github/workflows/label.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<module>students/23K0130</module>
6969
<module>students/23K0164</module>
7070
<module>students/23K0140</module>
71+
<module>students/23K0505</module>
7172
<module>students/23K0359</module>
7273
<module>students/23K0688</module>
7374
<module>students/23K0145</module>

students/23K0112/23K0112-p010/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>23K0112</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0112-p010</artifactId>
12+
<description>Стандартные интерфейсы Джава</description>
13+
</project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ru.mirea.practice.s26k0112;
2+
3+
import java.util.Comparator;
4+
5+
public final class Main {
6+
private Main() {
7+
8+
}
9+
10+
public static void main(String[] args) {
11+
SortingStudentsByGpa sorter = new SortingStudentsByGpa();
12+
13+
Student[] studentsArray = new Student[]{new Student("Alice","Physics", 2,"KV1",
14+
3.5), new Student("Bob","Mathematics", 3,"KV2", 4.7), new Student("Rain",
15+
"Biology", 1,"KV0", 3.9), new Student("Fon","Computer Science", 4,
16+
"KV10", 4.9)};
17+
18+
sorter.setArray(studentsArray);
19+
20+
Comparator<Student> gpaComparator = Comparator.comparingDouble(Student::getGpa).reversed();
21+
22+
sorter.quicksort(gpaComparator);
23+
24+
System.out.println("Sorted by GPA using Quick Sort:");
25+
sorter.outArray();
26+
27+
sorter.setArray(studentsArray);
28+
29+
sorter.mergeSort(gpaComparator);
30+
31+
System.out.println("\nSorted by GPA using Merge Sort:");
32+
sorter.outArray();
33+
34+
}
35+
}
36+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package ru.mirea.practice.s26k0112;
2+
3+
import java.util.Comparator;
4+
5+
public class SortingStudentsByGpa {
6+
private Student[] students;
7+
8+
public void setArray(Student[] students) {
9+
this.students = students;
10+
}
11+
12+
public void quicksort(Comparator<Student> comparator) {
13+
quicksort(students, 0, students.length - 1, comparator);
14+
}
15+
16+
private void quicksort(Student[] array, int low, int high, Comparator<Student> comparator) {
17+
if (low < high) {
18+
int pi = partition(array, low, high, comparator);
19+
quicksort(array, low, pi - 1, comparator);
20+
quicksort(array, pi + 1, high, comparator);
21+
}
22+
}
23+
24+
private int partition(Student[] array, int low, int high, Comparator<Student> comparator) {
25+
Student pivot = array[high];
26+
int i = low - 1;
27+
for (int j = low; j < high; j++) {
28+
if (comparator.compare(array[j], pivot) > 0) {
29+
i++;
30+
swap(array, i, j);
31+
}
32+
}
33+
swap(array, i + 1, high);
34+
return i + 1;
35+
}
36+
37+
private void swap(Student[] array, int i, int j) {
38+
Student temp = array[i];
39+
array[i] = array[j];
40+
array[j] = temp;
41+
}
42+
43+
public void mergeSort(Comparator<Student> comparator) {
44+
mergeSort(students, 0, students.length - 1, comparator);
45+
}
46+
47+
private void mergeSort(Student[] array, int left, int right, Comparator<Student> comparator) {
48+
if (left < right) {
49+
int mid = (left + right) / 2;
50+
mergeSort(array, left, mid, comparator);
51+
mergeSort(array, mid + 1, right, comparator);
52+
merge(array, left, mid, right, comparator);
53+
}
54+
}
55+
56+
private void merge(Student[] array, int left, int mid, int right, Comparator<Student> comparator) {
57+
int n1 = mid - left + 1;
58+
int n2 = right - mid;
59+
60+
Student[] l = new Student[n1];
61+
Student[] r = new Student[n2];
62+
63+
System.arraycopy(array, left, l, 0, n1);
64+
System.arraycopy(array, mid + 1, r, 0, n2);
65+
66+
int i = 0;
67+
int j = 0;
68+
int k = left;
69+
70+
while (i < n1 && j < n2) {
71+
if (comparator.compare(l[i], r[j]) >= 0) {
72+
array[k++] = l[i++];
73+
} else {
74+
array[k++] = r[j++];
75+
}
76+
}
77+
78+
while (i < n1) {
79+
array[k++] = l[i++];
80+
}
81+
82+
while (j < n2) {
83+
array[k++] = r[j++];
84+
}
85+
}
86+
87+
public void outArray() {
88+
for (Student student : students) {
89+
System.out.println(student);
90+
}
91+
}
92+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package ru.mirea.practice.s26k0112;
2+
3+
public class Student {
4+
private String name;
5+
private String major;
6+
private int year;
7+
private String group;
8+
private final double gpa;
9+
10+
public Student(String name, String major, int year, String group, double gpa) {
11+
this.name = name;
12+
this.major = major;
13+
this.year = year;
14+
this.group = group;
15+
this.gpa = gpa;
16+
}
17+
18+
public String getName() {
19+
return name;
20+
}
21+
22+
public String getMajor() {
23+
return major;
24+
}
25+
26+
public double getGpa() {
27+
return gpa;
28+
}
29+
30+
public void setMajor(String major) {
31+
this.major = major;
32+
}
33+
34+
public int getYear() {
35+
return year;
36+
}
37+
38+
public void setYear(int year) {
39+
this.year = year;
40+
}
41+
42+
public String getGroup() {
43+
return group;
44+
}
45+
46+
public void setGroup(String group) {
47+
this.group = group;
48+
}
49+
50+
51+
@Override
52+
public String toString() {
53+
return "Student{" + "Name='" + name + '\'' + ", major='" + major + '\'' + ", year=" + year
54+
+ ", group='" + group + '\'' + ", GPA='" + gpa + '\'' + '}';
55+
}
56+
}

students/23K0112/23K0112-p05/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>23K0112</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23K0112-p05</artifactId>
12+
<description>Java GUI</description>
13+
</project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package ru.mirea.practice.s24k0112;
2+
3+
import java.awt.Color;
4+
5+
class Circle extends Shape {
6+
public int radius;
7+
8+
public Circle(String name, Color color, int x, int y, int radius) {
9+
super(name, color, x, y);
10+
this.radius = radius;
11+
}
12+
13+
public void setRadius(int newRadius) {
14+
this.radius = newRadius;
15+
}
16+
17+
public int getRadius() {
18+
return radius;
19+
}
20+
21+
22+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ru.mirea.practice.s24k0112;
2+
3+
import java.awt.Color;
4+
5+
class Rectangle extends Shape {
6+
public int width;
7+
public int length;
8+
9+
public Rectangle(String name, Color color, int x, int y, int width, int length) {
10+
super(name, color, x, y);
11+
this.width = width;
12+
this.length = length;
13+
}
14+
15+
public int getLength() {
16+
return length;
17+
}
18+
19+
public int getWidth() {
20+
return width;
21+
}
22+
23+
public void setWidth(int newWidth) {
24+
this.width = newWidth;
25+
}
26+
27+
public void setLength(int newLength) {
28+
this.length = newLength;
29+
}
30+
31+
}

0 commit comments

Comments
 (0)