Gabrielle Evans

Greenhorn
+ Follow
since Apr 14, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gabrielle Evans

I have browsed the other questions and found solutions as to how to do a deep copy of objects that contain references. I am specifically wanting to make a deep copy of a tree. Logically, each tree node contain references to its children nodes. Here is the basics of my node class


I know I must only be making a shallow copy because when I make a copy of tree1, called tree2, and edit tree1 the edits also appear on tree2. Here is my copy method within my BSTNode class

When I wish to copy the entire tree, I call that above copy method from my BSTree class using the methods below. (I have 2 methods because this is a homework assignment that requires a copy method that calls a preorder traversal method)


I use these lines to create the new tree and assign the copy to it



And further along when I make changes to tree1, tree 2 also changes. I have no clue what I'm doing wrong. I believe it must be somewhere in how I return the new tree or something. Any help is greatly appreciated!!
10 years ago
First of all, I understand that there are many similar questions to mine posted around the web. I have spent, literally, 2 hours looking through and attempting some of the solutions already given. I am at my wits end. I have a BST that I am told (this is for homework) that I must do a deep copy of into a separate tree. I am told to to this my implementing a preorder traversal method. This is what I have so far



I am doing it in 2 seperate methods because the specifications require a method BSTNode copy() that calls a preorder traversal method.

Here is my BSTNode class for reference



When I attempt to run the code, I get that only the first element (root) of the tree gets copied. Here is the code I am using to test



My output is

I really am desperate. This is about the 8th time I have completely re-written my copy method(s). Any guidance would be greatly appreciated.
10 years ago
My objective is to execute quick sort ( i was told to convert the pseudocode from the Cormen book) using arrays of increasing sizes and find the average number of comparisons for each of those sizes over 100 iterations. This is a school project and the numbers I am getting are far larger than those of my friends, so I am clearly doing something wrong. I believe it must be in the way that I am collecting and averaging my number of comparisons. I will first give the method in which most of that calculating is done, then I will include the whole program.



I am incrementing the variable comparisonCount for each comparison done and adding that to an array of all the comparison numbers for that array size. I am then running through that array, averaging it, and placing that average into another array.

10 years ago
Figured it out! I just needed to write the array with write() instead of writeObject()!
11 years ago
In one file, I save a TreeNode object, then an int, and then a byte array to a file named `huffmanTrial.huff`.
In another file I want to read in all three of those things and do work on them. I can read in the TreeNode just fine and the int, but when I get to reading in the byte array I get that it is of size zero. Is that saying that it doesn't exist? I am using `in.available()` after I read in the TreeNode and int so I can see how big I need to make my new byte array and I always get 0. Am I somehow saving the array wrongly or am I reading it in wrongly?

Here is where I save the objects:



And here is where I am trying to read all three things in


I get `Size of array: 0`
I know for sure that the array that I am saving is not empty because just two lines before I save it, I print its contents. What am I doing wrong?
11 years ago