File: demo_heapsort4

package info (click to toggle)
runawk 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 712 kB
  • sloc: awk: 1,127; ansic: 736; sh: 420; makefile: 103
file content (60 lines) | stat: -rwxr-xr-x 908 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env runawk

#use "heapsort.awk"

# This demo sorts the input lines as (key, value) pair
# and outputs sorted pairs.

# Input file for this demo: examples/demo_heapsort4.in

{
	# 1
	heapsort_fields(remap)
	printf "sorted1.1:"
	for (i=1; i <= NF; ++i){
		printf " %s", $(remap [i])
	}
	printf "\n"

	heapsort_fields(remap, 1, NF, 1)
	printf "sorted1.2:"
	for (i=1; i <= NF; ++i){
		printf " %s", $(remap [i])
	}
	printf "\n"

	heapsort_fields(remap, 1, NF, 2)
	printf "sorted1.3:"
	for (i=1; i <= NF; ++i){
		printf " %s", $(remap [i])
	}
	printf "\n"

	# 2
	orig = $0

	heapsort0()
	printf "sorted2.1:"
	for (i=1; i <= NF; ++i){
		printf " %s", $i
	}
	printf "\n"

	$0 = orig

	heapsort0(1, NF, 1)
	printf "sorted2.2:"
	for (i=1; i <= NF; ++i){
		printf " %s", $i
	}
	printf "\n"

	$0 = orig

	heapsort0(1, NF, 2)
	printf "sorted2.3:"
	for (i=1; i <= NF; ++i){
		printf " %s", $i
	}
	printf "\n"
}