Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:07:11+00:00 2026-06-02T13:07:11+00:00

I have some code below. This code is a basic push/pop stack class that

  • 0

I have some code below. This code is a basic push/pop stack class that I have created as a template to enable someone to push/pop stacks. I have a homework assignment and what I am trying to do now is create a stack that has multiple values.

So I want to be able to create a stack that basically can be sent three integers and where I can push/pop these as well. What I am looking for is the theory on how this should work and I am not trying to get someone to do my homework for me.

The scenario is that we are dealing with parts. So the user will put in the serial number (int), manufacture date (int), and lotnum (int). So my questions are:

  1. When I “pop” the value should I attempt to send all three of the values during the pop or handle this another way?
  2. Should I try to create a new class using the struct like the class or something else?

    /****************************************************************************
    Inventory class.
    
    Chad Peppers
    
    This class creates a object for stacking nodes
    
    In addition, there should be member functions to perform the following 
    operations:
    - Push to the stack
    - Pop to the stack
    - Function to check if empty
    
    ****************************************************************************/
    // Specification file for the DynIntStack class
    
    template <class T>
    class Inventory
    {
    private:
       // Structure for stack nodes
       struct StackNode
       {
          T value;        // Value in the node
          StackNode *next;  // Pointer to the next node
       };
    
       StackNode *top;      // Pointer to the stack top
    
    public:
       // Constructor
       Inventory()
          {  top = NULL; }
    
       // Destructor
       ~Inventory();
    
       // Stack operations
       void push(T);
       void pop(T &);
       bool isEmpty();
    }; 
    
    /*************************************************************************
    Basic class constructor.
    
    Input Parameters:  Information to build the  stack
    
    Return Type:  void
    
    *************************************************************************/
    
    template<class T>
    Inventory<T>::~Inventory()
    {
       StackNode *nodePtr, *nextNode;
    
       // Position nodePtr at the top of the stack.
       nodePtr = top;
    
       // Traverse the list deleting each node.
       while (nodePtr != NULL)
       {
          nextNode = nodePtr->next;
          delete nodePtr;
          nodePtr = nextNode;
       }
    }
    
    /*************************************************************************
    Function to push an item in the stack
    
    Input Parameters:  T
    
    Return Type:  void
    
    *************************************************************************/
    
    template<class T>
    void Inventory<T>::push(T num)
    {
       StackNode *newNode; // Pointer to a new node
    
       // Allocate a new node and store num there.
       newNode = new StackNode;
       newNode->value = num;
    
       // If there are no nodes in the list
       // make newNode the first node.
       if (isEmpty())
       {
          top = newNode;
          newNode->next = NULL;
       }
       else  // Otherwise, insert NewNode before top.
       {
          newNode->next = top;
          top = newNode;
       }
    }
    
    /*************************************************************************
    Function to pop an item in the stack
    
    Input Parameters:  T
    
    Return Type:  void
    
    *************************************************************************/
    template<class T>
    void Inventory<T>::pop(T &num)
    {
       StackNode *temp; // Temporary pointer
    
       // First make sure the stack isn't empty.
       if (isEmpty())
       {
          cout << "The stack is empty.\n";
       }
       else  // pop value off top of stack
       {
          num = top->value;
          temp = top->next;
          delete top;
          top = temp;
       }
    }
    
    /*************************************************************************
    Basic class deconstructor.
    
    Input Parameters:  None
    
    Return Type:  void
    
    *************************************************************************/
    template<class T>
    bool Inventory<T>::isEmpty()
    {
       bool status;
    
       if (!top)
          status = true;
       else
          status = false;
    
       return status;
    }
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:07:12+00:00Added an answer on June 2, 2026 at 1:07 pm

    you could create a struct which is aggregate of the 3 int values and then instantiate template Inventory for that struct somthing on these lines

    #include "Inventory.h"
    //create an aggregate structure
    struct ProductData {
       int serial_num;
       int manufacture_date;
       int lot_num;
    }
    
    //instantiate Inventory for ProductData
    
    Inventory<ProductData> stack;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: original question below, but I revise it now that I have some code
Ok I am still having some issues with this code below. I have received
i have done some code in jquery but where i commented in this bellow
I have some code as shown below: - (IBAction)startButtonPressed:(id)sender { statusText.text = @Processing...; //here
I have some really funky code. As you can see from the code below
UPDATE - I have fixed some mistakes in the code below and the images
I have some problem with my cfml website. I have used the below code
I'm wondering about the .childNodes property, I have the code below, and for some
I have some code using a System.Transactions.TransactionScope , that creating a new instance of
I have some code like this: doDatabaseFetch { ... @synchronized(self) { ... } }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.