Software Development

Overload == operator for Stack


#embody <bits/stdc++.h>

utilizing namespace std;


class Stack



    int* stk;

    int size;

    int measurement;




    Stack(int measurement)


        this->measurement = measurement;

        this->size = 0;

        this->stk = new int[size];




    int getSize() return this->measurement;



    int getLength() return this->size;



    int* start() return this->stk;



    void push(int val)


        if (size < measurement)

            stk[length++] = val;


            cout << "nstack is fulln";





    buddy bool operator==(Stack&, Stack&);



bool operator==(Stack& stk1, Stack& stk2)



    int lenghtOfStack_1 = stk1.getLength();

    int lenghtOfStack_2 = stk2.getLength();





    if (lenghtOfStack_1 != lenghtOfStack_2)

        return false;





    for (int i = 0; i < lenghtOfStack_1; i++)




        if (stk1.start()[i] != stk2.start()[i])

            return false;







    return true;


int predominant()

    Stack stk1(10), stk2(10);



    for (int i = 0; i < 5; i++)






    if (stk1 == stk2)

        cout << "Each stk1 and stk2 are equal.n";



        cout << "stk1 and stk2 are usually not equal.n";



    return 0;

What's your reaction?

Leave A Reply

Your email address will not be published. Required fields are marked *