I need to write a method that sorts a provided Linked list with bubble sort and...

80.2K

Verified Solution

Question

Programming

I need to write a method that sorts a provided Linked list withbubble sort and using ONLY Java List Iterator Methods (LinkBelow)

https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html  

  public static > void bubbleSort(List c) throws Exception {

    // first line to start you off

    ListIterator iit =c.listIterator(), jit;

    /**** Test code: do not modify*****/

    List cc = new LinkedList(c);

    Collections.sort(c);

    ListIterator it1 = c.listIterator(), it2= cc.listIterator();

while (it1.hasNext()) {

if (!it1.next().equals(it2.next()))

        throw newException(\"List not sorted\");

}

    /***********************************/

  }

Answer & Explanation Solved by verified expert
4.2 Ratings (482 Votes)
Here is the completed code for this method Comments are    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students