Additional points for sorting numeric values for beginners

Source: Internet
Author: User

Objective:
Skills in sorting any number of Columns
Problem-solving requirements:
Common and efficient code
Concise as possible
Try not to generate temporary files
Extra score rules:
1 unique Train of Thought benchmark score 5 points
2 code efficiency, general benchmark score: 4 points
3. Superb Skills, benchmark score: 3 points
4. Simple code benchmark: 2 points
5. Perfect code + 15 points
The questions are as follows:
Returns any sequence of values in positive order, for example:
3 2008 11 19 777 23 2014 453 789 51
Output: 3 11 19 23 51 453 777 789 2008 2014
Note:
You do not need to consider extra-large numbers. The given sequence is an integer.
Dishuo: Copy codeThe Code is as follows: cls & @ echo off & setlocal enabledelayedexpansion
Set "strings = 3 2008 11 19 777 23 2014 453 789 51"
Echo % strings %
Set/a n = 0
For % I in (% strings %) do (
Set/a n + = 1
Set num [! N!] = % I
)
Call: quicksort num 1% n %
For/l % I in (1,1, % n %) do echo! Num [% I]!
Pause & goto: eof
: QuickSort
: Code by dishuostec
: Use call: quicksort arrary low high
Set "ARR = % 1"
Set/a dep = 0
Call: QS % 2% 3
Goto: eof
: QS
Set/a dep + = 1, lTmpLow = % 1, lTmpHi = % 2, Low = % 1, Hi = % 2
If % Hi % leq % Low % set/a dep-= 1 & goto: eof
Set/a lTmpMid = (Low + Hi)/2
Call set/a vTempVal = % ARR % [! LTmpMid!] %
: QsMainLoop
If! LTmpLow! Leq! LTmpHi! (
: QsLoop1
Call set/a vVal = % ARR % [! LTmpLow!] %
If! VVal! Lss! VTempVal! If! LTmpLow! Lss! Hi! Set/a lTmpLow + = 1 & goto qsLoop1
: QsLoop2
Call set/a vVal = % ARR % [! LTmpHi!] %
If! VTempVal! Lss! VVal! If! Low! Lss! LTmpHi! Set/a lTmpHi-= 1 & goto qsLoop2
: QsSwap
If! LTmpLow! Leq! LTmpHi! (
Call set/a vTmpHold = % ARR % [! LTmpLow!] %
Call set/a % ARR % [! LTmpLow!] = % ARR % [! LTmpHi!] %
Set/a % ARR % [! LTmpHi!] = VTmpHold
Set/a lTmpLow + = 1, lTmpHi-= 1
)
Goto qsMainLoop
)
Set/a lTmpLow [% dep %] = lTmpLow, Hi [% dep %] = Hi
If % Low % lss % lTmpHi % call: QS % Low % lTmpHi %
Call set lTmpLow = % lTmpLow [! Dep!] % & Call set Hi = % Hi [! Dep!] %
If % lTmpLow % lss % Hi % call: QS % lTmpLow % Hi %
Set/a dep-= 1 & goto: eof

 
 
Terse:Copy codeThe Code is as follows: @ echo off & setlocal enabledelayedexpansion
Set str = 3 2008 11 19 777 23 2014 453 789 51
For % I in (% str %) do (
Set str = 0000000000% % I
Set .! Str :~ -10! ! Random! = % I
)
For/f "tokens = 2 delims =" % I in ('set. ') do set/p = % I <nul
Pause> nul

 
 
MKL:Copy codeThe Code is as follows: @ echo off & setlocal enabledelayedexpansion
Set "p = 3 2008 11 19 777 23 2014 453 789 51"
For % I in (% p %) do (
Set t = 1
For % r in (% p %) do (
If % I gtr % r set/a t =! T! + 1
)
Set! T! = % I
)
Echo! 1! ! 2! ! 3! ! 4! ! 5! ! 6! ! 7! ! 8! ! 9! ! 10!
Pause

 
523066680:Copy codeThe Code is as follows: @ echo off
Setlocal enabledelayedexpansion
Set hang = 3 2008 11 19 777 23 2014 453 789 51 3 3 4 2014
Set n = 0
For % a in (% hang %) do (
Set/a num = 1, n + = 1
For % B in (% hang %) do (
If % a gtr % B set/a num + = 1
)
Call: next! Num!
Set! Num! = %
)
For/l % a in (1,1, % n %) do echo! %!
Pause
Goto: eof
: Next
If defined % num % (set/a num + = 1 & goto: next)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.