开发者

Why is Pascal's Triangle manifesting itself in the output of my array (not intended)?

I am having a problem getting my Pep/8 assembly program to produce the correct output. The goal is to input a number n followed by n numbers and then have the output place the first number at the end of the array. An example of input and correct output is as follows:

"Three numbers of which 1,2, and 3 are in the array." Input: 3 1 2 3

"The first number in the array, 1, is placed at the end of the array." Correct Output: 2 3 1

My input and output are:

Input: 3 1 2 3 Incorrect Output: 2 2 1 Desired Output: 2 3 1

Input: 4 1 2 3 4 Incorrect Output: 2 3 3 1 Desir开发者_如何学Pythoned Output: 2 3 4 1

Input: 5 1 2 3 4 5 Incorrect Output: 2 3 3 4 1 Desired Output: 2 3 4 5 1

The three parts of my assembly code can be seen at: http://militarystudents.files.wordpress.com/2009/11/pic1of3.png http://militarystudents.files.wordpress.com/2009/11/pic2of3.png http://militarystudents.files.wordpress.com/2009/11/pic3of3.png

The output for n = 1 and n = 2 comes out correctly. For n > 2 the output seems to repeat a portion of my input. I am using a global array list. Any information will be greatly appreciated.


I do not know PEP8, however, I can tell a few things from your posted info:

  1. This is not Pascal's triangle, nothing is being added together as the outputs have no new (greater) values, they are only copies of the input values in the wrong order & count.

  2. This appears to be an error in how you have implemented the list rotation algorithm. Not knowing PEP8, I cannot tell what the error is, but here is the correct algorithm:

    A. Copy list(0) to tmp

    B. For i = 1 to N-1:

    (1) Copy list(i) to list(i-1)

    C. Copy tmp to list(N-1)

If I were to guess were the error was, I would say that it is in step "B.", as it appears the your loop is termination before it should, so that one or more of the later values are not being copied forward.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜