If I have a sorting algorithm that is special for numbers, how will I implement a program that will sort letters? Here is the pseudocode of the algorithm that sorts integers:
1 if size > 1 then
2 var a, b, max, min, NOP, NON, x, y, z
3 max:= array(0)
4 min:= array(0)
5 NOP:= 0
6 NON:= 0
7 for a:= 0 to size-1 do
8 if array(a) > max then
9 max := array(a)
10 else
11 min:=array(a)
12 end if
13 if array(a) >= 0 then
14 NOP:= NOP+1
15 else
16 NON:= NON+1
17 end if
18end for
8 if min ? max then
9 if NOP > 0 then
10 create a new array: PosArray[max+1]
11 if NON > 0 then
12 create a new array: NegArray[|min|+1]
13 for b:= 0 to size-1 do
14 if array(b)>= 0 then
15 PosArray(array(b)):= PosArray(array(b))+1
16 else
17 NegArray(|array(b)|):= NegArray(|array(b)|)+1
18 if NON > 0 then
19 for x:= |min| downto 1 do
20 if NegArray(x) == 1 then
21 array(i):= -1*x
22 i:= i+1
23 else
24 if NegArray(x) > 1 then
25 z=i
26 for y:= z to z+NegArray(x)-1 do
27 array(i) := -1* x
28 i:= i+1
29 if NOP > 0 then
30 for x:= 0 to max do
31 if PosArray(x) == 1 then
32 array(i):= x
33 i:= i+1
34 else
35 if PosArray(x) > 1 then
36 z=i
37 for y:= z to z+PosArray(x)-1 do
38 array(i) := x
39 i:= i+1
40 return array
Now, how will I be able to sort alphabets using the pseudocode? Is there a way? Thanks.
1 if size > 1 then
2 var a, b, max, min, NOP, NON, x, y, z
3 max:= array(0)
4 min:= array(0)
5 NOP:= 0
6 NON:= 0
7 for a:= 0 to size-1 do
8 if array(a) > max then
9 max := array(a)
10 else
11 min:=array(a)
12 end if
13 if array(a) >= 0 then
14 NOP:= NOP+1
15 else
16 NON:= NON+1
17 end if
18end for
8 if min ? max then
9 if NOP > 0 then
10 create a new array: PosArray[max+1]
11 if NON > 0 then
12 create a new array: NegArray[|min|+1]
13 for b:= 0 to size-1 do
14 if array(b)>= 0 then
15 PosArray(array(b)):= PosArray(array(b))+1
16 else
17 NegArray(|array(b)|):= NegArray(|array(b)|)+1
18 if NON > 0 then
19 for x:= |min| downto 1 do
20 if NegArray(x) == 1 then
21 array(i):= -1*x
22 i:= i+1
23 else
24 if NegArray(x) > 1 then
25 z=i
26 for y:= z to z+NegArray(x)-1 do
27 array(i) := -1* x
28 i:= i+1
29 if NOP > 0 then
30 for x:= 0 to max do
31 if PosArray(x) == 1 then
32 array(i):= x
33 i:= i+1
34 else
35 if PosArray(x) > 1 then
36 z=i
37 for y:= z to z+PosArray(x)-1 do
38 array(i) := x
39 i:= i+1
40 return array
Now, how will I be able to sort alphabets using the pseudocode? Is there a way? Thanks.