Complete a sort method in java.

Suppose you have a linked list class that stores integers. The integers can be both negative and positive. Based on the following class definition, give the pseudocode or the Java code for the sort() method, which sorts the list.

 

public class SortedIntegerList { 

    protected static class Node {

        Node next; 

        int value;

 

    }

 

    private Node head;

 

    public SortedIntegerList() { } 

 

    public void append(int value) {

        Node n = new Node(); n.value = value;

        if (head == null) { 

            head = n;

        } else {

            Node tmp = head;

            while (tmp.next != null) { 

                tmp = tmp.next;

 

            }

            tmp.next = n;

        }

 

    }

 

    public void sort() {

        // WRITE YOUR CODE HERE

    }

 

}

Need a custom answer at your budget?

This assignment has been answered 4 times in private sessions.

© 2024 Codify Tutor. All rights reserved