You don't need a topPtr and a headPtr. They are the same thing. Get rid of one of them.
class node is an implementation detail of class linkedList. The user shouldn't have to use it or even know about it. In other words, you want the user to be able to do:
1 2 3
|
linkedList list;
list.push(4);
list.push(8);
|
and the linkedList class will take care of the details. This means that the first thing push() does is create a node to hold the item pushed:
1 2 3 4 5 6
|
void linkedList::push(int val)
{
node *n = new node;
n->number = val;
n->nextPtr = nullptr;
...
|
Even better, let the node class take care of initializing itself:
class node {
public:
node(int v) : number(v), nextPtr(nullptr) {;}
...
};
and this way the beginning of push becomes:
1 2 3 4
|
void linkedList::push(int val)
{
node *n = new node(val);
...
|
pop() should return the item that was most recently pushed. This is always the item that topPtr points to, so you don't need lines 61-72 at all.
Personally, I wouldn't use so many blank lines. They just make you scroll through the code more. Also use consistent indenting.