Solved

Dimensional Array

Posted on 2006-10-28
4
132 Views
Last Modified: 2010-03-31
How to create sub array with different length?

[0] - > [0]
[1] -> [0] [1]
[2] -> [0] [1] [2]
[3] -> [0] [1] [2] [3]
0
Comment
Question by:heyhey84
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
gkishoreji earned 21 total points
ID: 17827927
// initially define only one dimension
int[][] a = new int[4][];

for(int i = 0; i < 4; i++)
{
// when needed, initialize the second dimension with required number of elements
a[i] = new int[i+1];
}
0
 

Author Comment

by:heyhey84
ID: 17827971
After able created my sub array with different length
The initial one dimension array will be all null

if i want to insert a value

Insert value 1
[0] -> [value 1]
[1] -> null
[2] -> null
[3] -> null

Insert value 2
[0] -> [Value 2]
[1] -> [Value 1][]
[2] -> null
[3] -> null

How do i create this insertion of value? bigger value to be store on top
0
 

Author Comment

by:heyhey84
ID: 17828150
void insert(int n) {
          
          // i think this should create the correct size of array
        count = count + 1;
          a[count] = new int[count+1];
          
        // how to insert the value into the correct slot?                    
       
    }
0
 

Author Comment

by:heyhey84
ID: 17832206
thanks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now