Tarrell Fletcher

Ranch Hand
+ Follow
since Oct 07, 2011
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 Tarrell Fletcher

Let me break down my approach. I'm trying to bubble my way through, my method first finds the tree/node with the attached key. I then set that tree with the right min key and if its no key there I then retrieve the left max. Next depending on which worked I then redo the delete method either right or left by now passing in the max or min key. Basically the program should replace..redo...replace..redo...til it gets to the bottom then delete the tree/node. I tried it on a tree with keys 10 , 5 , 12, 2, 6 but it removes the 10, but then I have two 12 values.
6 years ago

Campbell Ritchie wrote:Another suggestion:
Write down the structure of your tree with some likely values attached to each node. Remember there are bound to be nulls all over the place. You should now have a little diagram.
Remove one of the nodes. Start with a leaf and see how that alters the structure of the tree. Then remove a non‑leaf node and see how the tree alters. Convert the changes on the diagram into instructions for how to remove a node, and then convert that lot to code.



That's just it, I can't make any references to null values like if(such == null). I can't make a new tree and reinsert the values back into the tree in the delete method. This is why its bugging me, I already drew it up on paper a long time ago to see how I was gonna do it. The problem I am having is removing that leaf/tree. I can switch the key that needs to be removed with the left max or right min but when the method ends and I print the tree that left is now on the map twice. Its on there twice because its in the spot that needed to be removed which is fine, and its still in its original place. Like is there some type of command that deletes the tree leaf.?
6 years ago
Ok..I've been at this for hours and I can't figure it out. Before you all say right it down I already did that and such I just can't seem to find out how to completely remove the tree. I cannot use any null references which is why this is so hard to do because it has to be straight recursion. Here is my code I have so far:public Tree<K, V> delete(K key) {

6 years ago

Winston Gutkowski wrote:

Tarrell Fletcher wrote:I'm just trying to see if the remove method seems correct because I am trying to test the methods but I do not know how to pass a comparator as an argument. Ive tried doing like...


And that's most of your problem, I think: You're concentrating too much on coding, when what you need to do is take a step back and understand the problem.

Linked Lists are tricky and fiddly, and can be very hard to visualise when you're just looking at code.

My advice: Turn off your computer and draw some diagrams. A node can be drawn with a simple circle or box and an arrow for the "next" pointer(*). So maybe start out with two of those named 'head' and 'tail' and draw out all the stages needed for an "add first" and "add last", along with written instructions in English. Once you're happy with that, do the same thing for your 'peek' (get()) and 'pop' (retrieve()) methods (those are the "official" names for those functions).

The main thing is to make sure you really know the mechanics before you write another line of Java code; otherwise you're going to spend a lot of time "trying things out".

Winston

(*) - I actually often use a dot and an arrow: a dot on the edge of the box or circle to denote the pointer itself, and an arrow to show when it's actually pointing to something (because it can be null, which means "pointing to nothing").



That's just it, I have actually drawn it before to see what happens. Its kinda how I got through some of the other methods and also I seen some videos and the guys suggested it. I'm just more concerned about the comparator thing. I have never even stated a comparator as an parameter which means I have never had to pass one as an argument. It just kinda messes with me and whenever I've tried doing some searches to see how to exactly do it, I find nothing. I even checked the Java Api for the comparator class and it only has equal and compare methods. There's no type of constructor so its just messing with me right now.
6 years ago

Campbell Ritchie wrote:

Tarrell Fletcher wrote: . . . I am to use the comparator in my remove method. But so far does this seem correct? . . .

That sounds very peculiar

Apart from your getLast and retrieveLast methods having confusing names, there is some poor style there. Look for a style guide which tells you what to use instead. (Hint: try here.)

I know the names are a bit unusual but these are the method names I have to use for this assignment. The get methods just show the data but does not remove it and the retrieve methods show and remove.
I'm just trying to see if the remove method seems correct because I am trying to test the methods but I do not know how to pass a comparator as an argument. Ive tried doing like
Comparator<String> comp = new Comparator() and such but nothing I do seems to be working unless you have to assign it a certain way.

And I also changed my iterator methods up as well.
6 years ago
Ok so I did some revisions to the code. I am to use the comparator in my remove method. But so far does this seem correct? I just returned this when for the addToFront and addToEnd methods. I feel as if the hasNext method in the Iterator should be asking if the position != null then return true else false.

6 years ago

Winston Gutkowski wrote:

Tarrell Fletcher wrote:I need to make a method called getSize() and the method just returns the value of the instance variable you use to keep track of size. But here's the catch....I'm not suppose to traverse the list...


OK, so how else do you think you might do it? (Tip: the answer is in your instructions, which as far as I can see you haven't followed - at least not yet).

Ok so I just reread it, it seems like it is telling me to make an global counter and then I guess increment it whenever something is added to it. And Im just calling that variable to see where the counter is at. And I guess if I do a remove method to make sure I decrement whenever something is deleted?

Winston

6 years ago
So I have some project which I guess I am to create a class called BasicLinkedList and another called SortedLinkedList. I need to make a method called getSize() and the method just returns the value of the instance variable you use to keep track of size. But here's the catch....I'm not suppose to traverse the list. Here's a doc of all the methods I need to make if someone wanted to see the actual instructions themselve. http://www.cs.umd.edu/class/spring2013/cmsc132/projects/LinkedListsProject/doc/index.html But also for the addToFront method it says it should return a reference of the current object? This confuses me because its not letting me return head unless the head should be defined within the Node class. Here's my current code



6 years ago
Never checked that out but I will now.
7 years ago
I am guessing the Nodes in java is another way of saying Linked List right? Well I have a variety of steps to follow in making a linked list. I already did the first step and stored the values in the node.


How am I suppose to switch the values 6 and 2?
7 years ago
Btw, thanks
7 years ago
I found my mistake, I had spelled one of the methods wrong in interface and it didn't make the one in the abstract section.
7 years ago
Ok, I just need to test it out to make sure it works. The implementation is created then, but I just want to test it out to see if it works.
7 years ago
WHen I go to the main method I type

but it tells me I cant instantiate type Student.
7 years ago
Ok I forgot the constructor has to have the same name as the class. Ok everything there checks out but for some reason it wont let me implement the methods to implement the speaker interface.
7 years ago