0

I haven't programmed in C++ in forever and am really rusty. Help me out please? I've been tasked to develop a reversible singly linked listed but the nodes have to be declared in private. How do I access them to push/pop off my stack. Or am I going about this wrong?

#include <iostream>
using namespace std;

class ReversibleStack 
{
public:
    void push(int item);
    int pop();
    bool IsEmpty();
    void Reverse();

private:
    // let's build our singly linked list in private
    typedef struct node
    {
        int first; //the first node
        node *next; //pointer to the next node available
    }node;
};

#include "ReversibleStack.h"

#include <iostream>
using namespace std;

//This is the Push function that pushes an item onto the stack
void Push(int Item)
{
    node* current = first; // sets current pointer to first
    node* new_item = Item; // sets previous pointer to NULL
    node* next = current->next; // next item in stack
}
AstroCB
  • 12,337
  • 20
  • 57
  • 73
  • 1
    The easy answer: use `std::deque<>` (its by-definition already reversible since you can push/pop on both ends). The harsh reality: you need to review a number of things, such as pointer usage, `operator new`, case sensitivity, class name qualifiers, and a few others. – WhozCraig Aug 30 '13 at 23:03

1 Answers1

0

That's pretty much a syntax problem. You define methods like this:

void ReversibleStack::Push(int Item)
{
    // ... 
}
Marcin Łoś
  • 3,226
  • 1
  • 19
  • 21