-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.f90
44 lines (37 loc) · 1.14 KB
/
Stack.f90
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
module stack
!Stuff for storing previous 'guesses'
integer, parameter :: MaxStackSize = 100
integer, dimension(3,MaxStackSize) :: GridChoice
integer, dimension(9,9,MaxStackSize) :: GridStack
integer :: GridStackNo = 0
contains
subroutine EmptyStack()
GridStackNo = 0
end subroutine EmptyStack
subroutine PushGrid(grid,gchoice)
integer, dimension(9,9), intent(in) :: grid
integer, dimension(3), intent(in) :: gchoice
GridStackNo = GridStackNo + 1
if (GridStackNo.gt.MaxStackSize) then
write(*,*) 'Stack Overflow'
call Abort
end if
GridStack(:,:,GridStackNo) = grid
GridChoice(:,GridStackNo) = gchoice
end subroutine PushGrid
subroutine PopGrid(grid,gchoice,stat)
integer, dimension(9,9), intent(out) :: grid
integer, dimension(3), intent(out) :: gchoice
integer, intent(out) :: stat
stat = 0
if (GridStackNo .eq. 0) then
! write(*,*) 'Stack Underflow'
stat = 1
return
! call Abort
end if
grid = GridStack(:,:,GridStackNo)
gchoice = GridChoice(:,GridStackNo)
GridStackNo = GridStackNo - 1
end subroutine PopGrid
end module stack