2016-05-16 74 views
0

如果我有下面的伪代码,我需要添加任何进一步的东西,如下所述。我们非常感谢您的帮助:泡沫排序 - 到VB.NET

**repeat 
    swapped = false** 

    for i from 1 <- N 
      for j <- 0 to N - 1 
       if a[j] > a[j + 1] 
        swap(a[j], a[j + 1]) 
    **swapped = true 
      end if** 
     **end for 
     until not swapped** 

我有哪些行**需要在那里?例如,如果一个问题被问到“用冒泡排序算法编写伪代码”,我是否会被要求将其完全写出来(包括**项目),或者没有它们就可以吗?

我们需要“绳索学习”代码,显然代码越小越好,越容易记住。

谢谢!

+0

那么...你到底在问什么?代码是否按照你的意图工作? –

+0

@RyanBemrose我需要把**放在那里吗?即我用**突出显示的行。 – Alex

+0

需要什么? VB.NET? pseoudocode的特定方言?谁是你的受众 - 一个特定的编译器或其他程序员?我很确定“伪代码”不是一种真正的语言,因此就口译员而言,你基本上可以做任何你想做的事情。 –

回答

0
Sub Main() 
       Dim Numlist() As Integer = {23435, 1, 433, 5234} 
    'here you can use any numbers in any order 
     Dim Count As Integer = 0 
       Dim Swapvalue As Integer 
       For ii = 0 To Numlist.Length - 2 
        For i = 0 To Numlist.Length - 2 
         Count += 1 
         If Numlist(i) > Numlist(i + 1) Then 
          Swapvalue = Numlist(i) 
          Numlist(i) = Numlist(i + 1) 
          Numlist(i + 1) = Swapvalue 
         End If 
        Next 
       Next 
       Console.WriteLine("Number of comparisons: {0}", Count) 
       For i = 0 To Numlist.Length - 1 
        Console.WriteLine(Numlist(i)) 
       Next 
     End Sub