Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Left circular rotation of an array
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here int [] arr1 = {1,2,3,4,5,6}; display(arr1, "The array is : "); RotateLeftApproach1(arr1); display(arr1, "array after left shift : "); Console.WriteLine("\n"); int [] arr2 = { 2, 4, 6, 8 }; display(arr2, "The array is : "); RotateLeftApproach2(arr2); display(arr2, "array after left shift : "); } public static void RotateLeftApproach1(int[] array) { int size = array.Length; int temp; for (int j = size - 1; j > 0; j--) { //shift last element and array[j-1] element temp = array[size - 1]; array[size - 1] = array[j - 1]; array[j - 1] = temp; } } public static void RotateLeftApproach2(int[] array) { int size = array.Length; int temp; for (int j = 0; j <= size-2; j++) { //shift last element and array[j-1] element temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; } } public static void display(int [] arr, string msg ){ Console.Write(msg); foreach (int num in arr) { Console.Write(num + " "); } Console.WriteLine(); } } }
run
|
edit
|
history
|
help
0
Easy prgm
xyz
Homework4
pass-len-to-predicate-modified
C# Bubble Sort
sayalitrialc#
circular linked list
C# - a method that accepts an indefinite number of parameters
test1
Byte array to base 64 string