Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Second {
- static class DLLNode{
- public String ID;
- public int plata;
- public DLLNode next;
- public DLLNode prev;
- public DLLNode(String ID, int plata){
- this.ID = ID;
- this.plata = plata;
- this.next = null;
- this.prev = null;
- }
- }
- static class DLL{
- public DLLNode head;
- public DLLNode tail;
- public DLL(){
- this.head = null;
- this.tail = null;
- }
- public void sortInsert(String ID, int plata){
- DLLNode newNode = new DLLNode(ID, plata);
- if(this.head == null){
- head = newNode;
- } else {
- DLLNode current = head;
- while(current.plata > plata && current.next == null){
- current = current.next;
- }
- current.prev.next = newNode;
- newNode.prev = current.prev;
- newNode.next = current;
- current.prev = newNode;
- }
- }
- public void cuttOffPayment(int minPlata){
- DLLNode curr = head;
- while(curr != null){
- if(curr.plata < minPlata){
- deleteNode(curr);
- }
- curr = curr.next;
- }
- }
- private void deleteNode(DLLNode node){
- DLLNode curr = head;
- while(curr.next != node){
- curr = curr.next;
- }
- curr.next.next.prev = curr;
- curr.next = curr.next.next;
- }
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement