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 use of –w?
Enlist the advantages of using c over perl?
What is the use of strict?
Write a program to show the process of spawning a child process
What are arrays in perl?
Suppose an array contains @arraycontent=(‘ab’, ‘cd’, ‘ef’, ‘gh’). How to print all the contents of the given array?
Write a program to decode the data in the form using cgi programming
What are the different ways to run cgi?
What is boolean context?
Explain chop?
Mention the difference between die and exit in Perl?
Explain regular expression in perl?
Which of these is a difference between Perl and C++ ?
What does `new $cur->{LINK}' do? (Assume the current package has no new() function of its own.)
What is qq (double q)operator in perl?