} Also, can you please explain or show how this would be different if node was u
ID: 3592053 • Letter: #
Question
}
Also, can you please explain or show how this would be different if node was used as an implementation instead of Linked<T> ?
Explanation / Answer
// removing from stack (Pop operation)
Public T remove()
{
if(size<=-1)
{
printf(" Stack is under flow");
}
else
{
printf(" The popped elements is %d",array[size]);
size--;
}
}
// remove from queue – we need two variable size and front in queue operation, the front variable is used to identify top end/front end of the array. From where the deletion operation performed.
Public T remove()
{
if(front==size)
{
printf(" Queue is empty");
}
else
{
printf(" Deleted Element is %d",array[front++]);
front++;
}
}
The Use of node in implementation of stack or queue is very useful because of its dynamic memory allocation and had advantage over array implementation.
The memory is allocated when new item added and memory is released (free) when perform remove/pop operation.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.