Skip to main content
added 30 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

They seem right to me. A few minor comments:

  1. You don't need to construct your lists by adding .add(pos, value).add(pos, value). You can build them from an array as:

    int[] array = {6,12,9,-14}; List list = new ArrayList<>(Arrays.asList(array);

     int[] array = {6,12,9,-14};
     List<Integer> list = new ArrayList<>(Arrays.asList(array);
    

which is more concise and readable.

  1. In your bubblesort, you do:

    Integer temp1= unsortedList.get(i + 1); Integer temp2= unsortedList.get(i);

     Integer temp1= unsortedList.get(i + 1);
     Integer temp2= unsortedList.get(i);
    

accessing unsortedListunsortedList twice. If you assign outside the IFif, you can recycle it and make it more readable. Also, consider using better names than temp1temp1 and temp2temp2: not much difference here, but it's a good habit to get into. Same, same for insertion.

They seem right to me. A few minor comments:

  1. You don't need to construct your lists by adding .add(pos, value). You can build them from an array as:

    int[] array = {6,12,9,-14}; List list = new ArrayList<>(Arrays.asList(array);

which is more concise and readable.

  1. In your bubblesort, you do:

    Integer temp1= unsortedList.get(i + 1); Integer temp2= unsortedList.get(i);

accessing unsortedList twice. If you assign outside the IF, you can recycle it and make it more readable. Also, consider using better names than temp1 and temp2: not much difference here, but it's a good habit to get into. Same for insertion.

They seem right to me. A few minor comments:

  1. You don't need to construct your lists by adding .add(pos, value). You can build them from an array as:

     int[] array = {6,12,9,-14};
     List<Integer> list = new ArrayList<>(Arrays.asList(array);
    

which is more concise and readable.

  1. In your bubblesort, you do:

     Integer temp1= unsortedList.get(i + 1);
     Integer temp2= unsortedList.get(i);
    

accessing unsortedList twice. If you assign outside the if, you can recycle it and make it more readable. Also, consider using better names than temp1 and temp2: not much difference here, but it's a good habit to get into, same for insertion.

Source Link

They seem right to me. A few minor comments:

  1. You don't need to construct your lists by adding .add(pos, value). You can build them from an array as:

    int[] array = {6,12,9,-14}; List list = new ArrayList<>(Arrays.asList(array);

which is more concise and readable.

  1. In your bubblesort, you do:

    Integer temp1= unsortedList.get(i + 1); Integer temp2= unsortedList.get(i);

accessing unsortedList twice. If you assign outside the IF, you can recycle it and make it more readable. Also, consider using better names than temp1 and temp2: not much difference here, but it's a good habit to get into. Same for insertion.