Andziev

Компанија

Oct 25th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.15 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class DLLNode<E> {
  5.     protected E ID,plata;
  6.     protected DLLNode<E> next,prev;
  7.  
  8.     public DLLNode () {
  9.         ID = null;
  10.         plata = null;
  11.         next = null;
  12.         prev = null;
  13.     }
  14.     public DLLNode(E ID, E plata,DLLNode<E> next,DLLNode<E> prev) {
  15.         this.ID = ID;
  16.         this.plata = plata;
  17.         this.next = next;
  18.         this.prev = prev;
  19.     }
  20.     public String toString () {
  21.         return ID + " " + plata + "\n";
  22.     }
  23.     public void setData(E ID , E plata) {
  24.         this.ID=ID;
  25.         this.plata=plata;
  26.     }
  27. }
  28.  
  29. @SuppressWarnings("unchecked")
  30. class DLL<E> {
  31.     protected DLLNode<E> first,last;
  32.  
  33.     public DLL () {
  34.         first = null;
  35.         last = null;
  36.     }
  37.     public void insertFirst (E el1,E el2) {
  38.         DLLNode<E> temp = new DLLNode(el1,el2,first,null);
  39.         if(first == null)
  40.             last = temp;
  41.         else
  42.             first.prev = temp;
  43.         first = temp;
  44.     }
  45.     public void insertLast (E el1,E el2) {
  46.         DLLNode<E> temp = new DLLNode(el1,el2,null,first);
  47.         if(first == null)
  48.             first = temp;
  49.         else
  50.             last.next = temp;
  51.         last = temp;
  52.     }
  53.     public String toString() {
  54.         DLLNode<E> temp = first;
  55.         String s = new String ();
  56.         while(temp != null) {
  57.             s += temp.toString();
  58.             temp = temp.next;
  59.         }
  60.         return s;
  61.     }
  62. }
  63.  
  64. public class DLLKompanija {
  65.  
  66.     public static DLL<Integer> sort (DLL<Integer> lista) {
  67.         DLLNode<Integer> tmp = lista.first;
  68.        
  69.         while (tmp !=null) {
  70.             DLLNode<Integer> tmp1 = tmp;
  71.             while (tmp1 != null) {
  72.                 if (tmp.ID < tmp1.ID) {
  73.                     int pom = tmp.ID;
  74.                     tmp.ID=tmp1.ID;
  75.                     tmp1.ID=pom;
  76.  
  77.                     int pom1 = tmp.plata;
  78.                     tmp.plata=tmp1.plata;
  79.                     tmp1.plata=pom1;
  80.  
  81.                 }
  82.                 tmp1 = tmp1.next;
  83.             }
  84.             tmp = tmp.next;
  85.         }
  86.         return lista;
  87.     }
  88.     public static void fix (DLL<Integer> lista,int limit) {
  89.         DLLNode<Integer> temp = lista.first;
  90.         DLL<Integer> lista1 = new DLL<Integer> ();
  91.         boolean flag = false;
  92.         int k = 0;
  93.         while(temp != null) {
  94.             if(temp.plata >= limit) {
  95.                 lista1.insertLast(temp.ID,temp.plata);
  96.                 flag = true;
  97.             }
  98.             k++;
  99.             temp = temp.next;
  100.         }
  101.         if(!flag) {
  102.             System.out.print("nema");
  103.             return;
  104.         }
  105.         System.out.println(sort(lista1));
  106.     }
  107.     public static void main (String [] args) {
  108.         DLL <Integer> lista = new DLL<Integer>();
  109.         Scanner in = new Scanner (System.in);
  110.         int n = in.nextInt ();
  111.         int [] ID = new int [n];
  112.         int [] plata = new int [n];
  113.         for(int i=0; i<n; i++) {
  114.             ID[i] = in.nextInt();
  115.             plata[i] = in.nextInt();
  116.             lista.insertLast(ID[i],plata[i]);
  117.         }
  118.         int limit = in.nextInt();
  119.         fix(lista,limit);
  120.  
  121.     }
  122. }
Add Comment
Please, Sign In to add comment