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


Please Help Members By Posting Answers For Below Questions

What is the use of 'ne' operator?

681


what are the two ways to get private values inside a subroutine or block?

693


Comment on the scope of variables in perl.

704


what is the difference between java and cgi?

747


Mention the difference between die and exit in Perl?

842


What is the different between array and hash in perl programming?

677


How to open and read data files with Perl

812


What does next statement do in perl?

756


How do I sort a hash by the hash key?

730


What does 'do' statement do in perl?

663


What are perl array functions?

715


What is the use of now constructor in perl?

723


What is warn function in perl?

696


Mention how many ways you can express string in Perl?

786


Differentiate between c++ and perl.

761