Homework Solution: Please Do it in java!!!!!…

    Please Do it in java!!!!! Given Blewo is part of a class declaration and constructor for keeping two stacks within a single linear array. In this class, neither stack should overflow until all memory in the array is utillized and an entire stack should never be shifted to a different location within the arry. Fo this class you should write the methods push1(),push2(),pop1(), pop2(),clear1(),clear2(), isEmpty1(), isEmpty2(), and isFull() to manipulate the two stacks. 5. Given below is part of a class declaration and constructor for keeping two stacks within a single linear array. In this class, neither stack should overlow until all memory in the array is utilized and an entire stack should never be shifted to a different location within the array. For this class you should write the methods push push2 pop pop2, clearl), clear20, isEmpty1, isEmpty2(), and isFull() to manipulate the two stacks. (Hint: The two stacks grow toward each other.) public class Stack ( private inti item private int topli private int top2i private int sizei
    5. Given below is part of a class declaration and constructor for keeping two stacks within a single linear array. In this class, neither stack should overlow until all memory in the array is utilized and an entire stack should never be shifted to a different location within the array. For this class you should write the methods push push2 pop pop2, clearl), clear20, isEmpty1, isEmpty2(), and isFull() to manipulate the two stacks. (Hint: The two stacks grow toward each other.) public class Stack ( private inti item private int topli private int top2i private int sizei

    Expert Answer

     
    public class Stack { private int[] item;

    Please Do it in java!!!!!

    Given Blewo is separate-among-among of a tabulate avowal and parent ce maintenance couple stacks amid a uncompounded direct adorn. In this tabulate, neither stack should deluge until bountiful retrospect in the adorn is utillized and an integral stack should never be shifted to a opposed colonization amid the arry. Fo this tabulate you should transcribe the methods thrust1(),push2(),pop1(), pop2(),clear1(),clear2(), isEmpty1(), isEmpty2(), and isFull() to touch the couple stacks.

    5. Given beneath is separate-among-among of a tabulate avowal and parent ce maintenance couple stacks amid a uncompounded direct adorn. In this tabulate, neither stack should overlow until bountiful retrospect in the adorn is utilized and an integral stack should never be shifted to a opposed colonization amid the adorn. Ce this tabulate you should transcribe the methods thrust thrust2 pop pop2, clearl), clear20, isEmpty1, isEmpty2(), and isFull() to touch the couple stacks. (Hint: The couple stacks accrue inland each other.) exoteric tabulate Stack ( referable-open surround separate referable-open int topli referable-open int top2i referable-open int greatnessi

    5. Given beneath is separate-among-among of a tabulate avowal and parent ce maintenance couple stacks amid a uncompounded direct adorn. In this tabulate, neither stack should overlow until bountiful retrospect in the adorn is utilized and an integral stack should never be shifted to a opposed colonization amid the adorn. Ce this tabulate you should transcribe the methods thrust thrust2 pop pop2, clearl), clear20, isEmpty1, isEmpty2(), and isFull() to touch the couple stacks. (Hint: The couple stacks accrue inland each other.) exoteric tabulate Stack ( referable-open surround separate referable-open int topli referable-open int top2i referable-open int greatnessi

    Expert Response

     

    exoteric tabulate Stack {

    not-open int[] separate;
    not-open int top1,top2;
    not-open int greatness;

    exoteric Stack(int max){
    size=max;
    item=new int[size];
    top1=-1;
    top2=size;

    }

    exoteric destitute thrust1(int postulates){
    if(top2-top1>1)
    item[++top1]=data;
    else
    System.out.println(“No interinterintervenience to gorge postulates on stack1 “);
    }
    exoteric destitute thrust2(int postulates){
    if(top2-top1>1)
    item[–top2]=data;
    else
    System.out.println(“No interinterintervenience to gorge postulates on stack2 “);

    }
    exoteric int pop1(){
    if(top1>-1)
    return separate[top1–];
    else {
    System.out.println(“underflow stack1”);
    return 0;
    }
    }
    exoteric int pop2(){
    if(top2<item.length)
    return separate[top2++];
    else{
    System.out.println(“underflow stack2”);
    return 0;
    }
    }

    /**
    * to eject bountiful separates from the Stack.
    */
    exoteric destitute clear1()
    {
    for(int i = 0; i <= top1; i++)
    item[i] = -1;

    top1 = -1;
    System.out.println(“Clearing stack 1”);

    }
    exoteric destitute clear2()
    {
    for(int i = greatness; i <= top2; i–)
    item[i] = -1;

    top2 = greatness;
    System.out.println(“Clearing stack 2”);

    }

    //check whether stack is empty

    exoteric destitute isEmpty1(){
    if (top1==-1)
    System.out.println(“Stack 1 Is empty”);
    else
    System.out.println(“Stack 1 Is referable empty”);
    }
    exoteric destitute isEmpty2(){
    if(top2==(item.length))
    System.out.println(“Stack 2 Is empty”);
    else
    System.out.println(“Stack 2 Is referable empty”);
    }

    //check whether stack is bountiful.

    exoteric destitute isFull(){
    if(top1==size-1)
    System.out.println(“adorn is bountiful”);
    else
    System.out.println(“adorn is referable bountiful”);

    }

    exoteric static destitute main(String[] args) {

    Stack couplestack=new Stack(10);
    twostack.push1(9);
    twostack.push2(8);
    twostack.push1(99);
    twostack.push2(98);
    System.out.println(“Poped atom from the 1st stack: “+twostack.pop1());
    System.out.println(“Poped atom from the 2nd stack: “+twostack.pop2());
    twostack.isFull();
    twostack.isEmpty1();
    twostack.clear1();
    twostack.isEmpty1();
    twostack.isEmpty2();
    twostack.clear2();
    twostack.isEmpty2();

    }

    }

    Output: