Adobe Interview Questions --FullStackImplementation

Adobe Interview Questions

Full Stack Implementation

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Memory_understanding
{
    class fullStack
    {
        int[] arry;
        int top;
        int[] stack;
        int a;

        public fullStack()
        {
            arry = new int[7];
            stack = new int[7];
            top = -1;

        }

        public void push(int element)
        {
            if (!isfull())
            {
                arry[top+1] = element;

                if (top == -1)
                {
                    stack[top+1] = element;
                }
                else
                {
                    if (stack[top] > element)
                    {
                        stack[top+1] = element;
                    }
                    else
                    {
                        stack[top+1] = stack[top];
                    }
                }
                top++;

            }
            else
                Console.WriteLine("Stack is full");

        }

        public void pop()
        {
            if (isEmpty())
            {
                Console.WriteLine("No more elements !!!");
            }
            else
            {
                 a = arry[top];
                top--;
                Console.WriteLine("poped" + a);
            }

        }

        public bool isfull()
        {
            if (top == arry.Length)
                return true;
            else
                return false;

        }

        public bool isEmpty()
        {
            if (top == -1)
                return true;
            else
                return false;
        }

        public void getMin()
        {
           
            Console.WriteLine("Minimum element :" + stack[top]);

        }

        public void display()
        {
            for (int i = top; i >= 0; i--)
            {
               Console.WriteLine(arry[i]);
            }
        }


    }

    class programmable
    {
        public static void Main()
        {
            fullStack fs = new fullStack();
            fs.push(5);
            fs.push(19);
            fs.push(21);
            fs.push(10);
            fs.push(4);
            fs.push(8);
            fs.push(1);
            fs.display();

            Console.WriteLine("------------------ ");
            fs.getMin();
           
            Console.WriteLine("------------------- ");
            Console.WriteLine("Poping");
            fs.pop();
            fs.pop();
            Console.WriteLine(" -----------------");
           
            fs.getMin();
            Console.WriteLine(" ");
            fs.display();
            Console.ReadLine();



        }
    }
}

Comments

Popular posts from this blog

Authentication and Authorization in Web API -Part1

My Gardening Journey 6