Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8477889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:35:31+00:00 2026-06-10T18:35:31+00:00

I have a 2D array that gets dynamically created by any integer N. Initially,

  • 0

I have a 2D array that gets dynamically created by any integer N. Initially, I need to set all values in the array to a value that represents it being “uninitialized” where I use the number “-1”. However, I want to convert this 2D array to a 1D array and assign every value to be equal to its index in the new 1D array.

public class Percolation {

private int[][] id;
private int[] array1D;
private int blocked = -1;   //a number that doesn't exist in the array

// create N-by-N grid, with all sites blocked
public Percolation(int N){

    id = new int[N][N];
    for (int k = 0; k < N; k++)
    { for (int i = 0; i < N; i++) id[k][i] = blocked; } 
}


// open site (row i, column j) if it is not already
public void open(int i, int j){


}

In the open method it should change the value at the given indexes to be the corresponding index in a 1D array. For example:

[-1] [-1]

[-1] [-1]

Would then become:

[0] [1] [2] [3]

Unfortunately, since this is homework I’m unsure how I can share the grid size “N” to be able to create a new 1D array with the indexes as the values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:35:33+00:00Added an answer on June 10, 2026 at 6:35 pm

    You get the grid size N in your class with id.length.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following php array that gets all values from a form full
I have an array that gets created from JSON. The array looks like this:
I have an array that gets its values from a text file. Each line
I have a class called set that is a dynamically allocated array in the
I have an associative array in awk that gets populated like this: chr_count[$3]++ When
I have made an app that gets an array of addresses from a web
I have the following php code that gets a serialized array from a mysql
I have applications(WinForm) that gets some objects from webservice. After receiving array I transform
I have one array that is filled by mysql_query. Values that are in this
I have an array that gets processed through a foreach loop. foreach($images as $imageChoices)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.