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
What is the purpose of _package_ literal?
What is a chomp() function in perl?
How the interpreter is used in Perl?
Why -w argument is used with perl programs?
How to read a directory in perl?
What does perl do in linux?
What are prefix dereferencer? List them.
What are the different types of perl operators?
What is the main function of cookie server?
What can be done for efficient parameter passing in perl?
Define perl scripting?
How to print escaping characters inside a string in perl?
What is the use of -w, -t and strict in Perl?
What is the importance of perl warnings? How do you turn them on?
What are the advantages of perl programming?