I need to create a table (using multidimensional array/vector) that contains datas in a spiral form.

Here's my work so far:

int current_char = 0, rows = 3, columns = 4;
string input = "abcdefghijkl";
vector< vector<string> > str_table(rows, vector<string>(columns));

    for(int i = 0; i < (int)input.length(); i++)
        splitted_input.push_back(input.substr(i, 1));
    for(int x = 0; x < rows; x++)
        for(int y = 0; y < columns; y++)
            str_table[x][y] = splitted_input.at(current_char);

and it produces... (illustrated below)

Now my problem is making it spiral..


any ideas?

(sorry i made the illust. using mspaint :p)

Well What exactly does Spiral mean?

Secondly could you just illustrate what is the desired output your code like you did with the mspaint example.

I mean, it looks like spiral..if you dont know how spiral looks like, http://images.google.com/images?q=spiral

now look at my illustration back
I wanna read it from left to right, from top to bottom..
so, normally it will be read as


but after I reformed it to spiral,


any ideas? help would be greatly appreciated :)

I guess you should first fill in the numbers in the 1st row then the last column and then the last row then the first colomn. After that make it recrusive for the columns and rows inside and you can have that.

k l e
j i h g f

This article has been dead for over six months. Start a new discussion instead.