Hey all. I'm trying to learn stack operations and so far, I believe I've gotten push() and pop() down.

I seem to be stuck on copy, however. I cannot get a check for empty to work correctly.

typedef struct _node
{
   payload       data;
   struct _node *prev;
} node;

int main() {
   node    *rootPtr = NULL;
   node    *copyPtr = NULL;
   payload userInput;    

   // get user input for adding items to the stack, yada yada yada...
   copyPtr = stackCopy(rootPtr,copyPtr);
}

node *stackCopy(node *originalPtr, node *copyPtr)
{
   node    *tempPtr;             
   node    *tempTop;             
   payload  data;                
   node    *copyStackRev = NULL; 
   node    *copyStackOrg = NULL; 

   if (copyPtr != NULL) {
	   while (!copyPtr.empty()) {
		   copyPtr.pop();
	   }
   }
...
}

I'm getting a compile error stating that "left of '.empty' must have class/struct/union" so I know I'm using the .empty check incorrectly but I don't know what's wrong. I've check around the forum as well as on cplusplus.com and cannot find the issue.

Are you instantiating copyPtr anywhere?

Oh, I get it... You declared copyPtr in main, and you are using it int the StackCopy function. That function wouldn't know what copyPtr is.

Forget what I said about copyPtr, you're taking it in as an argument

A "node" doesn't have an empty() method (if it did, you'd have to access it as copyPtr->empty() anyway, because copyPtr is a pointer). Did you mean to pass in stacks instead of nodes?

A "node" doesn't have an empty() method (if it did, you'd have to access it as copyPtr->empty() anyway, because copyPtr is a pointer). Did you mean to pass in stacks instead of nodes?

I'm trying to delete and existing copy of copy stack. Checking for null and popping everything if it isn't null.

Right, but you need a stack to do those operations on, not a node. A node has the two things that you have in the struct typedef. I'm not sure where you think the stack is coming from...

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.