How can I implement a stack?

How do I create a program to convert binary to decimal using a stack in C #?

0


source to share


1 answer


Here is a hint, this snippet converts decimal integer to binary using Stack, you just need to invert the process: -P



        int num = 50;
        Stack<int> stack = new Stack<int>();
        while (num != 0)
        {
            stack.Push(num % 2);
            num /= 2;
        }

        while (stack.Count > 0)
        {
            Console.Write(stack.Pop());
        }

      

+4


source







All Articles