Header file provided by instructor

#ifndef BIGSTACK_H

#define BIGSTACK_H

#include "ministack.h"

struct ListNode            // Description of a ListNode struct
{
    MiniStack* stackPtr;   // Pointer to a MiniStack object
    ListNode*  nextPtr;    // Pointer to next ListNode
};


class BigStack             // Description of BigStack class
{
  private:
    int num;               // Total number of values stored in MiniStack
    ListNode* headPtr;     // Pointer to head of list of nodes representing bigstack

  public:
    BigStack();            // Default constructor
    void Push(char ch);    // Adds element to top of stack assuming stack not full
    void Pop();            // Removes element from top of stack
    char Top();            // Returns copy of top value assuming stack not empty
    bool IsFull() const;   // Returns true if ministack is full; false otherwise
    bool IsEmpty() const;  // Returns true if ministack empty; false otherwise
    void Print() const;    // Prints stack contents, top to bottom
    ~BigStack();           // Destructor
};

#endif

The BigStack class uses a dynamically allocated list of Nodes to implement a small stack that
contains no more than five characters.

I am at a loss on what to do here. I am having problems setting up the push function. Can someone help.

My code that I have written so far

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
#include <new>
#include <cstddef>
#include "ministack.h"
#include "bigstack.h"

using namespace std;

BigStack::BigStack()             // Default constructor
{
    headPtr = NULL;
    num = 0;
}

void BigStack::Push(char ch)    // Adds element to top of stack assuming stack not full
{
	if (num == 0)
	{
		ListNode* nextPtr = new ListNode;
		headPtr = nextPtr;
	}
	nextPtr->num = ch;

/* Directions from instructor. 
Adds a new character to the top of the BigStack assuming that it
is not already full. If BigStack is empty (i.e. num is zero), Push
must dynamically allocate a ListNode structure before it can store
the character in BigStack. Remember, a MiniStack is a part of a
ListNode. Once a ListNode is available, the character can be
stored in the embedded MiniStack*/
}

void BigStack::Pop()            // Removes element from top of stack
{
}

char BigStack::Top()            // Returns copy of top value assuming stack not empty
{
}

bool BigStack::IsFull() const   // Returns true if ministack is full; false otherwise
{
}

bool BigStack::IsEmpty() const  // Returns true if ministack empty; false otherwise
{
}

void BigStack::Print() const    // Prints stack contents, top to bottom
{
}

BigStack::~BigStack()           // Destructor
{
}

line 24 of the *.cpp code: you have to set nextPtr->nextPtr to headptr before setting headptr = nextPtr. If you don't do that you will lose all the new nodes in the list.

if (num == 0)
{
    ListNode* nextPtr = new ListNode;
    nextPtr->nextPtr = headPtr;
    headPtr = nextPtr;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.