作者liwei0321 (ㄚ笠伯)
看板perl
标题[问题] 请问个排序的问题
时间Sun Jun 11 01:56:19 2006
就是今天我有个排序的题目 可是我不用 sort ($a <=> $b) 下去做
我要把我给的几个数给排序
想法是(假如有四个) 两两相比 找出第一个最小的 然後删掉
剩下三个在继续比较.....一直到结束
这重复过程就用sub来做
===================================================
#!/usr/bin/perl
print "请输入你要排序的数字,输入完成请按ctrl+d结束\n";
chomp (@data = <STDIN>);
open(FILE,">data\n");
print FILE "@data";
close(FILE);
my @input = @data;
my @out = sort { $a <=> $b } @input;
open(FILE,">output");
print FILE "@out\n";
close(FILE);
这些是我sort写出来的
希望知道的高手可以教一下 !!!!感谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
※ 编辑: liwei0321 来自: 140.113.223.181 (06/11 02:22)