Rotate an Array - Question | Functions and Arrays | Data Structures and Algorithms in JAVA

preview_player
Показать описание


#pepcoding #programming #freeonlinecourses
Рекомендации по теме
Комментарии
Автор

every thing is good in your channel...except of thumbnail

himanshuraj
Автор

package Arraysss;

import java.util.Scanner;

public class rotat {
public static void rotate(int[] arr, int start, int end) {
while (start < end) {
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("enter the no of array");
int n = s.nextInt();
System.out.println("now enter the array");
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
System.out.println("enter the shift no");
int k = s.nextInt();
rotate(arr, 0, n - 1 - k);
rotate(arr, n - k, n - 1);
rotate(arr, 0, n - 1);
System.out.println("the output array is");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}

}
}

atulmankotia
Автор

Sir left rotation is algorithm se hoga

anjneykumarsingh
Автор

sir pehle modulus aur fir negative krna kyu jaroori h ulta kyu nhi kr sakte???

prakharagarwal