2 Replies - 534 Views - Last Post: 23 February 2012 - 01:01 PM Rate Topic: -----

#1 pandep   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 15-February 12

Unable to find out how much time it takes for the shell sorting

Posted 23 February 2012 - 12:49 PM

Although I have no errors in my code; however, I am not able to find the time it required to do the shell sort. Can anyone tell me what am I missing in these codes? I am attaching all three files I used for this.

Thank you!!

Attached File(s)


Is This A Good Question/Topic? 0
  • +

Replies To: Unable to find out how much time it takes for the shell sorting

#2 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Unable to find out how much time it takes for the shell sorting

Posted 23 February 2012 - 12:58 PM

Could you post your code. Use a spoiler if it's a lot.
Was This Post Helpful? 0
  • +
  • -

#3 pandep   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 15-February 12

Re: Unable to find out how much time it takes for the shell sorting

Posted 23 February 2012 - 01:01 PM

View Post_HAWK_, on 23 February 2012 - 02:58 PM, said:

Could you post your code. Use a spoiler if it's a lot.


'clsShellSort.vb
Public Class clsShellSort

    'Data Members
    Private arr() As Integer
    Private numElements As Integer

    'Constructor(s)
    Public Sub New(ByVal number As Integer)
        ReDim Preserve arr(number)
        numElements = 0
    End Sub

    'Methods
    Public Sub Insert(ByVal item As Integer)
        If (numElements > arr.GetUpperBound(0)) Then
            ReDim Preserve arr(numElements * 1.25)
        End If
        arr(numElements) = item
        numElements += 1
    End Sub

    Public Sub showArray()
        Dim index As Integer
        For index = 0 To numElements - 1
            Console.Write(arr(index) & " ")
        Next
        Console.WriteLine()
    End Sub


    Public Sub ShellSort() 'Shell Sort
        Dim inner As Integer
        Dim outer As Integer
        Dim temp As Integer
        Dim h As Integer = 1
        While (h <= numElements / 3)
            h = h * 3 + 1
        End While

        While (h > 0)
            For outer = h To numElements - 1
                temp = arr(outer)
                inner = outer
                While (inner > h - 1 AndAlso arr(inner - h) >= temp)
                    arr(inner) = arr(inner - h)
                    inner -= h
                End While
                arr(inner) = temp
            Next
            h = (h - 1) / 3
            Me.showArray()
        End While
    End Sub
End Class


'clsTiming.vb
Public Class clsTiming

    'Data Members
    Private startingTime As TimeSpan
    Private duration As TimeSpan

    'Constructor(s)
    Public Sub New()
        startingTime = New TimeSpan(0)
        duration = New TimeSpan(0)
    End Sub

    'Methods
    Public Sub stopTime()
        duration = Process.GetCurrentProcess.Threads(0).UserProcessorTime.Subtract(startingTime)
    End Sub

    Public Sub startTime()
        GC.Collect()
        GC.WaitForPendingFinalizers()
        startingTime = Process.GetCurrentProcess.Threads(0).UserProcessorTime
    End Sub

    'Properties
    Public ReadOnly Property Result() As TimeSpan
        Get
            Return duration
        End Get
    End Property

End Class


'modDriver.vb
Module modDriver

    Sub Main()
        Dim sortTime As New clsTiming
        Dim SIZE As Integer = 9
        Dim theArray As New clsShellSort(SIZE)
        Dim index As Integer
        For index = 0 To SIZE
            theArray.Insert(Int(1000 * Rnd() + 1)) 'Generates a random number from 1 to 1000 in integer format
        Next
        Console.WriteLine("Before ShellSort:")
        theArray.showArray()
        Console.WriteLine()
        sortTime.startTime()
        Console.WriteLine("During ShellSort:")
        theArray.ShellSort()
        sortTime.stopTime()
        Console.WriteLine()
        Console.WriteLine("After ShellSort:")
        theArray.showArray()
        Console.WriteLine()
        Console.WriteLine("Time for ShellSort: " & sortTime.Result.TotalMilliseconds)
        Console.Read()
    End Sub
End Module

This post has been edited by AdamSpeight2008: 23 February 2012 - 01:04 PM
Reason for edit:: Please Enclose CODE inside of CODETAGS

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1