public static Node ordersort(Node head, Node waitforsort) { Node p = head; Node newhead = head; Node temp = waitforsort; while (p.expo < temp.expo) { if (p.next == null) { p.next = temp; return newhead; } if (p.next.expo > temp.expo) { temp.next = p.next; p.next = temp; return newhead; } p = p.next; } if (p.expo == temp.expo) { p.coeff = temp.coeff + p.coeff; return newhead; } if (p.expo > temp.expo) { temp.next = p; newhead = temp; return newhead; } return newhead; }