如何使用螺旋遍历在二维数组中找到特定元素的地址? [英] How do I find the address of a particular element in 2-D array using Spiral traversal?

查看:84
本文介绍了如何使用螺旋遍历在二维数组中找到特定元素的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虚构的编译器使用虚数组排序将多维数组表示为1-D数组。这个假想的排序称为螺旋排序。它的工作方式如下:

给定2-D数组 - {{1,2,3,4} {5,6,7,8} {9,10,11,12} {13,14,15,16}}然后一维数组将是{1, 2,3,4,8,12,16,15,14,13,9,5,6,7,11,10}

推算计算元素地址的通用公式(x,y)在二维数组中的位置,给定元素的地址为(0,0)。

An imaginary compiler uses an imaginary array ordering to represent multi-dimensional arrays into 1-D arrays.Say,this imaginary ordering is called spiral ordering.It works like:
Given 2-D array-{{1,2,3,4}{5,6,7,8}{9,10,11,12}{13,14,15,16}} then the 1-D array will be {1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10}
Deduce the general formula for calculating the address of an element at (x,y) position in a 2-D array,given the address of the element at (0,0).

推荐答案

作为一个想象的响应者我想象这个是你的功课,所以不要指望其他人为你做这件事。
As an imaginary responder I imagine this is your homework, so don't expect other people to do it for you.


这篇关于如何使用螺旋遍历在二维数组中找到特定元素的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆