Untitled
plain_text
16 days ago
1.3 kB
1
Indexable
Never
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.nextLine(); PriorityQueue<Node> numbers = new PriorityQueue<>(); for (int i = 0; i < n; i++) { numbers.add(new Node(i, scanner.nextInt())); } System.out.println(numbers); } public static class Node implements Comparable<Node>{ private final int index; private int value; public Node(int index) { this.index = index; } public Node(int index, int value) { this.index = index; this.value = value; } public int getIndex() { return index; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } @Override public int compareTo(Node o) { return Integer.compare(Math.abs(this.getValue()), Math.abs(o.getValue())); } @Override public String toString() { return "Node{" + "index=" + index + ", value=" + value + '}'; } } }