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

Hey could I get some help in this please. Its in Java. Thank you, what i have al

ID: 3668694 • Letter: H

Question

Hey could I get some help in this please. Its in Java. Thank you, what i have already is post underneath the question

Objective: Yes, the data structures you may have agonized over is actually already implemented in java, but now you know the details behind each of them. Write a program that does the following: Create and populate an ArrayList of integers with 10 to 20 numbers where each number could be between 0-99. Then print that out. Sort the ArrayList in ascending order either by writing QuickSort or MergeSort. You may NOT use the collections sort. Write it yourself. Then print that out. Populate a Queue with the ArrayList, and then dequeue each element and print it out until the queue is empty. Populate a Stack with the ArrayList, and then pop each element and print it out until the stack is empty. Do this process 3 times. Notes: Make sure to use import.util.*; Queues have a different kind of constructor from the rest Queue q = new LinkedList(); Here is the documentation links for reference ArrayList https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html Queue https://docs.oracle.com/javase/7/docs/api/java/util/Queue.html Stack https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html Example: Populating the Array List of Size 12 This list contains 86 15 7 36 50 32 60 88 0 63 92 59 Sorting Printing Sorted Numbers 0 7 15 32 36 50 59 60 63 86 88 92 Adding elements in the list to a queue Removing and Printing each element from the Queue 0 7 15 32 36 50 59 60 63 86 88 92 Adding elements in the list to a stack Removing and printing each element from the Stack 92 88 86 63 60 59 50 36 32 15 7 0 Populating the Array List of Size 11 This list contains 36 6 36 66 98 12 15 48 53 33 14 Sorting Printing Sorted Numbers 6 12 14 15 33 36 36 48 53 66 98 Adding elements in the list to a queue Removing and Printing each element from the Queue 6 12 14 15 33 36 36 48 53 66 98 Adding elements in the list to a stack Removing and printing each element from the Stack 98 66 53 48 36 36 33 15 14 12 6 Populating the Array List of Size 18 This list contains 27 5 70 48 35 39 14 16 59 94 21 73 83 78 32 97 60 4 Sorting Printing Sorted Numbers 4 5 14 16 21 27 32 35 39 48 59 60 70 73 78 83 94 97 Adding elements in the list to a queue Removing and Printing each element from the Queue 4 5 14 16 21 27 32 35 39 48 59 60 70 73 78 83 94 97 Adding elements in the list to a stack Removing and printing each element from the Stack 97 94 83 78 73 70 60 59 48 39 35 32 27 21 16 14 5 4 This is what I have

import java.util.Random; import java.util.ArrayList; import java.util.*; public class BuiltInDataStructures { public static void main(String[] args) { // TODO Auto-generated method stub ArrayListarrList1=new ArrayList(); ArrayListarrList2=new ArrayList(); ArrayList arrList=new ArrayList(); BuiltInDataStructures ms=new BuiltInDataStructures(arrList); arrList.add(43); arrList.add(32); arrList.add(12); arrList.add(20); arrList.add(39); arrList.add(17); arrList.add(24); arrList.add(71); arrList.add(66); arrList.add(87); arrList.add(99); System.out.println("Populating the Array List of Size" +" This list contains"); for(int i=0;i look up global counter } }

Explanation / Answer

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;


public class ArrayListUserDefined {
    static Random r = new Random();
   
    public static ArrayList<Integer> sort(ArrayList<Integer> list) {
        if (list.size() <= 1)
            return list;
       int rotationplacement = r.nextInt(list.size());
        int rotation = list.get(rotationplacement);
        list.remove(rotationplacement);
        ArrayList<Integer> lower = new ArrayList<Integer>();
        ArrayList<Integer> higher = new ArrayList<Integer>();
        for (int num : list)
            if (num <= rotation)
                lower.add(num);
            else
                higher.add(num);
        sort(lower);
        sort(higher);

        list.clear();
        list.addAll(lower);
        list.add(rotation);
        list.addAll(higher);
        return list;
    }
   
   
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
System.out.println("Enter size of the arrayList......");
        int size=sc.nextInt();
        ArrayList al=new ArrayList<>();
       
       
        for (int i = 0; i < size; i++) {
        al.add(sc.nextInt());           
        }

        System.out.println("Before sorting ");
       
        for (int i = 0; i < size; i++) {
System.out.println(al.get(i));
        }

        ArrayList al2=sort(al);
        System.out.println("After sorting ");
        for (int i = 0; i < size; i++) {
System.out.println(al2.get(i));
        }
       
       
       
   
        Stack st=new Stack<>();
        Queue que=new LinkedList<>();
   
        System.out.println("This is the queue implementation...........");
        for (int i = 0; i < al.size(); i++) {
            que.add(al2.get(i));
        }
       
        for (int i = 0; i < que.size(); i++) {
        System.out.println(que.remove());
        }
       

        System.out.println("This is the STACK implementation...........");
       
        for (int i = 0; i < al.size(); i++) {
            st.add(al2.get(i));
        }
       
       
        for (int i = 0; i < st.size(); i++) {
        System.out.println(st.pop());
        }
       
       
       
       
    }

}