Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: a) Explain each line of code of both codes b) Explain what the both co

ID: 3886718 • Letter: Q

Question

Question:

a) Explain each line of code of both codes

b) Explain what the both codes do overall, like the main purpose of them

BubbleSort.java No Selection LinkedStackOflnts.java No Selection public class BubbleSort public int swapCount- 0 public class LinkedStackOfInts public int size0; public Node first = null; public boolean isEmpty) public LinkedStackofInts bubbleSort (LinkedStackofInts list) i if (list.isEmpty)) System.out.println( "List is empty! "); return null; return first ll; int R = list. size - 2; boolean swapped true; while (R >= 0 && swapped) { nu public void push(int value) f swapped false; LinkedStackOfInts.Node a - list.first; for (int 1-0; 1 1++) { Node oldFirst first; first = new Node(); first.value = value; first.next-oldFirst; size++ LinkedStack0fInts . Node b = a.next; if (a.value > b.value) I swapped = true; swap (a, b)i swapCount++; public class Node t int value; Node next; R=R-1; return list; private void swap (LinkedStackOfInts.Node a, LinkedStackOfInts.Node b) I int temp a . value ; a.value - b.value; b.value temp;

Explanation / Answer

A) Bubble sort is used for sorting algorithm.here we are sorting the LinkedStackOfInts.

here we are checking first if list is empty we returning NULL.
Otherwise we are running 2 loop
1) While outer loop
2) for inner loop

In inner for loop compares the first two elements, and swaps since a.value> b.value
If the List is already sorted, but our algorithm does not know if it is completed so to optimized that we have used swapped flag this helps in stopping the algorithm if inner loop didn’t cause any swap.

B)

LinkedStackOfInts creates a list of integers.
isEmpty function checks if the list is Empty that is when there is no element in the List.

The new node is always added before the front of the given List. And newly added node becomes the new front of the List.

For example if the given Linked List is 2->4->6->7 and we add an item 5 at the front, then the Linked List becomes 5->2->4->6->7.

For adding Integer at the front of the list push(int value) is called.

so in general this program add the element in the front of the linkedlist.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote