Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- class DLLNode<E> {
- protected E ID,plata;
- protected DLLNode<E> next,prev;
- public DLLNode () {
- ID = null;
- plata = null;
- next = null;
- prev = null;
- }
- public DLLNode(E ID, E plata,DLLNode<E> next,DLLNode<E> prev) {
- this.ID = ID;
- this.plata = plata;
- this.next = next;
- this.prev = prev;
- }
- public String toString () {
- return ID + " " + plata + "\n";
- }
- public void setData(E ID , E plata) {
- this.ID=ID;
- this.plata=plata;
- }
- }
- @SuppressWarnings("unchecked")
- class DLL<E> {
- protected DLLNode<E> first,last;
- public DLL () {
- first = null;
- last = null;
- }
- public void insertFirst (E el1,E el2) {
- DLLNode<E> temp = new DLLNode(el1,el2,first,null);
- if(first == null)
- last = temp;
- else
- first.prev = temp;
- first = temp;
- }
- public void insertLast (E el1,E el2) {
- DLLNode<E> temp = new DLLNode(el1,el2,null,first);
- if(first == null)
- first = temp;
- else
- last.next = temp;
- last = temp;
- }
- public String toString() {
- DLLNode<E> temp = first;
- String s = new String ();
- while(temp != null) {
- s += temp.toString();
- temp = temp.next;
- }
- return s;
- }
- }
- public class DLLKompanija {
- public static DLL<Integer> sort (DLL<Integer> lista) {
- DLLNode<Integer> tmp = lista.first;
- while (tmp !=null) {
- DLLNode<Integer> tmp1 = tmp;
- while (tmp1 != null) {
- if (tmp.ID < tmp1.ID) {
- int pom = tmp.ID;
- tmp.ID=tmp1.ID;
- tmp1.ID=pom;
- int pom1 = tmp.plata;
- tmp.plata=tmp1.plata;
- tmp1.plata=pom1;
- }
- tmp1 = tmp1.next;
- }
- tmp = tmp.next;
- }
- return lista;
- }
- public static void fix (DLL<Integer> lista,int limit) {
- DLLNode<Integer> temp = lista.first;
- DLL<Integer> lista1 = new DLL<Integer> ();
- boolean flag = false;
- int k = 0;
- while(temp != null) {
- if(temp.plata >= limit) {
- lista1.insertLast(temp.ID,temp.plata);
- flag = true;
- }
- k++;
- temp = temp.next;
- }
- if(!flag) {
- System.out.print("nema");
- return;
- }
- System.out.println(sort(lista1));
- }
- public static void main (String [] args) {
- DLL <Integer> lista = new DLL<Integer>();
- Scanner in = new Scanner (System.in);
- int n = in.nextInt ();
- int [] ID = new int [n];
- int [] plata = new int [n];
- for(int i=0; i<n; i++) {
- ID[i] = in.nextInt();
- plata[i] = in.nextInt();
- lista.insertLast(ID[i],plata[i]);
- }
- int limit = in.nextInt();
- fix(lista,limit);
- }
- }
Add Comment
Please, Sign In to add comment