473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

i want some help in c++ on how to organize an array?

5
does anyone know how to write a function that organize an array like this?:
for example:

Expand|Select|Wrap|Line Numbers
  1. 18 9   20 7  90
  2. 65 4   77 83 32
  3. 2  34  12 20 11
  4. 22 23  10 89 57
  5. 1  28  55  0 99
becomes:

Expand|Select|Wrap|Line Numbers
  1. 0  1  4  10 20
  2. 2  7  11 20 32
  3. 9  12 22 34 65
  4. 18 23 55 77 89
  5. 28 57 83 90 99
please i need your help i tried like 5 different methods none of them worked :( please give the solution if you can... :/
Dec 28 '13 #1
1 1108
weaknessforcats
9,208 Expert Mod 8TB
The array is sorted along the diagonals starting upper left and proceeding to lower right.

Step 1 is to sort the array in ascending sequence.
Step 2 is to arrange the values in the correct display position.

I would use a mask array to do this:

0 1 5 6 10 11 etc...

Step 3 display the sorted array according to the mask:
arr[0], arr[1], arr[5]. arr[6], arr[10], arr[11], etc...

You can create the display in rows inside the display function. What you see on the screen does not have to match what is in memory.
Dec 28 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave Smithz | last post by:
Hi there. Because of the lack of a Union query in MySQL 3 I have decided to take the approach where I populate two arrays with values from similar tables in DB. In this case they are `courses`...
2
by: hrmadhu | last post by:
Hi, I am trying to write a template for an array which I can use to create multi-dimensional matrices as // A 10x10 matrix with each element initialized to 0 Array< Array<int> > Matrix (10,0);...
4
by: Desperate | last post by:
I want to create class Matrix which contains array of class Rows and some additions Class Rows contains array of Cells Here is the declaration public class Cell public int value = 0...
1
by: Dave Guenthner | last post by:
Hi. I am trying to structure a command that returns an array. First, let me show some working code: string strEKey = AdminService.AccountGetEncryptionKey(intAccount, "Account holder forgot...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
0
by: josh.23.french | last post by:
Here's the code i have: $db = array(); //main array $db = array(); //table `main` $db = array('id'=>0, 'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin'); //row $db =...
2
by: sicapitan | last post by:
I'm trying to build some xml from an array with the help from another array. In one array I have $cells Array ( =CELL0
1
by: dkumar | last post by:
Hi, This is dharmendra and i want to knowladge array in c language and unsigned integer in c language . Dharmendra
0
by: rafeig77 | last post by:
I want help How I can align rectangles differ in its tow dimensions inside big rectangle with lesser waste in area ? for mor information align.rar - 1.8 Kb or: copy this code to text file...
9
by: cephal0n | last post by:
I have a problem that's been bothering me for a week now. I want to learn more array in vba so I searched on forums and books made my own, according to my understanding. I have three textboxes:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.