Tuesday, December 6, 2022
HomeSoftware DevelopmentOverload == operator for Stack

Overload == operator for Stack


  

#embrace <bits/stdc++.h>

utilizing namespace std;

  

class Stack {

  

    

    int* stk;

    int size;

    int measurement;

  

public:

    

    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;

        else

            cout << "nstack is fulln";

    }

  

    

    

    good friend 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 important()

{

    Stack stk1(10), stk2(10);

  

    

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

        stk1.push(i);

        stk2.push(i);

    }

  

    

    if (stk1 == stk2) {

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

    }

    else {

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

    }

  

    return 0;

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments