Re: Singly Linked LIst and Objects Newbie Question



Now that this is done, I'm not sure what to do with my time. (well
all 1 day of freedom.) I was considering on implementing a red black
tree algorithm for my personal project to continue learning how to use
objects, and to strengthen my understanding of it because it'll be on
the next midterm. I have a bad feeling though, it sounds hard...so
maybe not. :p

I understand Japanese actually. :) Exposed to it everyday so I
recognize the structure...it's an interesting analogy and one I will
remember.

Hm it seems that my algorithm and datastructure knowledge is really
limited. I've studied computer science for 3 years, but never got to
the advanced parts because of health problems. There was only an
introductory course on datastructures and algorithms in the first
year. I had never even heard of red-black trees or 2-3-4 trees or any
other of the optimizations.

If you want to study objects I think the most interesting part is
polymorphism. For example, some base abstract class defines some set
of methods including complex methods that operate on the simpler ones.
Then you subclass this base class and provide your own implementation
for the the simple methods. The complex methods that are already there
now operate on YOUR simple methods instead of those of the base class,
so you get their functionality for free.

That kind of stuff. You could study the Java Collection Framework and
its source, to see how Interface builds upon Interface and subclass
builds upon abstract class. But perhaps you've already done all that.
But then there's nothing more you need to learn about objects, I
guess.

This is also quite cool btw. You can't have nested methods in Java,
ie. you can't define a method inside a method. You also cannot define
a static class and use that, although the compiler can and does
sometimes. But you CAN define a class inside a method if you
immediately instantiate it, and have the class implement a 'nested'
method.

So for example you want to write an assertion that evaluates a complex
expression. You could define a new method:

boolean method1_checkAssert(int a, Object b) {
// calculated boolean value
return resut;
}

void method1(int a, Object b) {
// check whether the preconditions are satisfied and throw
// an AssertionError otherwise:
assert method1_checkAssert(a,b): "" + a + " must be equal to " + b;
}

But if the checkAssert method is not so big, you might do:

void method1(int a, Object b) {
assert new Object() {
boolean eval(int a, Object b) {
// calculate boolean value
return result;
}
}.eval(a,b): "" + a + " must be equal to " + b;
}

The drawback is that this creates an object but you would turn
assertions off anyway in production code. Note that you can't use any
of the method's variables unless you make them final so you must
either make them final or pass them as parameters to eval()

hope you find it interesting,
xen.
.



Relevant Pages

  • Re: No trees in the stdlib?
    ... The particular algorithm to achieve this is a secondary issue. ... It's my fault for having opened the topic with simply "trees" instead, it would have avoided this vagueness problem, but I'm genuinely surprised to know there are no data structures that efficiently support such a common need in Python. ... second option, anyway) ...
    (comp.lang.python)
  • Re: Prefered resistor range
    ... >>Can you reconsider that assertion? ... Expressed mathematically, (and ignoring the rounding ... > Well, it depends on how your algorithm works, and I can't read PERL. ... ability to devise such a rule. ...
    (sci.electronics.design)
  • Re: Tomazos Binary Tree Traverse Algorithm
    ... I consider it confusing to say that the algorithm take Theta ... Traversal Algorithm for Binary Trees with Parent Pointers. ... One can write an algorithm to do the same traversal in a binary tree ...
    (comp.theory)
  • Re: A Definition of an Algorithm
    ... Towards a Definition of an Algorithm ... the set of primitive recursive functions is considered. ... trees that show how the function is built up. ... a language built with binary trees is fundamentally different ...
    (sci.math.research)
  • Re: Speculative Design Hypothesis (with predictions)
    ... algorithm that created it. ... All life is related....through common descent. ... design....better provide some details about the designer, ... Common *descent* is an assertion. ...
    (talk.origins)