fork download
  1. Option Explicit
  2.  
  3. Sub main()
  4. 'WordVBAでマージソート実装例
  5.  
  6.  
  7. On Error GoTo E
  8. Dim c1 As New Collection
  9. Dim c2 As New Collection
  10. Dim o
  11. c1.Add "ken", "1"
  12. c1.Add "joe", "2"
  13. c1.Add "acep", "3"
  14. c1.Add "bob", "11"
  15. c1.Add "zen", "5"
  16. c1.Add "asu", "6"
  17.  
  18. Set c2 = msort(c1)
  19. For Each o In c2
  20. Debug.Print o
  21. Next
  22. MsgBox "ok"
  23. E:
  24. Set c1 = Nothing
  25. Set c2 = Nothing
  26. End Sub
  27.  
  28. Function msort(c As Collection) As Collection
  29. Dim cL1 As New Collection
  30. Dim cL2 As New Collection
  31. Dim cr1 As New Collection
  32. Dim cr2 As New Collection
  33. Dim resC As New Collection
  34. Dim m As Long
  35. Dim m2 As Long
  36. Dim i
  37. Dim lp, rp, p
  38. Dim lmax, rmax
  39.  
  40. m = c.Count
  41. If m = 0 Then
  42. '何もしない
  43. ElseIf m = 1 Then
  44. resC.Add c(1)
  45. Else
  46. m = m - 1
  47. m2 = m \ 2
  48. p = 1
  49. For i = 0 To m2
  50. cL1.Add c(i + 1)
  51. Next
  52. p = 1
  53. For i = m2 + 1 To m
  54. cr1.Add c(i + 1)
  55. Next
  56. Set cL2 = msort(cL1)
  57. Set cr2 = msort(cr1)
  58. lmax = cL2.Count
  59. rmax = cr2.Count
  60. lp = 1
  61. rp = 1
  62. While lp <= lmax Or rp <= rmax
  63. If lp > lmax Then
  64. resC.Add cr2(rp)
  65. rp = rp + 1
  66. ElseIf rp > rmax Then
  67. resC.Add cL2(lp)
  68. lp = lp + 1
  69. Else
  70. If cL2(lp) > cr2(rp) Then
  71. resC.Add cr2(rp)
  72. rp = rp + 1
  73. Else
  74. resC.Add cL2(lp)
  75. lp = lp + 1
  76. End If
  77. End If
  78. p = p + 1
  79. Wend
  80. End If
  81.  
  82. Set cL1 = Nothing
  83. Set cL2 = Nothing
  84. Set cr1 = Nothing
  85. Set cr2 = Nothing
  86. Set msort = resC
  87.  
  88. End Function
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Visual Basic.Net Compiler version 0.0.0.5943 (Mono 4.0.1 - tarball)
Copyright (C) 2004-2010 Rolf Bjarne Kvinge. All rights reserved.

/home/nx54jA/prog.vb (3,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (7,3) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (8,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (9,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (10,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (11,3) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (12,3) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (13,3) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (14,3) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (15,3) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (16,3) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (18,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (19,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (20,10) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (21,5) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (22,7) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (23,2) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (24,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (25,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (26,8) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (28,9) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (29,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (30,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (31,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (32,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (33,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (34,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (35,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (36,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (37,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (38,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (40,2) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (41,3) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (43,7) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (44,9) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (45,5) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (46,6) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (47,7) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (48,6) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (49,8) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (50,12) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (51,9) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (52,6) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (53,8) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (54,12) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (55,9) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (56,8) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (57,8) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (58,9) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (59,9) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (60,7) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (61,7) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (62,10) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (63,11) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (64,17) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (65,15) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (66,15) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (67,17) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (68,15) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (69,13) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (70,15) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (71,21) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (72,19) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (73,17) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (74,21) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (75,19) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (76,19) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (77,15) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (78,10) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (79,9) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (80,7) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (82,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (83,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (84,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (85,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (86,4) : error VBNC30203: Identifier expected.
/home/nx54jA/prog.vb (88,13) : error VBNC30203: Identifier expected.
There were 77 errors and 0 warnings.
Compilation took 00:00:00.2586500
stdout
Standard output is empty