Swap elements in LinkedList

前端 未结 7 1778
别那么骄傲
别那么骄傲 2020-12-20 14:32

I want to maintain order of the elements being added in a list. So, I used a LinkedList in Java.

Now I want to be able to swap two elements in the linke

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-20 15:26

     // I tried to reduce time complexity here, in 3 while loops (get() and set() use 4 while loop)
       void swapAt(int index1, int index2){ // swapping at index
            Node tmp = head;
            int count=0;
            int min, max;   // for future reference to reduce time complexity
            if(index1

提交回复
热议问题