נושאים פעיליםנושאים פעילים  הצגת רשימה של חברי הפורוםרשימת משתמשים  חיפוש בפורוםחיפוש  עזרהעזרה
  הרשמההרשמה  התחברותהתחברות RSS עדכונים
תיכנות
RSS UnderWarrior Forums : RSS תיכנות
נושא

נושא: בעיה התכנית - "מחולל" רצפים של כל המחרוזו

שליחת תגובהשליחת נושא חדש
כותב
הודעה << נושא קודם | נושא הבא >>
shoshan
מנהל האתר
מנהל האתר
סמל אישי

הצטרף / הצטרפה: 16 July 2005
מדינה: Israel
משתמש: מנותק/ת
הודעות: 4637
נשלח בתאריך: 20 August 2005 בשעה 11:56 | IP רשוּם
ציטוט shoshan

יש לי שתי אותיות, גדולה וקטנה ו-מספר אותיות מאקסימלי

"מחולל" רצפים של כל המחרוזות האפשריות (בסדרים והרכבים שונים) של האותיות שבין האות הקטנה והגדולה

קוד:

Module Module1

 

    'First of all I would like to say that the reason I use global

    'variables in all of my subs Is that I have been seeing some memory

    'problems.

 

    Dim abcStr As String = ""       'the string we change (generate)

    Dim lastabcStr As String = ""   'the last string we want to come to

    Const minChar As Char = "a"     'the smaller letter

    Const maxChar As Char = "c"     'the bigger letter

    Dim len As Integer = 10         'the max length of the string we want to generate

    Dim i As Integer                  'this is just a variable for loops

    Dim notFound As Boolean         'another varilable for while loops

 

    ''' <summary>

    ''' the sub putCharAtPos insert a char instead of an existing char

    ''' it was created since the chars property of the string is readonly

    ''' </summary>

    ''' <param name="s">the string variable</param>

    ''' <param name="pos">the position of the char</param>

    ''' <param name="c">the new char to insert</param>

    ''' <remarks></remarks>

    Sub putCharAtPos(ByRef s As String, ByVal pos As Integer, ByVal c As Char)

 

        s = Left(s, pos) + c.ToString + Right(s, s.Length - pos - 1)

    End Sub

 

    ''' <summary>

    ''' the sub is for generating the next combination of chars

    ''' and showing it...

    ''' </summary>

    ''' <remarks>recursive</remarks>

    Sub nextAbc()

 

        If abcStr.Length < len Then ' if the number of letters is not the last one

             notFound = True ' will tell us if we can steel go on with this number of letters

             i = 0           ' will point to to the char we want to check

             While (i < abcStr.Length) And (notFound) ' while we didn't find a letter that can't be Increased

                 If abcStr.Chars(i) = maxChar Then ' if this letter can't be Increased

                     i += 1  ' I will point to the next letter

                 Else ' if this letter can be Increased

                     notFound = False

                End If ' abcStr.Chars(i) = maxChar

             End While ' (i < abcStr.Length) And (notFound)

             If notFound Then ' if this hole string can't be Increased

                 WriteLine(abcStr) ' we show the string

                 Beep(3000, 750) ' show when adding a letter

                 i = abcStr.Length   '

                 abcStr = ""         ' we generate a string that will be lengthed one char more than the last one

                 For i = 0 To i      ' and all chars will the smaller char.

                     abcStr += minChar.ToString

                 Next ' for i =0 to i (the length of abcStr)

             End If ' notFound

        End If ' abcStr.Length < len

 

        If abcStr < Left(lastabcStr, abcStr.Length) Then ' if the string is not the last one

             WriteLine(abcStr)   ' show the string

             i = abcStr.Length - 1 ' points to the last letter

             notFound = True         ' the letter can be Increased

             While (i > 0) And (notFound)

                 If abcStr.Chars(i) >= maxChar Then

                     putCharAtPos(abcStr, i, minChar)

                     i -= 1

                 Else

                     notFound = False

                 End If

             End While

             putCharAtPos(abcStr, i, Convert.ToChar(Convert.ToByte(abcStr.Chars(i)) + 1))

             nextAbc()

        Else

             Write(lastabcStr)

        End If

    End Sub

 

    Sub Main()

        abcStr = minChar

        For i As Integer = 1 To len

             lastabcStr += maxChar

        Next

        nextAbc()

        Beep(100, 2000)

    End Sub

 

End Module

הבעיה היא שבאמצע הוא אומר לי שיש An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll



__________________
עד מתי רשעים יעלוזו?

עַל כֵּן אֶמְאַס וְנִחַמְתִּי עַל עָפָר וָאֵפֶר.
חזרה לתחילת העמוד הצג את כרטיס החבר של shoshan חפש הודעות אחרות של shoshan בקר בדף הבית של shoshan
 

אם ברצונך להגיב לנושא זה עליך קודם להתחבר
אם אינך רשום/ה כבר עליך להרשם

  שליחת תגובהשליחת נושא חדש
גרסת הדפסה גרסת הדפסה

קפיצה לפורום
אינך יכול/ה לשלוח נושאים חדשים בפורום זה
אינך יכול/ה להגיב לנושאים בפורום זה
אינך יכול/ה למחוק את הודעותיך ותגוביך בפורום זה
אינך יכול/ה לערוך את הודעותיך ותגובותיך בפורום זה
אינך יכול/ה לצור סקרים בפורום זה
אינך יכול/ה להצביע בסקרים בפורום זה