我很长时间没有滚动。我记得现在使用这些方法,这些都是等价的:
韵(-ish)
NJ 卷
堆栈(的东西)
也许一个更好的办法来想它是一个物理堆栈 (例如书籍),所以堆栈的顶部字面上是“在顶部”。
然后积极的卷上升:
for j number of times
pick up n books
put the top one on the bottom (shifting the substack "up")
put them back down
和负滚下山:
for j number of times
pick up n books
put the bottom one on top (shifting the substack "down")
put them back down
横盘
但我通常想象堆栈横盘整理,道路对象 将作为一系列文字查看文件。所以我认为 积极的一面,因为它隐藏了第n个 事物背后的前j个事物;和负面卷作为钩起j事情开始 第n件事情。给与承担。
客场。
n j roll
__ j > 0 __ move top j elements to the bottom of n
n TOS
-------------|
| j |
| -----|
| | |
V V |
a b c d e f g h
^ | |
| |-------|
^ |
-<-<-<-<-<-
move
然后回来。
__ j < 0 __ move j elements from the bottom of n to the top
n TOS
-------------|
| j |
|----- |
| | |
V V |
a b c d e f g h
| | ^
|-------| |
| ^
->->->->->-
move
棉绒滚筒
又一方式是侧身图片它,并铺在顶部粘性轮(棉绒辊,也许)
(a) (b) (c) (d) (e) 5 3 roll
_______
/ \
| 3 |
|/| \ |
\_______/
(a) (b) (c) (d) (e)
然后一个正像卷轴逆时针旋转 就像弧形和旋转一样。
_______ (e)
/ /\
| 3 --| (d)
| \ |
\_______/ (c)
(a) (b)
(e)__(d)__(c)
/\ | /\
| 3 |
| |
\_______/
(a) (b)
(c)_______
/\ \
(d) |-- 3 |
|/ |
\_______/
(e) (a) (b)
_______
/ \
| 3 |
|/| \ |
\_______/
(c) (d) (e) (a) (b)
和负滚去顺时针 喜欢的ARCn和负旋转。
_______
/ \
| 3 |
|/| \ |
\_______/
(a) (b) (c) (d) (e)
(a)_______
/\ \
(b) |-- 3 |
|/ |
\_______/
(c) (d) (e)
(c)__(b)__(a)
/\ | /\
| 3 |
| |
\_______/
(d) (e)
_______ (c)
/ /\
| 3 --| (b)
| \ |
\_______/ (a)
(d) (e)
_______
/ \
| 3 |
|/| \ |
\_______/
(d) (e) (a) (b) (c)
消除负
它不应该是不难看出,负轧辊是完全不必要的,因为如果j < 0,可以用n-J所取代。例如。
3 -1 roll % roll bottom 1 element from 3 to the top
3 2 roll % roll top 2 elements behind the 3rd
是一样的。
16 -4 roll % roll bottom 4 elements from 16 to the top
16 12 roll % roll top 12 elements behind the 16th
是一样的。
这导致了最终的,最终的简化视图(虽然上面的每一个都可以)。
卷只是一个大交换
你真的只是交换顶部Ĵ元素与下面的正Ĵ元素。
假设你有一个堆栈(其中$ TOS $标记堆栈的顶部)上的这个烂摊子,并要适当地订购吧:
g h i j k l m n o p q r s t u v w x y z a b c d e f $TOS$
数上升(下降)为ñ和j。
g h i j k l m n o p q r s t u v w x y z a b c d e f
26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
| | j = 6 . . . .
| n = 26 . . . . . . . . . . . . . . . . . . . . . . .
> 26 6 roll pstack
a b c d e f g h i j k l m n o p q r s t u v w x y z
为Ĵ简单地定位从Ñ元件之间划分相对于最深元件行(它从下面计数)的负值。
t u v w x y z a b c d e f g h i j k l m n o p q r s
26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
. . . . j = -7 | |
. . . . . . . . . . . . . . . . . . . . . . . n = 26 |
> 26 -7 roll pstack
a b c d e f g h i j k l m n o p q r s t u v w x y z
这里是一个方便的功能,让一个接口滚这是更紧密地类似于大交换视图。
% r0..rN s0..sM N M swap s0..sM r0..rN
% a gentler interface to the power of roll
/swap {
exch 1 index add exch
roll
} def
0 1 2 3 /a /b /c 4 3 swap pstack
输出:
GPL Ghostscript 8.62 (2008-02-29)
Copyright (C) 2008 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
3
2
1
0
/c
/b
/a
GS<7>GS<7>
这个问题是为了激发答案(分享你的知识)。任何有待改进的建议都是热切期盼的。 –