Home > Software engineering >  Josephus implementation in VB
Josephus implementation in VB

Time:10-04

Because now to use Java, use the VB for a long time, see josephus posts in the Java version, optional also open in VB related post, the following example is a custom list in VB to achieve,

 Option Explicit 
Private pointerHead As Object

Public Sub CreateLinkList (n As an Integer)
Dim pointer As the Node
Dim nLoop As Integer
The Static pointerLast As Node
PointerHead. Data=https://bbs.csdn.net/topics/1
The Set pointerLast=pointerHead
For nLoop=2 To n
The Set pointer=New Node
Pointer. Data=https://bbs.csdn.net/topics/nLoop
The Set pointerLast. PointerNext=pointer
The Set pointer. Pointerprevious=pointerLast
The Set pointerLast=pointer
Next
The Set pointerLast=Nothing
The Set pointer. PointerNext=pointerHead
The Set pointerHead. Pointerprevious=pointer
End Sub

The Public Function Josephus As Integer (m) As an Integer
Dim As Integer I
Dim f As Integer
Dim p, p1 As Node
The Set p=pointerHead
For I=1 To m - 1
The Set p=p.p ointerNext
Next
The Set p1=p.p ointerprevious
The Set p1. PointerNext=p.p ointerNext
F=conviction yourself ata
The Set p=p.p ointerNext
Set p.p ointerprevious p1=
The Set pointerHead=p
Josephus=f
End the Function

Private Sub Command1_Click ()

Dim m As Integer
Dim n As Integer
Dim n1 As Integer
Dim MSG As String

The Set pointerHead=New Node

N=Val (Trim (Text1. Text))
M=Val (Trim (Text2. Text))

Call CreateLinkList (n)

The Do While Not (pointerHead pointerNext Is pointerHead)
N1=Josephus (m)
MSG=MSG + "numbered" + Str (n1) + "departure;" + CRH (13)
Loop
MSG=MSG + "the final Numbers for" + Str (Josephus (m)) + "win,"
MsgBox MSG


End Sub

CodePudding user response:

http://bbs.csdn.net/topics/70017667

CodePudding user response:

Listed above, which are made with array to realize

CodePudding user response:

VB no pointer that. Of course is to use an array of convenient.
  • Related