How do you set the stack input amount? like for example, I only want the stack to hold 10 data and no more. Is therre a way to do this?
How do you set the stack input amount? like for example, I only want the stack to hold 10 data and no more. Is therre a way to do this?
It depends upon how you're implementing the stacks.
You could be using linked-lists, arrays...or even some ready-made stack system provided by your compiler...
plz mention these details, so you can get a reasonable answer.
oops...
Its using a singly linked list.
does anybody has an example for linked list?
Store your stack in something like
typedef struct Node {
int data;
struct Node* next;
} Node;
typedef struct Stack {
Node* header;
int n;
} Stack;
When you create a stack set n to 0 and then
Everytime you insert increment n and compare n to 10.