Code Fragment: LinkedStack2



// ... (continuation of LinkedStack)
protected:                                	// protected utilities
  void removeAll()				// remove entire stack contents
    { while (!isEmpty()) pop(); }
  void copyFrom(const LinkedStack& ls);		// copy from ls

public:
  LinkedStack(const LinkedStack& ls)		// copy constructor
    { copyFrom(ls); }				// copy new contents
  						// assignment operator
  LinkedStack& operator=(const LinkedStack& ls) {
    if (this != &ls) {				// avoid self copy (x = x)
      removeAll();				// remove old contents
      copyFrom(ls);				// copy new contents
    }
    return *this;
  }
  ~LinkedStack()				// destructor
    { removeAll(); }				// destroy old contents