
-----------------------------------
reymalile
Thu May 19, 2011 8:40 am

Sorting Arrays in Alphabetical Order, capitals and lowercase
-----------------------------------
What is it you are trying to achieve?
I am trying to sort arrays in alphabetical order


What is the problem you are having?
When I am sorting capital and lowercases, i change the capitals into a lowercase, sort them but then I cant change the capitals I changed to lowercase, back to capital.


Describe what you have tried to solve this problem
I tried using two arrays however theres a problem when sorting


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




var firstName : array 1 .. 40 of string
var HowMany : int
var first : string (1)
var lowercase : string := ""
var change : flexible array 1 .. 20 of string
proc total
    var n : flexible array 1 .. 40 of string
    var x : flexible array 1 .. 40 of string
    var ctr : int
    ctr := 0
    loop
        ctr += 1
        HowMany := ctr
        put "Enter name (xxx to exit): "
        get n (ctr)
        if ord (n (ctr) (1)) >= 65 and ord (n (ctr) (1))  n (ctr2) then
                temp := n (ctr1)
                n (ctr1) := n (ctr2)
                n (ctr2) := temp
            end if
        end for
    end for

    for ctr1 : 1 .. upper (n)
        put n (ctr1)
    end for
end total

total



Please specify what version of Turing you are using
4.1.1

-----------------------------------
Tony
Thu May 19, 2011 11:01 am

RE:Sorting Arrays in Alphabetical Order, capitals and lowercase
-----------------------------------
[tdoc]Str.Upper[/tdoc] does the opposite of Str.Lower, but... since both "abc" and "Abc" both look like "abc" when you lower the first character, you wouldn't know how to restore the word without additional information.

Since you are trying to implement a custom definition of a sort, perhaps the build-in
[code]
"full_word"  "ANOTHER_word"
[/code]
is not the right way to go (since the comparison operators such as > are already defined as something else).

-----------------------------------
Insectoid
Thu May 19, 2011 12:00 pm

RE:Sorting Arrays in Alphabetical Order, capitals and lowercase
-----------------------------------
You don't actually need to store lower-case values of upper-case characters. Since str.lower returns a value and doesn't actually change the parameter, you can use it in a condition.

[code]
if Str.Lower (string1) > Str.Lower (string2) then
    swap (string1, string2)
end if
[/code]

-----------------------------------
reymalile
Fri May 20, 2011 8:07 am

RE:Sorting Arrays in Alphabetical Order, capitals and lowercase
-----------------------------------
thanks insectoid, your code worked
