Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////////// Student Class
- public class Student implements Comparable<Student>{
- private final int id;
- private final String name;
- public Student(int i, String n){
- id=i;
- name=n;
- }
- public int getId(){
- return id;
- }
- public String getName(){
- return name;
- }
- @Override
- public int compareTo(Student s){
- if (id>s.getId()){
- return 1;
- } else if (id<s.getId()){
- return -1;
- } else {
- return 0;
- }
- }
- @Override
- public String toString(){
- return id+" "+name;
- }
- }
- ///////////////////////////////////////////////////////////////////////////////Test Class
- public class testClass {
- public static void main(String[] args){
- SortedQueue<Student> mSQ=new LinkedListSortedQueue();
- mSQ.insert(new Student(2, "q"));
- mSQ.insert(new Student(4, "w"));
- mSQ.insert(new Student(1, "d"));
- mSQ.insert(new Student(3, "j"));
- mSQ.insert(new Student(5, "o"));
- System.out.println("Size: "+mSQ.getSize()+"\n"+mSQ+"\n");
- while (mSQ.getSize()>0){
- try{
- System.out.println(mSQ.dequeue());
- } catch (Exception ex){
- }
- }
- try{
- System.out.println(mSQ.dequeue());
- } catch (Exception ex){
- System.out.println(ex.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment