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
When you _____ a scroll bar, a shortcut menu appears with commands related to the scroll bar
stich3 [128]
I think d is the right answer
8 0
2 years ago
What are two example of ways an electronic record may be distributed to others?
murzikaleks [220]
By email or publishing on the internet, I hope that helps!
4 0
2 years ago
Use the drop-down menus to complete the statements about using section breaks in a document
krok68 [10]

Answer:

layout, next page, continuous

Explanation:

just took it

7 0
3 years ago
What are threats to computer system
4vir4ik [10]
Breach..
bugs and viruses
hack
3 0
3 years ago
Read 2 more answers
What are the functions of information technology?
Gekata [30.6K]

There are six basic functions of IT.

1. Capture: Compiling detailed records of activities.

2. Processing: Converting, analyzing, computing and synthesizing all forms of data and information.

3. Generation: Organizing information into a useful form.

4. Storage: Retaining information for further use.

5. Retrieval: Locating and copying stored data or information for further processing or for transmission to another user.

6. Transmission: Distributing information over a communication network.

3 0
1 year ago
Other questions:
  • Which of the following journals is not aimed at the public as well as scientists?
    7·1 answer
  • Put the following five steps in the order in which you would perform them to use the Paste Special function. 1. Select and copy
    6·1 answer
  • Given the strings s1 and s2 that are of the same length, create a new string consisting of the last character of s1 followed by
    10·1 answer
  • To under a clip art you must do the following.
    14·1 answer
  • The user can set their own computer hostname and username. Which stage of the hardware lifecycle does this scenario belong to?
    6·1 answer
  • What does NCR stand for
    12·2 answers
  • Select the correct answer.
    14·2 answers
  • Which of the following is NOT a valid name for a function?
    5·1 answer
  • You're working in a table that has three columns and five rows. Since the first row will be a header row, you want it to span al
    6·1 answer
  • What is a functional organisation? and how it functions​?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!