Can we delete a element from between of a stack!?
Like stack contain 1,2,3,4,5
I want to pop 3 but without using any another data structure?
ADT Stack is
objects: a finite ordered list with zero or more elements, the element at the back of the list is designated the top element
functions:
for all stack ∈ Stack, item ∈ Element, maxStackSize ∈ positive integer
Stack CreateS(maxStackSize) ::=
create an empty stack whose maximum size is maxStackSize
Boolean IsFull(stack, maxStackSize) ::=
if (number of elements in stack == maxStackSize)
return TRUE
else return FALSE
Stack Push(stack, item) ::=
if (IsFull(stack)) return
else create a Stack identical to stack except that it has an extra Element, item, which is the new top element
Boolean IsEmpty(stack) ::=
if (stack == CreateS(maxStackSize))
return TRUE
else return FALSE
Stack Pop(stack) ::=
if (IsEmpty(stack)) return
else create a Stack identical to stack except that the current top element has been removed from the stack
Element Peek(stack) ::=
if (IsEmpty(stack)) return
else return the top element of stack