Advertisement

08.06.2003 at 02:02AM PDT, ID: 20701192
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

problems with binary-tree-sort (only for experts / plz don't post if you don't understand it)

Asked by ragerino in Lotus Notes

Tags: ,

hi all

i've written a class that sorts an string-array using the binary-tree-sort algorithm. when i use the class via webagent i get sometimes an overflow error or sometime errors like this:
--error class baumsort_string/sub toArray():Subscript out of range (9) in zeile 228
--error class baumsort_string/sub toArray():No RESUME (19) in zeile 228
--error class baumsort_string/sub toArray():No RESUME (19) in zeile 228
--error class baumsort_string/sub toArray():No RESUME (19) in zeile 228
--error class baumsort_string/sub toArray():No RESUME (19) in zeile 228
-error sub sort_string():No RESUME (19) in Zeile 12
error:No RESUME (19) in Zeile 60

if i use arrays from 1 to 900 entries i have no problems
but if i use arrays with more than 1000 entries i get often an overflow error (but not allways)

when debugging in notesclient i don't get the error.
im using server version 5.0.12 (same error with 5.0.11) and clien version 5.0.11


here's the class: (put it into the declarations part of the agent)
i got it into a seperate class, but for testing it should also work from your agent
******************************************************************************************************************
Public Class baumsort_string
      Public value As String
      Public lChild As baumsort_string
      Public rChild As baumsort_string
      
      'create binary tree object
      Sub new(par_value As String)
            Me.value=par_value
            Set Me.lChild=Nothing
            Set Me.rChild=Nothing
      End Sub
      
      'add new value to binary tree
      Sub addValue(par_value As String)
            If par_value<=Me.value Then
                  If Me.lChild Is Nothing Then
                        Set Me.lChild=New baumsort_string(par_value)
                  Else
                        Call Me.lChild.addValue(par_value)
                  End If
            Else
                  If Me.rChild Is Nothing Then
                        Set Me.rChild=New baumsort_string(par_value)
                  Else
                        Call Me.rChild.addValue(par_value)
                  End If                  
            End If
      End Sub
      
      'return binary-tree to array
      Sub toArray(par_array() As String)
            On Error Goto err_
            If Not Me.lChild Is Nothing Then Call Me.lChild.toArray(par_array)
            Redim Preserve par_array(Ubound(par_array)+1)
            par_array(Ubound(par_array))=Me.value
            If Not Me.rChild Is Nothing Then Call Me.rChild.toArray(par_array)
exit_:
            Exit Sub
err_:
            If Err=200 Then 'Array not initialized
                  Redim par_array(0)
                  Resume Next
            Else
                  Print "<br>--error class baumsort_string/sub toArray():" & Error & " (#" & Err & ") in line " & Erl
            End If
      End Sub
End Class
******************************************************************************************************************



and here's the function that sorts an array using the class above:
******************************************************************************************************************

Sub sort_string(par_array() As String)
      On Error Goto err_
      Dim baum As baumsort_string
      Dim i As Integer
      Dim vers As Integer
      
      Set baum=New baumsort_string(par_array(0))
      For i=1 To Ubound(par_array)
            Call baum.addValue(par_array(i))
      Next
      Erase par_array()
      Call baum.toArray(par_array)
exit_:
      Exit Sub
err_:
      Print "<br>-error sub sort_string():" & Error & " (#" & Err & ") in line " & Erl
End Sub
******************************************************************************************************************



'here's the rest of the agent: (variable maxanz defines the number of array-entries)
******************************************************************************************************************

Sub Initialize
      On Error Goto err_
      Dim maxanz As Integer
      Dim offset As Integer
      Dim maxwert As Integer
      Dim i,j As Integer
      Dim gesstartzeit As Single
      Dim startzeit As Single
      
      Dim temp As String
      Dim temp1() As String
      Dim temp2() As String
      Dim baum As baumsort_string
      
      offset=Asc("a")
      maxwert=Asc("z")-offset
      maxanz=1000
      
'Create Random-Strings
      Print "<br><b>Create Random Strings:</b>"
      gesstartzeit=Timer()
      startzeit=Timer()
      Redim temp1(maxanz)
      For i=0 To Ubound(temp1)
            temp1(i)=Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert)
            temp1(i)=temp1(i) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & "_" & Cstr(i)
      Next
      Print "<br>time elapsed:" & Format$((Timer()-startzeit),"0.000") & "s"
      Print "<br>ubound of array:" & Ubound(temp1) & "<br>"
      
'Sort the Array
      Print "<p><b>Sorting Array:</b>"
      startzeit=Timer()
      Call sort_string(temp1())
      
      Print "<br>time elapsed:" & Format$((Timer()-startzeit),"0.000") & "s"
      
      Print "<p><h1>total time elapsed:" & Format$((Timer()-gesstartzeit),"0.000") & "s</h1>"
      Exit Sub
err_:
      Stop 'for debugging in notes client
      Print "<br>Error sub initalize():" & Error & " (#" & Err & ") in line " & Erl
End Sub
******************************************************************************************************************
Start Free Trial
[+][-]08.06.2003 at 12:15PM PDT, ID: 9093915

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Lotus Notes
Tags: notes, tree
Sign Up Now!
Solution Provided By: pgloor
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.07.2003 at 02:49AM PDT, ID: 9098238

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42