Chat LIVE With Programming Experts! There Are 23 Online Right Now...

 

Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 244,068 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,378 people online right now. Registration is fast and FREE... Join Now!





BIRST Sort (Improved)

Sorts string using the BIRST Method. Bytewise Indexing Radix SorT Devised my AdamSpeight2008

Submitted By: AdamSpeight2008
Actions:
Rating:
Views: 573

Language: VB.NET

Last Modified: July 14, 2008
Instructions: VB2005 or higher
Modded 14Jul2008: Added 2 missing Structures

Snippet


  1.     Private Sub BIRST2_Strings(ByRef WordList As List(Of String))
  2.         ' BIRST2
  3.         ' Bytewise Indexing Radix SorT
  4.         ' Swaps the strings only once
  5.         Dim Nxt As Integer
  6.         Dim Curr As Integer
  7.         Dim m As Integer = 0
  8.         Dim List_Pos(WordList.Count) As Integer
  9.         Dim byteindex(255) As ByteIndice
  10.         Dim TmpNP(WordList.Count) As PtrNextPtr
  11.         Dim Ptr_Pos As Integer
  12.         Dim b As Integer
  13.         Dim k As Integer
  14.         For i As Integer = 0 To WordList.Count - 1
  15.             List_Pos(i) = i
  16.             If WordList(i).Length > m Then
  17.                 m = WordList(i).Length
  18.             End If
  19.         Next i
  20.         For r As Integer = m - 1 To 0 Step -1
  21.             For i As Integer = 0 To 255
  22.                 ' Clear Index
  23.                 byteindex(i).First = -1 : byteindex(i).Last = -1
  24.             Next i
  25.             For i As Integer = 0 To WordList.Count - 1
  26.                 ' Get Pointer to string's position
  27.                 Ptr_Pos = List_Pos(i)
  28.                 ' Check to see if radix within the bounds of string length
  29.                 If r >= WordList(Ptr_Pos).Length Then
  30.                     ' Radix Position is beyind the lenght of the string
  31.                     ' So give it a default value
  32.                     b = 0
  33.                 Else
  34.                     ' Otherwise get value of character at current radix position
  35.                     b = Asc(WordList(Ptr_Pos).Substring(r, 1))
  36.                 End If
  37.                 TmpNP(i).NextPtr = -1 ' end of node list
  38.                 TmpNP(i).Ptr = Ptr_Pos
  39.                 If byteindex(b).First > -1 Then
  40.                     ' Radix value has node chain attached to it
  41.                     ' so add a link to it by change Last node's next to point to this one
  42.                     TmpNP(byteindex(b).Last).NextPtr = i
  43.                 Else
  44.                     ' Pointer to first node of this radix value
  45.                     byteindex(b).First = i
  46.                 End If
  47.                 ' Pointer to last node of the radix value
  48.                 byteindex(b).Last = i
  49.             Next i
  50.             k = -1
  51.             For j As Integer = 0 To 255 Step 1
  52.                 ' Check to see if radix value has a node chain attached to it
  53.                 If byteindex(j).First > -1 Then
  54.                     ' Get first link in Node chain
  55.                     Nxt = byteindex(j).First
  56.                     Do
  57.                         Curr = Nxt
  58.                         k = k + 1
  59.                         List_Pos(k) = TmpNP(Curr).Ptr
  60.                         Nxt = TmpNP(Curr).NextPtr
  61.                     Loop Until Nxt = -1
  62.                 End If
  63.             Next j
  64.         Next r
  65.         ' Copy string into temp array
  66.         Dim Temp_List(WordList.Count) As String
  67.         For i As Integer = 0 To WordList.Count - 1
  68.             ' Set the TempList(i) to the word list at the indicate list position
  69.             Temp_List(i) = WordList(List_Pos(i))
  70.         Next i
  71.         ' Move back into Wordlist
  72.         WordList.Clear()
  73.         WordList.AddRange(Temp_List)
  74.     End Sub
  75.  
  76.     Private Structure ByteIndice
  77.         Dim First As Long
  78.         Dim Last As Long
  79.     End Structure
  80.     Private Structure PtrNextPtr
  81.         Dim Ptr As Long
  82.         Dim NextPtr As Long
  83.     End Structure
  84.  

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month