23. Program
(Imp_Q) Write a program for left rotate one elements ?
class G
{
public static void main(String args[])
{
int[] a = {2, 4, 4, 2, 4, 7, 4, 5};
for(int i = 0; i < a.length; i++)
{
System.out.print(a[i] + ",");
}
System.out.println();
int temp = a[0];
for(int i = 1; i < a.length; i++)
{
a[i-1] = a[i];
}
a[a.length - 1] = temp;
for(int i = 0; i < a.length; i++)
{
System.out.print(a[i] + ",");
}
System.out.println();
}
}
24. Program
(Imp_Q) Write a program for right shift one elements ?
class H
{
public static void main(String args[])
{
int[] a = {2, 4, 4, 2, 4, 7, 4, 5};
for(int i = 0; i < a.length; i++)
{
System.out.print(a[i] + " ,");
}
System.out.println();
for(int i = a.length - 1; i > 0; i--)
{
a[i] = a[i-1];
}
for(int i = 0; i < a.length; i++)
{
System.out.print(a[i] + " ,");
}
System.out.println();
}
}
25. Program
(Imp_Q) Write a program for right rotate one elements ?
class I
{
public static void main(String args[])
{
int[] a = {2, 4, 4, 2, 4, 7, 4, 5};
for(int i = 0; i < a.length; i++)
{
System.out.print(a[i] + ",");
}
System.out.println();
int temp = a[a.length - 1];
for(int i = a.length - 1; i > 0; i--)
{
a[i] = a[i-1];
}
a[0] = temp;
for(int i = 0; i < a.length; i++)
{
System.out.print(a[i] + ",");
}
System.out.println();
}
}