0

If I had the following pseudocode, would I need to add anything further onto it as mentioned below. Your help is much appreciated:

**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**

Are the lines I have ** REQUIRED to be in there? For example, if a question asked 'write in pseudocode for the bubble sort algorithm' would I be required to write it out fully (including the ** items) or without them is OK?

We are required to 'rope learn' the code and obviously the smaller the code the better and the easier it is to remember.

Thanks!

Alex
  • 1
  • 1
  • 2
  • So... What exactly are you asking? Is the code not working the way you intend? – Ryan Bemrose May 16 '16 at 07:51
  • @RyanBemrose Am I required to put ** in there? i.e the lines I have highlighted with **. – Alex May 16 '16 at 07:52
  • Required by what? VB.NET? A particular dialect of pseoudocode? Who is your audience - a particular compiler, or other programmers? I'm pretty sure "pseudocode" isn't a real language, so you can basically do anything you want as far as its interpreter is concerned. – Ryan Bemrose May 16 '16 at 07:54

1 Answers1

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