Question

J'ai essayé d'obtenir bulle trier une liste double lien, et je l'ai lu sur Internet pour le faire fonctionner avec une seule liste chaînée serait plus facile, donc j'ai essayé, et voici mon code

public void bubbleSort()
    {
        StudentNode n;
        boolean isSorted=false;

        for(int i=lenght-1; i>1 && isSorted==false; i--)
        {            
            for(int j=0; j<i; j++)
            {
                n=L.head;
                isSorted=true;
                for(int k=0; k n.next.data)
                {
                    isSorted=false;
                    swap(n, n.next);
                }
            }
        }
    }

    public void swap(StudentNode N1, StudentNode N2)
    {
        int temp=N1.data;
        N1.data=N2.data;
        N2.data=temp;

    }

Comment puis-je changer au travail avec une double liste liée?

Était-ce utile?

La solution

From your implementation point of view, it really doesn't matter whether it's doubly linked list or not, for the sorting(bubbling) part at least as you are simply changing the content instead of pointers.

Autres conseils

If you only change the content (data) of each node, and don't move the nodes themselves, I don't see any reason to change anything.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top