1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sp2606 [1]
3 years ago
12

2. Write a program that calls creates an ArrayList of integer and calls the method minToFront described below. Print out the lis

t before and after the method call Method minToFront: takes an ArrayList of integers as a parameter. The method moves the minimum value in the list to the front, otherwise preserving the order of the elements. For example, if a variable called list stores the following values: [4, 7, 9, 2, 7, 7, 5, 3, 5, 1, 7, 8, 6, 7] and you make this call: minToFront(list); it should store the following values after the call: [1, 4, 7, 9, 2, 7, 7, 5, 3, 5, 7, 8, 6, 7]. You may assume that the list stores at least one value. After the call print the list.
Computers and Technology
1 answer:
Novosadov [1.4K]3 years ago
3 0

Answer:

import java.util.ArrayList;

public class MinToFront {

   public static void minToFront(ArrayList < Integer > list){

       int miniIndex = 0;

       for(int j=1; j<list.size(); j++){

          if(list.get(miniIndex) > list.get(j))

               miniIndex = j;

      }

      // moving min to front

       int min = list.get(miniIndex);

       list.remove(miniIndex);

       list.add(0, min);

  }

  public static void main(String[] args) {

       ArrayList<Integer> list = new ArrayList<>();

      list.add(4);   //value store in list

      list.add(7);   //value store in list

      list.add(9);  //value store in list

      list.add(2);  //value store in list

      list.add(7);  //value store in list

      list.add(7);  //value store in list

      list.add(5);  //value store in list

       

      list.add(3);  //value store in list

       

      list.add(5);  //value store in list

       

      list.add(1);  //value store in list

       

      list.add(7);  //value store in list

       

      list.add(8);  //value store in list

       

      list.add(6);  //value store in list

       

      list.add(7);  //value store in list

       

      System.out.println(list);

      minToFront(list);

      System.out.println(list);

  }

}

Output:

[1, 4, 7, 9, 2, 7, 7, 5, 3, 5, 7, 8, 6, 7]

Explanation:

Firstly,we define a method minToFront(), than set an integer variable "miniIndex" to 0, than set a for loop and apply the following condition and inside the loop we apply the if condition, set an integer variable "min" in which we store the value and than we set the following list [4, 7, 9, 2, 7, 7, 5, 3, 5, 1, 7, 8, 6, 7], after that print the list and than print an output.

You might be interested in
You would like to enter a formula that subtracts the data in cell B4 from the total of cells B2 and B3. What should the formula
anastassius [24]

Answer:

=b2 b3-b4 or something close to that, I hope this helps ^^

Explanation:

6 0
3 years ago
What risks, threats, and vulnerabilities are prominent with wlan infrastructures?
vovangra [49]
The threats as well as the risk and vulnerabilities are present with the WLAN. The WLAN would encounter security issues with the range of the signal which is wireless, SSID broadcasting, password security and the packet sniffing or the capturing of signal.
4 0
3 years ago
What's your opinion on Pokemon​ and pixeldip
faust18 [17]

Answer:

Its a good game but an amazing show. 10/10

Explanation:

7 0
2 years ago
fill down feature on a formula and you need to keep a cell reference the same which one will allow you to keep the same cell ref
dedylja [7]
A dollar sign after both the letter and the number for each cell reference you want to keep the same will keep it the same when using the fill down/across function.
6 0
3 years ago
Which of the following relate to the term Technology?
sp2606 [1]

Answer:

the answer is D.All of the above

7 0
3 years ago
Read 2 more answers
Other questions:
  • George is a contractor who creates websites and web applications. What is George working as?
    7·2 answers
  • Semiconductor memory is used mainly for primary storage even with its high cost. In another hand, the magnetic tape is the cheap
    9·2 answers
  • You have a large dataset that will print on several pages. You want to ensure that related records print on the same page with c
    11·1 answer
  • True / False
    5·1 answer
  • Why you should care about copyright
    13·1 answer
  • Which of the following Internet protocols is MOST important in reassembling packets and requesting missing packets to form compl
    11·1 answer
  • How to find how much storage is left on pc?
    6·1 answer
  • Random number between 0 and 5 (inclusive)
    10·2 answers
  • What do you do when your computer shuts down
    15·2 answers
  • The cutting tool that has a zig zag edge is called a?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!