import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ int n = scanner.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = scanner.nextInt(); Arrays.sort(a); for (int i : a) System.out.print(i+" "); } } }
import java.util.Scanner; public class Main{
// 排序public static void sort(int[] data) {// 插入排序for (int i = 1; i < data.length; i++) {int j = i;int target = data[i];while (j > 0 && target < data[j - 1]) {data[j] = data[j - 1];j--;}data[j] = target;}}// 执行插入public static void insert(Node head, int[] data) {head.item = data[0];Node current = head;for (int i = 1; i < data.length; i++) {current.next = new Node(data[i]);current = current.next;}current.next = null;}// 循环遍历public static void travel(Node head) {for (Node first = head; first != null; first = first.next) {System.out.print(first.item + " ");}System.out.println();}public static void main(String[] args) {Scanner input = new Scanner(System.in);while (input.hasNext()) {int N = input.nextInt();int[] array = new int[N];for (int i = 0; i < N; i++) {array[i] = input.nextInt();}sort(array);Node head = new Node();insert(head, array);travel(head);}}}class Node {Integer item;Node next;public Node() {}public Node(Integer item) {this.item = item;}}
//求告知哪里错了。 import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); while(input.hasNextInt()){ int n = input.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = input.nextInt(); } Arrays.sort(arr); traverseList(createList(arr)); } } static Node createList(int[] arr) { Node n0 = new Node(arr[0]); Node end = n0; for (int i = 1; i < arr.length; i++) { Node temp = new Node(arr[i]); end.next = temp; end = temp; } return n0; } static void traverseList(Node head) { while (head != null) { System.out.print(head.value + " "); head = head.next; } } } class Node { Node(int value) { this.value = value; } int value; Node next; }