Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Arrange array element in right and left order starting from least element

var N = Convert.ToInt32(Console.ReadLine());
var arr = new List<int>();
for (int i = 0; i < N; i++)
{
    arr.Add(Convert.ToInt32(Console.ReadLine()));
}

arr.Sort();

var newArr = new int[arr.Count];
var temp = true;
var right = new Queue<int>();
var left = new Stack<int>();    

for (int i = 1; i < N; i++)
{
    if(temp)
    {
        temp = false;
        right.Enqueue(arr[i]);
    }
    else
    {
        temp=true;
        left.Push(arr[i]);
    }
}
var j = 0;

while(true)
{
    while(left.Count > 0)
    {
        newArr[j++] = left.Pop();
    }
    newArr[j++] = arr[0];
    while (right.Count > 0)
    {
        newArr[j++] = right.Dequeue();
    }
    break;
}
foreach (var item in newArr)
{
    Console.Write(item + " ");
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: xamarin timer example 
Csharp :: how to compare 2 date time in asp.net core 3.1 
Csharp :: c# datetime iso 8601 format 
Csharp :: c# unity camera follow 
Csharp :: c# regex number only 
Csharp :: Codewars Multiply 
Csharp :: removing illlegal char from filename 
Csharp :: c# image to byte array 
Csharp :: unity pause scene 
Csharp :: c# object initialization can be simplified 
Csharp :: unity detect if animation is playing 
Csharp :: valid url in .net 
Csharp :: ask for administrative permission 
Csharp :: c# initialize array 
Csharp :: get desktop path c# 
Csharp :: c# rename file add 
Csharp :: unity access phone camera 
Csharp :: How to read a XML on C# 
Csharp :: how to check the distance between two dates c# 
Csharp :: DateTime previous day c# 
Csharp :: get directory name of path c# 
Csharp :: regular expression for website url validation in c# 
Csharp :: C# Console multi language 
Csharp :: c# entity framework code first connection string 
Csharp :: Comapre Binary Trees 
Csharp :: c# file dialog to get folder path 
Csharp :: unity nested list 
Csharp :: replace elements with greatest element on right side 
Csharp :: get time from datetime c# 
Csharp :: c# wpf change label text color 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =