Skip to content
Snippets Groups Projects
Commit 88782ba4 authored by Eckl, Máté's avatar Eckl, Máté
Browse files

4. labor maradék feladatok befejezve

parent 75b7ecd0
No related branches found
No related tags found
No related merge requests found
public class EmptyQueueException extends ArrayIndexOutOfBoundsException{
public EmptyQueueException()
{
super("Üres a sor");
}
public EmptyQueueException(String err)
{
super(err);
}
public EmptyQueueException(int i)
{
super(i);
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public class PQueue <T extends Comparable> implements Iterable<T>{
private ArrayList<T> f = null;
public PQueue() {
f = new ArrayList<>();
}
int size()
{
return f.size();
}
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);
}
T pop()
{
T top = this.top();
f.remove(top);
return top;
}
void clear()
{
f.clear();
}
public Iterator<T> iterator() {
return f.iterator();
}
}
public class Test {
public static void main(String args[])
{
PQueue<String> q=new PQueue<>();
q.push("alma");
q.push("körte");
q.push("kiwi");
for(String s: q)
{
System.out.println(s);
}
System.out.println(q.size());
System.out.println(q.pop());
System.out.println(q.top());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment