Embed presentation
Download to read offline
![initially top=0,
if top reaches the size then stack is overflow,
else push the element at top of the stack and
increament the value top by 1
if (top == size)
return false; // ** overflow error **
else
{
data[top] = newNode.deepCopy();
top = top + 1;
return true; // push operation successful
}
Solution
initially top=0,
if top reaches the size then stack is overflow,
else push the element at top of the stack and
increament the value top by 1
if (top == size)
return false; // ** overflow error **
else
{
data[top] = newNode.deepCopy();
top = top + 1;
return true; // push operation successful
}](https://image.slidesharecdn.com/initiallytop0iftopreachesthesizethenstackisoverflow-230412092902-a2829191/75/initially-top-0-if-top-reaches-the-size-then-stack-is-overflow-pdf-1-2048.jpg)
The document outlines the process of managing a stack data structure, detailing the conditions that lead to stack overflow and the steps for a successful push operation. It specifies that if the 'top' reaches the size limit of the stack, an overflow error occurs. Otherwise, it describes how to store a new element and increment the 'top' index.
![initially top=0,
if top reaches the size then stack is overflow,
else push the element at top of the stack and
increament the value top by 1
if (top == size)
return false; // ** overflow error **
else
{
data[top] = newNode.deepCopy();
top = top + 1;
return true; // push operation successful
}
Solution
initially top=0,
if top reaches the size then stack is overflow,
else push the element at top of the stack and
increament the value top by 1
if (top == size)
return false; // ** overflow error **
else
{
data[top] = newNode.deepCopy();
top = top + 1;
return true; // push operation successful
}](https://image.slidesharecdn.com/initiallytop0iftopreachesthesizethenstackisoverflow-230412092902-a2829191/75/initially-top-0-if-top-reaches-the-size-then-stack-is-overflow-pdf-1-2048.jpg)