Question
COMPLETE THE SERIALIZE AND DESERIALIZE METHODS ONLY import java.util.*; public class NTree { protected class Node { E data; Node parent; List children; protected Node(E
COMPLETE THE SERIALIZE AND DESERIALIZE METHODS ONLY
import java.util.*;
public class NTree
protected class Node { E data; Node parent; List
protected Node(E data) { this.data = data; this.children = new ArrayList
protected void addChild(Node c) { children.add(c); } public boolean equals(Node rhs) { return this.data.equals(rhs.data); } }
protected Node root;
public NTree() {}
public NTree(List
public boolean equals(NTree
protected boolean equals(Node lhs, Node rhs) { if (lhs == null || rhs == null) return lhs == rhs; if (!lhs.equals(rhs) || lhs.parent != rhs.parent) return false; for (int i = 0; i < lhs.children.size(); i++) { if (!equals(lhs.children.get(i), rhs.children.get(i))) return false; } return true; }
public void serialize(String fname) {}
public void deserialize(String fname) {}
public static void main(String [] args) { try { List
foodtree.serialize("foodtree.out"); NTree
System.out.println(foodtree.equals(foodtree2));
List
NTree
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started