| |

VerySource

 Forgot password?
 Register
Search
View: 767|Reply: 3

Let's take a look at my program that went wrong and overflowed the stack space.

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-29 01:40:02
| Show all posts |Read mode
Dim visited (1 To 6) As Boolean
Dim u, v As Integer
Dim i As Integer, k As Integer
g (1, 1) = 0: g (1, 2) = 1: g (1, 3) = 1: g (1, 4) = 0: g (1, 5) = 0: g (1, 6 ) = 0:
g (2, 1) = 1: g (2, 2) = 0: g (2, 3) = 0: g (2, 4) = 1: g (2, 5) = 1: g (2, 6 ) = 0:
g (3, 1) = 1: g (3, 2) = 0: g (3, 3) = 0: g (3, 4) = 0: g (3, 5) = 0: g (3, 6 ) = 1:
g (4, 1) = 0: g (4, 2) = 1: g (4, 3) = 0: g (4, 4) = 0: g (4, 5) = 0: g (4, 6 ) = 0:
g (5, 1) = 0: g (5, 2) = 1: g (5, 3) = 0: g (5, 4) = 0: g (5, 5) = 0: g (5, 6 ) = 0:
g (6, 1) = 0: g (6, 2) = 0: g (6, 3) = 1: g (6, 4) = 0: g (6, 5) = 0: g (6, 6 ) = 0:
For i = 1 To 6
visited (i) = False
Next i
Call dfs (1, g)
For i = 1 To 6
Print visited (i); "";
Next i
Print
End Sub
Sub dfs (u, g)
Dim visited (1 To 6) As Boolean
visited (u) = True
For k = 1 To 6
  If g (u, k) = 1 Then
  v = k
    If visited (v) = faulse Then
    Call dfs (v, g)
    End If
  End If
Next k
End Sub
Reply

Use magic Report

0

Threads

46

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-3-4 22:00:02
| Show all posts
It should be an endless loop.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-17 21:00:01
| Show all posts
Either visit is defined as a non-module variable, or it is passed as a parameter, otherwise it is meaningless.
There is also Option Explicit turned on, there should be compilation errors.
Reply

Use magic Report

0

Threads

9

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-27 00:45:02
| Show all posts
If visited (v) = faulse Then 'visited is not defined as a module variable, faulse should be false
Call dfs (v, g)
End If
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list