I am trying to implement a Stack program which comprises of multiple smaller stack. Like for example:-
|..|
|..|
|..| |..| |..| |..|
|..| = |..| + |..| + |..|
|..|
|..|
In words suppose I wish to implement a stack of size 1000. I 'll use 10 stacks of size 100 each.
Like I have a fixed size of a stack and in case a stack of larger size is required another smaller stack is created.
I have written the following code-
#include<iostream>
#define MAX 2
using namespace std;
class Node{
int data;
Node *next;
Node(int d){
data = d;
next = NULL;
}
};
Node *n = NULL;
class multiStack{
public:
Node *head;
int size = 0;
void push(int d){
if(size < MAX){
if( head == NULL){
head = new Node(d);
}else{
Node *p = new Node(d);
p->next = head;
head = p;
}
n = head;
size++;
}else{
multiStack Sprime;
Sprime.head->next = n;
Sprime.push(d);
}
}
void print(){
Node *p;
p = n;
while (p!=null){
cout<<p->data<<" ";
p = p->next;
}
}
};
int main(){
multiStack s;
s.push(2);
s.push(1);
s.push(4);
s.print();
return 0;
}
The compiler of codepad.org is giving a "Compilation Termination Error due to -Wfatal-errors" on the following Line of Code-
int size = 0 ;
Thanx in advance If you could solve the error .
Below is the error details -