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]
4 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]4 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
Most nosql data stores were created to address problems associated with storing large amounts of distributed data in __________.
finlep [7]
NoSQL is primarily designed for supporting the decision making systems. Most NoSQL data stores were created to address problems associated with storing large amounts of distributed data in relational database management systems(RDBMS).
RDBMS is system used for the management of the database.D<span>ata is stored in the form of related tables.</span>
3 0
4 years ago
What objective behaves like a high level array
zavuch27 [327]

Answer:

C.Vector

Explanation:

Vector is a high level array used in C++.It has the capability of resizing itself when it gets full.it has many functions that increases it's functionality like size(),begin(),end(),erase(),clear(),push_back(),pop_back() and many more and we store any kind of data type in the vector.

syntax for declaring a vector:-

vector<data type> vector name.

8 0
3 years ago
What are examples of macro events related to a form? Check all that apply.
Westkost [7]

Answer:

A form is closed

A form is resized.

A form is opened

A user presses a key

A user moves the mouse

Explanation:

There are different events in a form, and we can use them in different situations like:

  • We can use On Resize to resize our form.
  • If we On Load the form will be displayed.
  • On Clicked, If there was a click in an object
  • On Unload to close the form.
  • On Mouse Enter and On Mouse Leave, in this case, the mouse enters or leaves the object.

6 0
4 years ago
Write a program that reads the data from rawdata_2004.txt into a dictionary whose keys are country names and whose values are pe
san4es73 [151]

Answer:

import re

def country_capita():

   #opens file

   file=open("inputfile.txt", "r")

   dictionary=dict()

   #reads line by line

   for line in file.readlines():

       # substitutes for multiple space a single space

       line = re.sub(r"[\s]{2, }", ' ', line)

       list=[]

       #splits line on space

       list=line.split(" ")

       #put into dictionary

       dictionary[list[1]]=list[2]

#   get input

   while True:

       choice=input("Enter the country name or quit to exit: ")

       if choice=="quit":

           break

       elif choice in dictionary.keys():

           print(dictionary[choice])

       else:

           print("Invalid Country")

country_capita()

Explanation:

Using python to code this program. First we, (line 1) import the re module which offers us a set of functions that allows us to search a string for a match. ((line 2) Next we define a function country_capita() that will open rawdata_2004.txt, read the information within line by line and create a dictionary list. The we create a while loop with conditional statements that prompt the user to enter country names, print the corresponding values and stops when the user enters quit.

7 0
3 years ago
A(n) _____ is any hardware component that allows you to enter data and instructions into a computer or mobile device.
Darya [45]
Hello there.

<span>A(n) _____ is any hardware component that allows you to enter data and instructions into a computer or mobile device.

</span><span>Input Device</span>
4 0
3 years ago
Other questions:
  • (04.01 MC)
    11·1 answer
  • Which of the following should businesses and organizations do to promote a safe work environment?
    6·1 answer
  • Once you create a slide show, it is not easy to rearrange things, so you should plan your presentation ahead of time.
    14·1 answer
  • How do web bugs invade a person's privacy?
    7·1 answer
  • A buffer is filled over a single input channel and emptied by a single channel with a capacity of 64 kbps. Measurements are take
    11·1 answer
  • Match the image to the view type in a presentation program. scroll bar tool bar status bar menu bar provides an array of buttons
    10·2 answers
  • I will mark Brainliest if you sub to Huggablesheep 89 he said he is going to quit if he gets 50 subs he might try again please h
    8·2 answers
  • ANSWER ASAP! 50 POINTS!!!!
    10·2 answers
  • I don't know what to do for these two questions
    13·1 answer
  • Write an algorithm to find the area of a circle of radius r
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!