I am trying to write pop() function in a file but I am really stuck.
It looks like it is asking to delete the top element of the stack and returns a Bookmark pointer. Please, help!!
I am showing the header which explains what needs to be done.
#include "Bookmark.h"
class ArrayStack {
Bookmark **elements;//stores the array of Bookmark pointers
int numElements, capacity;
public:
//initializes an empty stack with capacity maxCapacity. The array initialized
//holds pointers to Bookmarks.
ArrayStack(int maxCapacity);
//Deallocates the Stack and all of the Bookmarks in the Stack.
~ArrayStack();
//Preconditions: newEl is a pointer to a Bookmark object
//Postconditions: newEl gets pushed on the stack if it does not exceed the capacity
//Returns: true if pushed and false otherwise
bool push(Bookmark *newEl);
//Postconditions: the Stack has the top element popped if the stack is non-empty
//Returns: a pointer to the Bookmark at the top of the stack if it exists and NULL
// if the Stack is empty.
Bookmark *pop();
//Returns: a pointer to the Bookmark at the top of the stack if it exists and NULL
// if the Stack is empty.
Bookmark *top();
//Returns: the number Bookmarks in the stack
int getNumElements();
//Postconditions: the Stack remains unchanged
//Returns: true if the Stack is empty and false otherwise
bool isEmpty();
//Postconditions: the Stack remains unchanged
//Returns: true if the Stack is full and false otherwise
bool isFull();
};
Code for Bookmark.h:
#include <cstdlib>
#include <cstring>
#include <cstdio>
class Bookmark{
char *address;//stores the address for the website
char *title; //stores the title for the website
int visits; //stores the number of times this page gets visited.
public:
//initializes a Bookmark with a *copy* of newAddress and newTitle dynamically allocated as webAddress
//and title, with 0 for visits
Bookmark(char *newAddress, char *newTitle);
//Preconditions: newName is a reference to a string
//Postconditions: changes the address of the Bookmark to be a copy of newName dynamically allocated
void setAddress(char *newName);
//Postconditions: Bookmark remains unchanged
//Returns: a reference to the string containing the address of the Bookmark
char *getAddress();
//Preconditions: newName is a reference to a string
//Postconditions: changes the title of the Bookmark to be a copy of newName dynamically allocated
void setTitle(char *newName);
//Postconditions: Bookmark remains unchanged
//Returns: a reference to the string containing the title of the Bookmark
char *getTitle();
//Postconditions: the number of visits has been increased by one.
void increaseVisits();
//Returns: the number of times the page is visited
int getVisits();
//Deallocates all memory associated with the Bookmark.
~Bookmark();
};