数据结构56页E4作业

A stack may be regarded as a railway switching network like the one in Figure 2.3. Cars numbered 1,2.....,n, are on the line at the left ,and it is desired to rearrange (permute)the cars as they leave on the righthand track .A car that is on the spur(stack)can be left there or sent on its way down the right track but it can never be sent back to the incoming track . For example ,if n=3,and we have the cars ,1,2,3on the left track ,then 3 first goes to the spur.we could then send 2 to the spur,then on its way to the right ,then send 3 on the way,then 1,obtaining the new order 1,3,2.

(a)For n=3,find all possible permutations that can be obtained.

123   132   213   321   312

(b)For n=4,find all possible permutations that can be obtained.

1234  1243  1324  1423  1432  2134  2143  3124  3214  4123  4132  4213  4312  4321 

你可能感兴趣的:(数据结构56页E4作业)