What is the problem with my code?

using System;
using System.Text;

namespace Orders
{
    class Program
    {
        static int Main(string[] args)
        {
            int numberOfTestCases = Convert.ToInt16(Console.ReadLine());
            for (int i = 0; i < numberOfTestCases; i++)
            {
                int size = Convert.ToInt16(Console.ReadLine());
                int[] arr = new int[size];
                for (int k = 0; k < size; k++)
                {
                    StringBuilder sb = new StringBuilder();
                    char c;
                    while (true)
                    {
                        c = Convert.ToChar(Console.Read());
                        if (c == ' ' || c == '\n')
                            break;
                        sb.Append(c);
                    }
                    arr[k] = Convert.ToInt16(sb.ToString());
                }
                //Input completed
                MyLinkedList stack = new MyLinkedList(arr);
                stack.reArrange();
                stack.populateRank();
                stack.printRank();
            }
            
            return 0;
        }
    }

    class MyLinkedList
    {
        public MyLinkedList(int[] arr)
        {
            Head = null;
            Tail = null;
            Count = 0;
            rank = new int[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                this.addNode(arr[i], i);
            }
        }

        public int[] rank;

        public class Node
        {
            public int val;
            public int mov;
            public Node left;
            public Node right;
        }

        public Node Head
        {
            get;
            set;
        }

        public Node Tail
        {
            get;
            set;
        }

        public int Count
        {
            get;
            set;
        }

        public void addNode(int n, int k)
        {
            Node node = new Node { val = k, mov = n };
            if (this.Count == 0)
            {
                this.Head = node;
                this.Tail = node;
                this.Count++;
            }
            else
            {
                node.left = this.Tail;
                node.right = this.Head;
                this.Head.left = node;
                this.Tail.right = node;
                this.Tail = node;
                this.Count++;
            }
        }

        public void populateRank()
        {
            Node temp = this.Head;
            for (int i = 0; i < this.Count; i++)
            {
                rank[temp.val] = i + 1;
                temp = temp.right;
            }
        }

        public void printRank()
        {
            string str = "";
            for (int i = 0; i < rank.Length - 1; i++)
            {
                str += rank[i].ToString() + " ";
            }
            str += rank[rank.Length-1].ToString();
            Console.WriteLine(str);
        }

        public void reArrange()
        {
            Node cur = this.Head;
            int i = 0;
            while (i<this.Count)
            {
                Node temp = cur;
                for (int j = 0; j < cur.mov; j++)
                {
                    temp = temp.left;
                }
                i++;
                i--;
                if (cur == temp)
                {
                    i++;
                    cur = cur.right;
                    continue;
                }
                Node k = cur.right;
                addBefore(temp, cur);
                cur = k;
                i++;
            }

        }

        private void addBefore(Node n1, Node n2)
        {
            //remove n2
            if (n1 == this.Head)
            {
                this.Head = n2;
            }
            if (n2 == this.Tail)
            {
                this.Tail = n2.left;
            }
            n2.left.right = n2.right;
            n2.right.left = n2.left;
            //add n2
            n1.left.right = n2;
            n2.left = n1.left;
            n1.left = n2;
            n2.right = n1;
        }

    }
}

I’m getting runtime error (OTHERS)

please provide us a link toward the problem statement.

if (c == ’ ’ || c == ‘\n’)

maybe you should rather check if c is not a digit. you can’t be really sure of what the input string is made (there could be ‘\t’ or ‘\r’ in the line, even alpha chars…). it’s a hard-to-detect problem, as when we generate sample test cases ourselves, the code is obviously written in order to parse the data correctly. but when submitted to the online judge, who knows what can happen. :slight_smile: please tell us if you get AC with that. otherwise, i’ll try to go deeper into your code. good luck.

//