Question

in java Add a method removeMin that removes the minimum score without calling other methods. public...

in java

Add a method removeMin that removes the minimum score without calling other methods.

public static void transform(int[] array)
{
   int minPosition = 0;
   for (int k = 1; k < array.length; k++)
   {
      if (array[k] < array[minPosition])
      {
         minPosition = k;
      }
   }
   int temp = array[minPosition];
   array[minPosition] = array[0];
   array[0] = temp;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

public static void removeMin(int[] array)

{

    int i;

   

    // create an array of length one less than array

    int[] temp = new int[array.length - 1];

   

    // store the min value

    int min = Integer.MAX_VALUE;

   

    // store the index of the min value

    int index = -1;

   

    // get the index of minimum element

    for( i = 0 ; i < array.length ; i++ )

    {

        if(min > array[i])

        {

            min = array[i];

            index = i;

        }

    }

   

    int j = 0;

   

    // copy contents of array to temp instead of min element

    for( i = 0 ; i < index ; i++ )

        temp[j++] = array[i];

   

    for( i = index + 1 ; i < array.length ; i++ )

        temp[j++] = array[i];

   

    // make temp new array

    array = temp;

}

Add a comment
Know the answer?
Add Answer to:
in java Add a method removeMin that removes the minimum score without calling other methods. public...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • import java.util.Scanner; public class Chpt7_Project {    public static void bubbleSort(int[] list)    {    int...

    import java.util.Scanner; public class Chpt7_Project {    public static void bubbleSort(int[] list)    {    int temp;                       for (int i = list.length - 1; i > 0; i--)    {    for (int j = 0; j < i; j++)    {    if (list[j] > list[j + 1])    {    temp = list[j];    list[j] = list[j + 1];    list[j + 1] = temp;    }    }    }   ...

  • Hello this is my java sorting algorithm program i need all of my errors corrected so...

    Hello this is my java sorting algorithm program i need all of my errors corrected so I can run it. thank you!! import java.util.Scanner;    public class SortingAlogs { public static void main(String[]args){ int array [] = {9,11,15,34,1}; Scanner KB = new Scanner(System.in); int ch; while (true) { System.out.println("1 Bubble sort\n2 Insertion sort\n3 Selection sort\n"); ch = KB.nextInt(); if (ch==1)    bubbleSort(array); if (ch==2)    insertion(array); if (ch==3)    Selection(array); if (ch==4) break;    print(array);    System.out.println(); }    }...

  • JAVA Modify the existing (methods already in the file may be modified but not deleted) the...

    JAVA Modify the existing (methods already in the file may be modified but not deleted) the code to a MaxHeap and write a driver class to do the following: 1. Insert item into a Heap 2. Delete Max from the Heap 3. Display the Heap array 4. Convert an array to Heap 1,2 & 3 must all work on the same heap array. Option 4 is independent and must take in input from the user of an integer array and...

  • I need to program 3 and add to program 2 bellows: Add the merge sort and...

    I need to program 3 and add to program 2 bellows: Add the merge sort and quick sort to program 2 and do the same timings, now with all 5 sorts and a 100,000 element array. Display the timing results from the sorts. DO NOT display the array. ____________________>>>>>>>>>>>>>>>>>>>>___________________________ (This is program 2 code that I did : ) ---->>>>>> code bellow from program 2 java program - Algorithms Write a program that randomly generates 100,000 integers into an array....

  • JAVA PROBLEMS 1. Update the below method to throw an IndexOutOfBoundsException: public E get(int index) {...

    JAVA PROBLEMS 1. Update the below method to throw an IndexOutOfBoundsException: public E get(int index) {         if (index < 0 || index > numItems) {             System.out.println("Get error: Index "                         + index + " is out of bounds.");             return null;         }         return array[index]; } Hint: Update both the method signature and the method body! 2. Update the below method to include a try-catch block rather than throwing the exception to...

  • // CMPS 390 // MinHeap.java // Complete 4 methods: getMin, add, removeMin, reheap public class MinHeap...

    // CMPS 390 // MinHeap.java // Complete 4 methods: getMin, add, removeMin, reheap public class MinHeap { private Comparable a heap; // array of heap entries private static final int DEFAULT MAX SIZE = 100; private int lastIndex; // index of last entry public MinHeap() { heap = new Comparable (DEFAULT_MAX_SIZE]; lastIndex = 0; } // end default constructor public MinHeap (int maxSize) { heap = new Comparable (maxSize); lastIndex = 0; } // end constructor public MinHeap (Comparable[] entries)...

  • //calling method int[] data = {7, 4, 3, 2}; int size = 2; method(data, size); public...

    //calling method int[] data = {7, 4, 3, 2}; int size = 2; method(data, size); public static int[] method(int[] array, int length) {             int[] result = new int[length];             for (int index = 0; index < length && index < array.length; ++index)                         result[index] = array[index];             return result; }                                                                                                                         Heap Identifier Address Contents 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 Main Stack Frame         Identifier Address Contents 101 102 103...

  • instructions: Write a non-member method named bagScaler, which removes from a Bag all elements that occur...

    instructions: Write a non-member method named bagScaler, which removes from a Bag all elements that occur less than N times . The method returns the number of copies removed. For example, if B = {Bob, Joe, Bob, Ned, Bob, Ned, Kim}, then calling bagScaler(B, 3) removes Joe, Ned, and Kim making B = {Bob, Bob, Bob}, and returns 4 because it removed 2 copies of Ned, one of Joe, and one of Kim. Note: There's no iterator, but there is...

  • Java - I need help creating a method that removes a node at the specific index...

    Java - I need help creating a method that removes a node at the specific index position. The * first node is index 0. public boolean delAt(int index) { src code 2 different classes ******************************************** public class Node { private String data; private Node next; public Node(String data, Node next) { this.data = data; this.next = next; } public Node() { } public String getData() { return data; } public void setData(String data) { this.data = data; } public void...

  • JAVA- Trace the recursive quick sort and partition methods in Lab6.java for this list of numbers:...

    JAVA- Trace the recursive quick sort and partition methods in Lab6.java for this list of numbers: 47 71 15 35 66 61 44 26 68 56 18 19 36 84 69 55 1. Find the value of pivot 2. Show the result after partitionIt() is called first time 3. Show the value of partition 4. Show the content of the array ///////////////////////////// Lab6.java class ArrayIns { private long[] theArray; // ref to array theArray private int nElems; // number of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT