Adding into stack

procedure add(item : items);
{add item to the global stack stack;
top is the current top of stack
and n is its maximum size}
    if top = n then stackfull;
    top := top+1;
    stack(top) := item;
end: {of add}

Deletion in stack

procedure delete(var item : items);
{remove top element from the stack stack and put it in the item}
    if top = 0 then stackempty;
    item := stack(top);
    top := top-1;
end; {of delete}

These two procedures are so simple that they perhaps need no more explanation. Procedure delete actually combines the functions TOP and DELETE, stackfull and stackempty are procedures which are left unspecified since they will depend upon the particular application. Often a stackfull condition will signal that more storage needs to be allocated and the program re-run. Stackempty is often a meaningful condition.

Addition into a queue

procedure addq (item : items);
{add item to the queue q}
    if rear=n then queuefull
    else begin
         rear :=rear+1;
end;{of addq}

Deletion in a queue

procedure deleteq (var item : items);
{delete from the front of q and put into item}
    if front = rear then queueempty
    else begin
         front := front+1
         item := q[front];
end; {of deleteq}