sort a word "system" in perl/shell without using built in
functions
output should be emssty
Answer Posted / umesh
$value = "system";
@SortedArray = split('',$value);
$strlength = @SortedArray;
print "Current sort @SortedArray
";
$swapped = 0;
for($i=0; $i < $strlength; $i++){
for (my $j = 0; $j < $strlength-1-$i; $j++) {
if($SortedArray[$j] gt $SortedArray[$j+1]){
$tmp = $SortedArray[$j];
$SortedArray[$j] = $SortedArray[$j+1];
$SortedArray[$j+1] = $tmp;
$swapped =1;
}
}
if ($swapped) {
next;
}
}
print join('', split(' ', "@SortedArray")), "
";
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
In CPAN module, name an instance you use.
How does polymorphism work in perl?
You want to read command-line arguements with perl. How would you do that?
Why should I use the -w argument with my Perl programs?
Distinguish my and local?
What is the use of '>>' in perl?
What $! In perl?
What is the difference between perl list and perl array?
How do you give functions private variables that retain their values between calls?
Explain string comparison operators in perl.
What is the importance of perl warnings?
What does -> symbol indicates in Perl?
Explain split function in perl?
Why do we use "use strict" in perl?
How can you use Perl warnings and what is the importance to use them?