Detailed Print – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
siteicon
Solved Problem#CPP#5878

Problem Statement - 03C

Write the definition of a member function Pop() in C++, to delete a book from a dynamic stack of TEXTBOOKS considering the following code is already included in the program.

struct TEXTBOOKS
{
  char ISBN[20]; char TITLE[80];
  TEXTBOOKS *Link;
};
class STACK
{
  TEXTBOOKS *Top;
public:
  STACK() {Top=NULL;}
  void Push();
  void Pop();
  ~STACK();
};

Solution

Click to open popup

Solved Problem Understanding

void STACK::POP()
{
  if (Top!=NULL)
  {
    TEXTBOOKS *Temp;
    Temp=Top;
    cout<<Top->ISBN<<Top->TITLE<<"deleted"<<endl;
    Top=Top->Link;
    delete Temp;
  }
  else
    cout<<”Stack Empty”<<endl;
}