Circular List
The stack as a Circular List
Empty(pstack)
NODEPTR 8pstack;
{
Return((*pstack == NULL) ? TRUE : FALSE);
}
Push(pstack, x)
NODEPTR *pstack;
Int x;
{
NODEPTR P;
P = getnode();
p->info = x;
if (empty(pstack) == TRUE)
*pstack = p;
Else
p->next = (*pstack)->next;
(*pstack) -> next = p;
}
Pop(pstack)
NODEPTR *pstack;
{
Int x;
NODEPTR p;
If (empty(pstack) == TRUE)
{
Printf(“stack underflow”);
Exit(1);
}
P=(*pstack) -> next;
X=p->info;
If ( p == *pstack)
*pstack = NULL;
Else
(*pstack) - > next = p->next;
Freenode(p);
Return(x);
}
No comments:
Post a Comment