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 6717341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:50:24+00:00 2026-05-26T08:50:24+00:00

i use the solution in this link not work Deep cloning objects the following

  • 0

i use the solution in this link not work
Deep cloning objects

the following code, can not copy to a new tree, mutate will affect the original tree root(root)

                 foreach (Bag b in bag_list)
                {
                    if (b.cards.Count() == 2)
                    {
                        Node original_root = new Node();
                        original_root = (Node)root.Clone(); // copy to a new tree

                        target_list = choose_valid_target(target_list, b.cards, b.cards.Count() - 1);

                        foreach (Target t in target_list)
                        {
                            Console.WriteLine("op:" + t.op + ", label:" + t.label);

                            Node mutated_root = mutate(original_root, target_list);

                            result = "";
                            result = inorder(mutated_root, result); // get inorder
                            Console.WriteLine(result.Substring(1, result.Length - 2)); //print
                        }
                    }
                }

    public class Node : System.Object, ICloneable
    {
        public int priority;
        /*
        7 alphabet
        6 (,)
        5 *,/,%
        4 +,-
        3 <,<=,>,>=
        2 &&,||
        1 =
         */
        public string Data;
        public Node Left;
        public Node Right;
        public string Label;

        public object Clone()
        {
            //return this as object; 
            return this.MemberwiseClone(); 
            //return new Node() as object;
        }
    }

        public Node mutate(Node root, List<Target> targets) // mutate
        {
            if (root != null)
            {
                if (!IsLeaf(root.Left.Data))
                    mutate(root.Left, targets);

                foreach (Target target in targets)
                {
                    if (root.Label == target.label)
                    {
                        root.Data = target.op;
                    }
                }

                if (!IsLeaf(root.Right.Data))
                    mutate(root.Right, targets);
            }
            return root;
        }
  • 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-05-26T08:50:25+00:00Added an answer on May 26, 2026 at 8:50 am

    Clone all nodes recursively:

    public object Clone()
    {
        Node clone = (Node)MemberwiseClone();
        if (Left != null)
            clone.Left = (Node)Left.Clone();
        if (Right != null)
            clone.Right = (Node)Right.Clone();
        return clone;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Regarding the answer provided at this link: Proposed solution I tried to use this
if your app use this solution , do do you plan port the app
The solution to this question suggested the use of John Resig's class implementation. This
I know one awkward solution for this taks will be : first use ct
I use contructor injection in my solution, but this one class has a property
How can we use Solution Package (WSP) MOSS 2007 to synchronize lists from one
Having searched everywhere for a solution to this problem, and attempting to use a
Following this thread solution, I have managed to get a bunch of lists that
I need to make to following snippet of code work in the context of
I am trying to use the solution given here -> C# ADO.NET: nulls and

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.