Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java Parameters and Inheritance question

Name: Javafag 2007-06-07 15:06 ID:8FwQmpEe

Building a Red-Black Tree for a project. Right now I've got a working Binary Search Tree with constructors:

public class BSTree <T extends Comparable>{
    private BSTNode<T> root;
   
    public BSTree(){
    }
    public BSTree(BSTNode<T> n){
        root=n;
    }
    public BSTree(T c){
        root=new BSTNode<T>(c);
    }

And then I've got the Red-Black Tree's constructors:

public class RBTree <T extends Comparable> extends BSTree{
   
    public RBTree (){
        super();
    }
    public RBTree (T c){
        super(c);
    }
    public RBTree (BSTNode<T> n){
        super(n);
    }

My question: Will this handle Parameters correctly? Ex, if I make a RBTree<Integer>(), will it run BSTree<Integer>(), or just BSTree() ?

Sorry for Java faggotry, it's the only language my school teaches.

Name: Anonymous 2007-06-07 15:42 ID:7twpv8iV

why don't you try it and share your results?

Name: Javafag 2007-06-07 15:51 ID:8FwQmpEe

public static void main(String [] args){
        RBTree<Integer> r=new RBTree<Integer>();
        r.add(new Integer(4));
        Integer thisDoesntWork=r.getNode(new Integer(4)).getData();
    }

Gives a Type mismatch, so no, it doesn't work, and yes, I'm a fucking idiot for not actually trying it.

So does anybody know what I'm supposed to do for something like this? One thing I did try was looking it up, but I didn't find much on how parameters deal with inheritance.

Name: Anonymous 2007-06-07 17:36 ID:HOqul2bs

extends BSTree<T>

Name: Anonymous 2007-06-08 15:51 ID:JnfLo0VY

Forget it, it's NP-complete.

Name: Anonymous 2007-06-08 16:01 ID:HPucPeFI

NP-complete means its impossible to solve.

Name: Anonymous 2007-06-08 16:06 ID:tDwwFPs2

what the fuck are you trying to do

BSTree<Integer>(), or just BSTree()
it will run the constructor named BSTree(), and gives you a class where T is 'replaced' everywhere in it by Integer (saving you a shitload of typecasts)

Name: Anonymous 2007-06-08 16:32 ID:cRQtsPi3

>>5
But is it Touring-complete?

Name: Anonymous 2007-06-08 23:22 ID:hTHkOXCy

>>5
I'm surprised people still remember this.

Name: Anonymous 2007-06-09 1:35 ID:EXLbf8Uo

You're missing parameterization somewhere if it's not returning Integer.

public class RBTree <T extends Comparable> extends BSTree{

try changing BSTree to BSTree<T> or BSTree<T extends Comparable>

Java really is a shitty language.

Name: Anonymous 2007-06-09 6:22 ID:bsYOqMFh

Java is nasty

Name: Anonymous 2007-06-09 6:29 ID:Heaven

>>6
No, it doesn't. I can just enumerate all possible solutions.

Name: Anonymous 2007-06-09 6:45 ID:HG2DFXiU

>>6
NP-complete means the problem grows exponentially with respect to the input, so it quickly becomes intractable.

Name: Anonymous 2007-06-09 7:44 ID:bsYOqMFh

Many of today's frequently solved problems are NP-complete. An acceptable solution can be found in acceptable time given the input.

Name: Anonymous 2007-06-09 11:17 ID:xBtmiZHn

>>12-14
Give it up, this discussion is NP-complete.

Name: Anonymous 2007-06-09 12:16 ID:JBINkuZK

>>12
>>13
no, NP complete means that its unsolveable. GIven an NP complete problem its not intractable to any solvable problem, therefore its unsolveable.
Go read wikipedia if you are confused.

Name: Anonymous 2007-06-09 13:41 ID:HG2DFXiU

>>16
You're the one who's confused pal. NP complete means that finding a complete solution takes a non-polynomial amount of time.

Name: Anonymous 2007-06-09 14:13 ID:JBINkuZK

>>17
stop arguring and read what you are actually saying. Its obvious you dont know what you are talking about.
We are discussing "NP completeness", please read about it to the point that you know what it is before trying to discuss it with us.

Name: Anonymous 2007-06-09 14:19 ID:HG2DFXiU

>>18
If you're attempting to troll me, you have succeeded. Otherwise you're just annoyingly stupid.

Name: Anonymous 2007-06-09 14:27 ID:xBtmiZHn

>>19
The N in NP-complete means nondeterministic, which means that you cannot determine the answer to the problem.  Not even Touring-complete languages like BBcode, maybe Perl though.

Name: Anonymous 2007-06-09 15:15 ID:f5Wj+rCr

>>20
How do I solved NP-complete problem?

while True:
    solution = give_random_solution()
    if is_answer_correct(solution):
        return solution

Name: Anonymous 2007-06-09 15:18 ID:Heaven

>>21
One word, the forced indentation of code, NP-complete.

Name: Anonymous 2007-06-09 15:34 ID:Heaven

>>21
it's better to do give_next_solution() instead. that way you won't repeat the same solution more than once.

Name: Anonymous 2007-06-09 17:28 ID:JBINkuZK

>>23
The solutions for an NP complete problem may be innerable, and theres no heuristic to iterativly travel toward a solution. This is the fundamental nature of NP complete problem, and its why the are unsolveable.

Name: Anonymous 2007-06-09 18:31 ID:bsYOqMFh

>>24
But you can still establish an order of operation instead of bothering to take random choices (slower, and chance of repeating your choices).

Name: Anonymous 2007-06-09 18:37 ID:HG2DFXiU

>>25
The classic NP complete problem is the travelling salesman. The solution is to enumerate all possible routes. There is no way to say that any given route is the shortest without enumerating all of them.

Name: Anonymous 2007-06-09 21:21 ID:bsYOqMFh

>>26
Of course, I'm just talking about proceeding in some order (any order), instead of doing it randomly (which is more costly and can be redundant).

Name: Anonymous 2007-06-09 21:33 ID:bsYOqMFh

Hi, >>27 here. I'll auto-own myself with this paragraph from Wikipedia:

Random path change algorithms are currently the state-of-the-art search algorithms and work up to 100,000 cities. The concept is quite simple: Choose a random path, choose four nearby points, swap their ways to create a new random path, while in parallel decreasing the upper bound of the path length. If repeated until a certain number of trials of random path changes fail due to the upper bound, one has found a local minimum with high probability, and even further it's a global minimum with high probability (whereas high means that the rest probability decreases exponentially in the size of the problem - thus for 10,000 or more nodes, the chances of failure is negligible).

Name: Anonymous 2007-06-09 21:39 ID:JBINkuZK

>>28
OK can we just accept that NP problems are unsolvable now that you have read wikipedia.

Name: Richard Machowicz 2007-06-09 23:23 ID:/2r4L6hy

Random PATH change algorithms are currently the STATE-OF-THE-ART search AL-gorithms and work up to 100,000 CITIES. The CON-cept is quite SIM-ple: Choose a random PATH, choose four NEAR-BY points, SWAP their WAYS to create a NEW random path, while in PARA-llel DE-creasing the UPPER bound of the path LENGTH.

Name: Anonymous 2007-06-10 1:24 ID:Heaven

>>30
THIS IS WHY WE DON'T SUBMIT /prog/ TO REDDIT

Name: Anonymous 2007-06-10 5:08 ID:Heaven

IF U WERE DROPPED TO /opt TOMORROW, I WOULDNT GO 2 UR DELETION CUZ ID B N UPSTREAM BUGZILLA

FLAMIN DA CUNT THAT MADE UR EBUILD!
     __   
   .'  `. 
   |a_a  |
   \<_)__/
   /(   )\
  |\`> < /\
  \_|=='|_/

WE TRUE NERDS
WE OPTIMIZE OUR CFLAGS TOGETHER
WE TALKIN ON IRC WITH www.opera.com TOGETHER
send this PENGUIN to every thread you care about including this one if you care. C how many

times you get this, if you get 256 your A TRUE NERD

Name: Anonymous 2007-06-10 10:25 ID:Heaven

>>31
THIS IS WHY WE DON'T SUBMIT /prog/ TO REDDIT

Name: Anonymous 2009-01-14 12:24

LISP

Name: Anonymous 2010-12-06 9:41

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-02-03 0:26

Don't change these.
Name: Email:
Entire Thread Thread List