-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueueList.java
119 lines (107 loc) · 3.5 KB
/
QueueList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package lab1;
import java.util.*;
public class QueueList extends ParamList {
public static void main(String[] args)
{
Deque<ParamList> list = new LinkedList<>();
list.push(new ParamList<>(32));
list.push(new ParamList<>("catherine"));
list.push(new ParamList<>(45));
list.push(new ParamList<>("cathere"));
list.push(new ParamList<>(38));
list.push(new ParamList<>(39));
list.push(new ParamList<>("carine"));
list.push(new ParamList<>(352));
list.push(new ParamList<>("caterine"));
list.push(new ParamList<>(302));
list.push(new ParamList<>("cathrine"));
list.push(new ParamList<>(320));
print(list,1);
avg(list);
print(list,2);
Scanner sc = new Scanner(System.in);
int rey = sc.nextInt();
delKey(list, rey);
print(list,3);
refresh(list);
}
public static Deque<ParamList> refresh(Deque<ParamList> arr)
{
ArrayList<Integer> count = new ArrayList<>();
Iterator<ParamList> it = arr.iterator();
while (it.hasNext()) {
String z = it.next().toString();
char[] how = z.toCharArray();
p(how.length);
count.add(how.length);
}
int min = Collections.min(count);
p("Minimum is "+min);
Deque<ParamList> arr1 = new LinkedList<>();
Iterator<ParamList> it1 = arr.iterator();
while (it1.hasNext()) {
String z = it1.next().toString();
char[] how = z.toCharArray();
char[] how2 = new char[how.length-min];
for (int i = 0; i<how2.length;i++) {
how2[i] = how[i];
}
String k = new String(how2);
arr1.offerLast(new ParamList<>(k));
}
print(arr1, 4);
return arr1;
}
public static Deque<ParamList> delKey(Deque<ParamList> arr, int n)
{
ArrayList<ParamList> list = arrayIt(arr);
list.remove(n);
for (int i=0; i<list.size(); i++)
{
arr.offerLast(list.get(i));
}
return arr;
}
public static ArrayList<ParamList> arrayIt(Deque<ParamList> arr)
{
ArrayList<ParamList> list = new ArrayList<>();
Iterator<ParamList> it = arr.iterator();
while (it.hasNext()) {
list.add(it.next());
it.remove();
}
return list;
}
public static void print(Deque<ParamList> arr, int x)
{
p("Task "+x);
Iterator<ParamList> it = arr.iterator();
while (it.hasNext())
p(it.next());
}
public static Deque<ParamList> avg(Deque<ParamList> arr)
{
int sum = 0;
int count = 0;
Iterator<ParamList> it = arr.iterator();
while (it.hasNext())
{
String z = it.next().toString();
char[] how = z.toCharArray();
sum+=how.length;
count++;
}
arr.push(new ParamList<>(sum/count));
p("Количество символов: "+sum+", количество объектов: "+count);
return arr;
}
public static void p(Object o)
{
System.out.println(o.toString());
}
@Override
public String toString() {
if ((this.str instanceof Integer)||(this.str instanceof Double)) return String.valueOf(str);
return (String) str;
}
}