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

  • Home
  • SEARCH
  • 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 8367719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:13:51+00:00 2026-06-09T13:13:51+00:00

I’ve been trying to do deep copy of a 2 dimensional array but never

  • 0

I’ve been trying to do deep copy of a 2 dimensional array but never succeeded.
Here is my code.

class node {
    public node head;
    public node left;
    public node right;
    public node up;
    public node down;
}

node[][] OriginalArrayOfNode = new node[100][200];

//filling original node
for (int n = 0; n < 200; n++) {
     for(int m = 0; m < 100; m++) {
        OriginalArrayOfNode[m][n].head = OriginalArrayOfNode[m][0];
        OriginalArrayOfNode[m][n].left = ...
        //etc
     }
}

node[][]CopyArrayOfNode = new node[100][200];
//The code to copy the original array to new array should be here.

My question is how can i make a deep copy of my the OriginalArrayOfNode to CopyArrayOfNode ?
Thanks in advance.

EDIT :

Im trying to make a copy of circular doubly-linked list with 4 pointers for Knuth’s Dancing Link Algorithm. It’s pretty hard to trace where is the problem, but i assume if the original-array give “x” as a result from Knuth’s DL Algorithm, then a correct deep copy of the original-array will also give “x” as a result, provided that there are no other variable change and no random modifier. However, ive tried clone() method, arrayutil.copy() method, and none of them give a “correct” deep copy based on my assumption above.

  • 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-09T13:13:52+00:00Added an answer on June 9, 2026 at 1:13 pm

    In my opinion, you’re copying this in a very strange way; almost like you’re trying to copy the wrong way around.

    I’d do it more like this:

    for (int m = 0; n < 200; m++) {
         for(int n = 1; n < 100; n++) {
            OriginalArrayOfNode[m][n].head = OriginalArrayOfNode[m][0].head;
            OriginalArrayOfNode[m][n].left = OriginalArrayOfNode[m][0].left;
            //etc
         }
    }
    

    Note: You should start n at 1, as you’re copying from as you’re copying from 0 to the others.

    What I would suggest you do however, is add into your class node a clone() method. Clone would then provide an exact copy of the original class.

    class node {
        public node head;
        public node left;
        public node right;
        public node up;
        public node down;
    
        public node clone() {
            final node clonedNode = new node();
            node.head = this.head;
            node.left = this.left;
            node.right = this.right;
            node.up = this.up;
            node.down = this.down;
        }
    }
    
    
    for (int n = 1; n < 200; n++) {
        OriginalArrayOfNode[n] = OriginalArrayOfNode[m].clone(); }
    

    That’s not the exact code at all, but you get what I’m meaning.

    Finally, another thing to note is that if you’re trying to deep copy in the way you’re doing, you could easily just populate from index 1 – 200 using ArrayUtil.copy(...).

    Hope all this helps.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.