-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.pas
More file actions
74 lines (57 loc) · 1.17 KB
/
Copy pathStack.pas
File metadata and controls
74 lines (57 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// Created by Matthew Abbott 24/8/22
//
{$mode objfpc}
{$M+}
unit Stack;
interface
type
stackArray = array of integer;
TStack = object
public
constructor create(maxSizeInput: integer);
procedure push(inputNumber: integer);
function pop(): integer;
function peek(): integer;
function isEmpty(): boolean;
function isFull(): boolean;
end;
var
top, maxSize: integer;
stackArrayVar: stackArray;
implementation
constructor TStack.create(maxSizeInput: integer);
begin
maxSize := maxSizeInput;
setLength(stackArrayVar, maxSizeInput);
top := 0;
end;
procedure TStack.push(inputNumber: integer);
begin
inc(top);
stackArrayVar[top] := inputNumber;
end;
function TStack.pop(): integer;
begin
dec(top);
pop := stackArrayVar[top + 1];
end;
function TStack.peek(): integer;
begin
peek := stackArrayVar[top];
end;
function TStack.isEmpty(): boolean;
begin
if top = -1 then
isEmpty := true
else
isEmpty := false;
end;
function TStack.isFull(): boolean;
begin
if top = maxSize - 1 then
isFull := true
else
isFull := false;
end;
end.