Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Prog3 laborok
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gutemadanielhunduma
Prog3 laborok
Commits
8598926f
Commit
8598926f
authored
9 years ago
by
Eckl, Máté
Browse files
Options
Downloads
Patches
Plain Diff
4. labor. Félreértett 6. feladat kijavítva
parent
88782ba4
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
4. labor/PQueue/src/PQueue.java
+11
-2
11 additions, 2 deletions
4. labor/PQueue/src/PQueue.java
4. labor/PQueue/src/ReverseComparator.java
+11
-0
11 additions, 0 deletions
4. labor/PQueue/src/ReverseComparator.java
4. labor/PQueue/src/Test.java
+10
-1
10 additions, 1 deletion
4. labor/PQueue/src/Test.java
with
32 additions
and
3 deletions
4. labor/PQueue/src/PQueue.java
+
11
−
2
View file @
8598926f
/*
In computer science, a priority queue is an abstract data type which is
like a regular queue or stack data structure, but where additionally each element
has a "priority" associated with it. In a priority queue, an element with high priority
is served before an element with low priority. If two elements have the same priority,
they are served according to their order in the queue.
https://en.wikipedia.org/wiki/Priority_queue
*/
import
java.util.ArrayList
;
import
java.util.Collections
;
...
...
@@ -18,14 +27,13 @@ public class PQueue <T extends Comparable> implements Iterable<T>{
void
push
(
T
t
)
{
f
.
add
(
t
);
Collections
.
sort
(
f
);
}
T
top
()
{
if
(
size
()<
1
)
throw
new
EmptyQueueException
(
"Nincs elem a listában"
);
return
f
.
get
(
size
()-
1
);
return
(
T
)
Collections
.
max
(
f
);
}
T
pop
()
...
...
@@ -41,6 +49,7 @@ public class PQueue <T extends Comparable> implements Iterable<T>{
}
public
Iterator
<
T
>
iterator
()
{
Collections
.
sort
(
f
,
new
ReverseComparator
<
T
>());
return
f
.
iterator
();
}
}
This diff is collapsed.
Click to expand it.
4. labor/PQueue/src/ReverseComparator.java
0 → 100644
+
11
−
0
View file @
8598926f
import
java.util.Comparator
;
public
class
ReverseComparator
<
T
extends
Comparable
>
implements
Comparator
<
T
>{
public
int
compare
(
T
t
,
T
t1
)
{
return
-
1
*
t
.
compareTo
(
t1
);
}
}
This diff is collapsed.
Click to expand it.
4. labor/PQueue/src/Test.java
+
10
−
1
View file @
8598926f
...
...
@@ -12,7 +12,16 @@ public class Test {
}
System
.
out
.
println
(
q
.
size
());
System
.
out
.
println
(
q
.
pop
());
System
.
out
.
println
(
q
.
top
());
System
.
out
.
println
(
q
.
pop
());
System
.
out
.
println
(
q
.
pop
());
// System.out.println(q.pop());//exceptiont dobna ami nekünk most jó
PQueue
<
Integer
>
s
=
new
PQueue
<>();
s
.
push
(
1
);
s
.
push
(
2
);
s
.
push
(
3
);
s
.
push
(
4
);
for
(
Integer
i
:
s
)
{
System
.
out
.
println
(
i
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment