Mitrezzz

Компанија

Nov 19th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.74 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. class DLLNode<E> {
  5.     protected E ID,Plata;
  6.     protected DLLNode<E> succ,pred;
  7.     public DLLNode() {
  8.         this.ID=null;
  9.         this.Plata=null;
  10.         this.succ=null;
  11.         this.pred=null;
  12.     }
  13.     public DLLNode (E ID,E Plata, DLLNode<E> succ,DLLNode<E> pred) {
  14.         this.ID=ID;
  15.         this.Plata=Plata;
  16.         this.succ=succ;
  17.         this.pred=pred;
  18.     }
  19.     @Override
  20.     public String toString() {
  21.         return String.format("%s %s",ID.toString(),Plata.toString());
  22.     }
  23.     public void setData(E ID , E Plata) {
  24.         this.ID=ID;
  25.         this.Plata=Plata;
  26.     }
  27.  
  28.  
  29. };
  30.  
  31. class DLL<E extends Comparable <E>> {
  32.     private DLLNode<E> first, last;
  33.     public DLL () {
  34.         //construct empty list
  35.         this.first=null;
  36.         this.last=null;
  37.     }
  38.     public void insertFirst(E o,E o1) {
  39.         DLLNode<E> ins = new DLLNode<E>(o,o1,null,first);
  40.         if(first == null) {
  41.             first=ins;
  42.         } else {
  43.             first.pred=ins;
  44.             first=ins;
  45.         }
  46.  
  47.     }
  48.     public int getSize() {
  49.         int ret;
  50.         if (first != null) {
  51.             DLLNode<E> tmp = first;
  52.             ret = 1;
  53.             while (tmp.succ != null) {
  54.                 tmp = tmp.succ;
  55.                 ret++;
  56.             }
  57.             return ret;
  58.         } else
  59.             return 0;
  60.  
  61.     }
  62.  
  63.     public void insertLast(E o , E o1) {
  64. if (first != null) {
  65.             DLLNode<E> tmp = first;
  66.             while (tmp.succ != null)
  67.                 tmp = tmp.succ;
  68.             DLLNode<E> ins = new DLLNode<E>(o,o1 , last,null);
  69.             tmp.succ = ins;
  70.         } else {
  71.             insertFirst(o,o1);
  72.         }
  73.  
  74.     }
  75.     public DLLNode<E> getFirst() {
  76.         return first;
  77.     }
  78.     public DLLNode<E> getLast() {
  79.         return last;
  80.     }
  81. };
  82. public class DLLKompanija {
  83.     public static DLL<Integer> getGreaterThan(DLL<Integer> list ,int Greater) {
  84.         DLLNode<Integer> tmp = list.getFirst();
  85.         DLL<Integer> list1 = new DLL<Integer>();
  86.         while(tmp!=null) {
  87.             if(tmp.Plata>=Greater) {
  88.                 list1.insertLast(tmp.ID, tmp.Plata);
  89.             }
  90.             tmp=tmp.succ;
  91.         }
  92.  
  93.         return list1;
  94.     }
  95. //@SuppressWarnings("unused")
  96.     public static void sort(DLL<Integer> list) {
  97.         int i = 0;
  98.        if(list.getFirst()==null)
  99.            return;
  100.         DLLNode<Integer> currentNode = list.getFirst();
  101.         DLLNode<Integer> auxNode=new DLLNode<Integer>();
  102.         boolean foundChange =true;
  103.         while(foundChange) {
  104.             if(currentNode.succ==null)
  105.                     break;
  106.             foundChange = false;
  107.             for(i=0; i<list.getSize()-1; i++) {
  108.                 if (currentNode.succ.ID>currentNode.ID) {
  109.                     auxNode.setData(currentNode.ID,currentNode.Plata);
  110.                     currentNode.setData(currentNode.succ.ID,currentNode.succ.Plata);
  111.                     currentNode.succ.setData(auxNode.ID,auxNode.Plata);
  112.                     foundChange = true;
  113.                 }
  114.                
  115.                 if(currentNode.succ!=null)
  116.                 currentNode = currentNode.succ;
  117.             }
  118.  
  119.         }
  120.     }
  121.    
  122.    /* public static void sort(DLL<Integer> list){
  123.        
  124.         for(int i =0;i<list.getSize()-1;i++){
  125.             DLLNode<Integer> temp= list.getFirst();
  126.             for(int j=0;j<list.getSize()-1-i;j++){
  127.                 if(temp.ID < temp.succ.ID ){
  128.                     DLLNode<Integer>tmp=temp;
  129.                     temp=temp.succ;
  130.                     temp.succ=tmp;
  131.                 }
  132.                 temp=temp.succ;
  133.             }
  134.            
  135.         }
  136.        
  137.        
  138.     }
  139.     */
  140.     public static void print(DLL<Integer> list ) {
  141.         DLLNode<Integer> tmp=list.getFirst();
  142.         if (tmp==null){
  143.         System.out.print("nema");
  144.             return;
  145.         }
  146.         while(tmp!=null) {
  147.             System.out.print(tmp.ID+" "+tmp.Plata+"\n");
  148.            
  149.             //;
  150.             tmp=tmp.succ;
  151.         }
  152.  
  153.     }
  154.  
  155.  
  156.     public static void main (String[] args) {
  157.  
  158.         Scanner s = new Scanner(System.in);
  159.         DLL<Integer> list1 = new DLL<Integer>();
  160.         int n = s.nextInt();
  161.         int [] ID = new int [n];
  162.         int [] Plata = new int [n];
  163.         for(int i =0; i<n; i++) {
  164.             ID[i] = s.nextInt();
  165.             Plata[i]=s.nextInt();
  166.             list1.insertLast(ID[i],Plata[i]);
  167.         }
  168.         int plata;
  169.         plata=s.nextInt();
  170.         DLL<Integer> result = new DLL<Integer>();
  171.         result = getGreaterThan(list1,plata);
  172.         //print(result);
  173.        // System.out.println();
  174.         sort(result);
  175.         sort(result);
  176.          sort(result);
  177.          sort(result);
  178.          sort(result);
  179.          sort(result);
  180.         print(result);
  181.  
  182.         s.close();
  183.     }
  184.  
  185.  
  186.  
  187. };
Add Comment
Please, Sign In to add comment