Computer Science, asked by hdsoft, 8 months ago

Are these 2 questions same

Attachments:

Answers

Answered by niishaa
22

Answer:

// C++ program to find minimum number of move-to-front

// moves to arrange items in sorted order.

#include <bits/stdc++.h>

using namespace std;

// Calculate minimum number of moves to arrange array

// in increasing order.

int minMoves(int arr[], int n)

{

// Since we traverse array from end, extected item

// is initially n

int expectedItem = n;

// Taverse array from end

for (int i=n-1; i >= 0; i--)

{

// If current item is at its correct position,

// decrement the expectedItem (which also means

// decrement in minimum number of moves)

if (arr[i] == expectedItem)

expectedItem--;

}

return expectedItem;

}

// Driver Program

int main()

{

int arr[] = {4, 3, 2, 1};

int n = sizeof(arr)/sizeof(arr[0]);

cout << minMoves(arr, n);

return 0;

}

Answered by OoINTROVERToO
0

Yes both QUESTION are same

Explanation:

Sort an Array in JAVA

  • import java. util. Arrays;
  • public class Sorting {
  • public static void main (String [] args) {
  • int [] array = {45,12,85,32,89,39,69,44,42,1,6,8};
  • Arrays. sort(array);
  • System. out. println("Completely Sorted: " + Arrays.
  • int index = Arrays. binarySearch(array, 42);
  • System. out.
Similar questions
Math, 3 months ago