wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in code" Watch "doubt in code" New topic
Author

doubt in code

aditya miduthuru
Greenhorn

Joined: Nov 28, 2012
Posts: 1
how can we write a code for transpose of a matrix with only one array and that too for non-symmetric array???
Help me up we are trying to do in c but not able write a logic
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
Well considering that you have an array(which in actuality is an array of arrays) you want to write a program to convert from Ain to Aout on the same array. Hope I got that right.

Ain =
[
1 2 3
4 5 6
]

Aout =
[
1 4
2 5
3 6
]

It is not possible either in C or in Java to convert a 2x3 array to 3x2. A single array's dimensions and capacity are fixed during compile time and you cannot change that programmatically.

You can take an input array, create an output array(with dimensions switched) and then iterate and fill the output array.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11250
    
  16

I would suggest you work it out by hand first. Write down the directions, in English (or any other natural language), that a 10 year old child can understand. Once you have that, writing the code is a lot simpler.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt in code