thu vien stack

UNIT STACK;

INTERFACE TYPE

StackElement=integer;

PointerType=^StackNode;

StackNode=record

Du_lieu:StackElement;

Next:PointerType;

end;

StackType=PointerType;

Procedure CreateS(Var Stack:StackType);

Function EmptyS(Stack:StackType):Boolean;

Procedure Pop(Var Stack:StackType;Var Item:StackElement);

Procedure Push(Var Stack:StackType;Item:StackElement);

IMPLEMENTATION

Procedure CreateS(Var Stack:StackType);

Begin Stack:=Nil end;

Function EmptyS(Stack:StackType):Boolean;

Begin EmptyS:=(Stack=Nil) end;

Procedure Push(Var Stack:StackType;Item:StackElement);

Var TempPtr:PointerType;

Begin

New(TempPtr);

TempPtr^.Du_lieu:=Item;

TempPtr^.Next:=Stack;

Stack:=TempPtr;

End;

Procedure Pop(Var Stack:StackType;Var Item:StackElement);

Var TempPtr:PointerType;

Begin

If EmptyS(Stack) then halt

else

Begin Item:=Stack^.Du_lieu;

TempPtr:=Stack;

Stack:=Stack^.Next;

Dispose(TempPtr);

end;

end;

End.

Bạn đang đọc truyện trên: TruyenTop.Vip

Tags: